def test_get_glottolog_data_download(self): data_dir = os.path.join(self.tmp.as_posix(), 'data') class URLopener(object): def retrieve(self, url, fname): with io.open(fname, 'w', encoding='utf8') as fp: fp.write('(B [abcd1234],C [abcd1234])A [abcd1234];') class URLopenerError(object): def retrieve(self, url, fname): raise IOError() with patch.multiple( 'beastling.configuration', user_data_dir=Mock(return_value=data_dir), URLopener=URLopenerError, ): with self.assertRaises(ValueError): get_glottolog_data('newick', '2.5') with patch.multiple( 'beastling.configuration', user_data_dir=Mock(return_value=data_dir), URLopener=URLopener, ): assert get_glottolog_data('newick', '2.5')
def test_glottolog(): c, _, _ = classifications_from_newick( str(get_glottolog_data('newick', '4.0'))) struct = make_structure(c, ['olde1238', 'sate1242', 'hind1273', 'schi1234'], 0, 9) assert check_structure(struct) assert make_newick(struct) == '(((hind1273,schi1234),sate1242),olde1238)'
def test_get_glottolog_geo(self): geodata = self.tmp.joinpath('glottolog-2.5-geo.csv') with geodata.open('w', encoding='utf8') as fp: fp.write('x') with patch('beastling.configuration.user_data_dir', new=Mock(return_value=self.tmp.as_posix())): self.assertEqual(Path(get_glottolog_data('geo', '2.5')), geodata)
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(str(get_glottolog_data('newick', '2.5'))) assert trees[0].name == 'A [abcd1234]'
def test_get_glottolog_geo(tmppath, mocker): geodata = tmppath / 'glottolog-2.5-geo.csv' geodata.write_text('x', encoding='utf8') mocker.patch( 'beastling.configuration.user_data_dir', new=mocker.Mock(return_value=str(tmppath))) assert Path(get_glottolog_data('geo', '2.5')) == geodata
def test_get_glottolog_newick(self): with self.tmp.joinpath('glottolog-2.5.newick').open('w', encoding='utf8') as fp: fp.write('(B [abcd1234],C [abcd1234])A [abcd1234];') with patch( 'beastling.configuration.user_data_dir', new=Mock(return_value=self.tmp.as_posix())): trees = newick.read(get_glottolog_data('newick', '2.5')) self.assertEqual(trees[0].name, 'A [abcd1234]')
def test_get_glottolog_geo(self): geodata = self.tmp.joinpath('glottolog-2.5-geo.csv') with geodata.open('w', encoding='utf8') as fp: fp.write('x') with patch( 'beastling.configuration.user_data_dir', new=Mock(return_value=self.tmp.as_posix())): self.assertEqual(Path(get_glottolog_data('geo', '2.5')), geodata)
def test_get_glottolog_newick(self): with self.tmp.joinpath('glottolog-2.5.newick').open( 'w', encoding='utf8') as fp: fp.write('(B [abcd1234],C [abcd1234])A [abcd1234];') with patch('beastling.configuration.user_data_dir', new=Mock(return_value=self.tmp.as_posix())): trees = newick.read(get_glottolog_data('newick', '2.5')) self.assertEqual(trees[0].name, 'A [abcd1234]')
def test_get_glottolog_data_download(tmppath, mocker): data_dir = tmppath / 'data' class URLopener(object): def retrieve(self, url, fname): with io.open(fname, 'w', encoding='utf8') as fp: fp.write('(B [abcd1234],C [abcd1234])A [abcd1234];') class URLopenerError(object): def retrieve(self, url, fname): raise IOError() mocker.patch('beastling.configuration.user_data_dir', mocker.Mock(return_value=str(data_dir))) mocker.patch('beastling.util.misc.URLopener', URLopenerError) with pytest.raises(ValueError): get_glottolog_data('newick', '2.5') mocker.patch('beastling.util.misc.URLopener', URLopener) assert get_glottolog_data('newick', '2.5')