Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_glottolog_newick(tmppath, mocker):
tmppath.joinpath('glottolog-2.5.newick').write_text(
'(B [abcd1234],C [abcd1234])A [abcd1234];', encoding='utf8')
mocker.patch(
'beastling.configuration.user_data_dir',
new=mocker.Mock(return_value=str(tmppath)))
trees = newick.read(get_glottolog_data('newick', '2.5'))
assert trees[0].name == 'A [abcd1234]'
def test_read_write(tmpdir):
trees = read(pathlib.Path(__file__).parent / 'fixtures' / 'tree-glottolog-newick.txt')
descs = [len(tree.descendants) for tree in trees]
# The bookkeeping family has 391 languages
assert descs[0] == 391
tmp = str(tmpdir.join('test.txt'))
write(trees, tmp)
assert pathlib.Path(tmp).exists()
assert [len(tree.descendants) for tree in read(tmp)] == descs
def test_read_write(tmpdir):
trees = read(pathlib.Path(__file__).parent / 'fixtures' / 'tree-glottolog-newick.txt')
descs = [len(tree.descendants) for tree in trees]
# The bookkeeping family has 391 languages
assert descs[0] == 391
tmp = str(tmpdir.join('test.txt'))
write(trees, tmp)
assert pathlib.Path(tmp).exists()
assert [len(tree.descendants) for tree in read(tmp)] == descs
match.group('glottocode'),
match.group('isocode'))
def get_classification(node):
ancestor = node.ancestor
if not ancestor:
# Node is root of some family
return [label2name[node.name]]
res = []
while ancestor:
res.append(label2name[ancestor.name])
ancestor = ancestor.ancestor
return list(reversed(res))
# Walk the tree and build the classifications dictionary
glottolog_trees = newick.read(get_glottolog_data('newick', self.admin.glottolog_release))
for tree in glottolog_trees:
for node in tree.walk():
name, glottocode, isocode = parse_label(node.name)
classification = get_classification(node)
self.classifications[glottocode] = classification
if isocode:
self.classifications[isocode] = classification
glottocode2node[glottocode] = node
# Load geographic metadata
for t in reader(
get_glottolog_data('geo', self.admin.glottolog_release), namedtuples=True):
if t.macroarea:
self.glotto_macroareas[t.glottocode] = t.macroarea
for isocode in t.isocodes.split():
self.glotto_macroareas[isocode] = t.macroarea