Esempio n. 1
0
    def test_factory(self):
        from pyglottolog.languoids import Languoid, Level

        f = Languoid.from_dir(self.tree.joinpath('abcd1234'))
        self.assertEqual(f.category, 'Family')
        l = Languoid.from_dir(self.tree.joinpath(f.id, 'abcd1235'))
        self.assertEqual(l.name, 'language')
        self.assertEqual(l.level, Level.language)
        self.assertAlmostEqual(l.latitude, 0.5)
        self.assertAlmostEqual(l.longitude, 0.5)
        l.latitude, l.longitude = 1.0, 1.0
        self.assertAlmostEqual(l.latitude, 1.0)
        self.assertAlmostEqual(l.longitude, 1.0)
        self.assertEqual(l.iso_code, 'abc')
        l.iso_code = 'cde'
        self.assertEqual(l.iso, 'cde')
        self.assertEqual(l.hid, 'abc')
        l.hid = 'abo'
        self.assertEqual(l.hid, 'abo')
        self.assertEqual(l.id, 'abcd1235')
        self.assertEqual(l.macroareas, ['a', 'b'])
        l.macroareas = ['a']
        self.assertEqual(l.macroareas, ['a'])
        self.assertEqual(l.parent, f)
        self.assertEqual(f.children[0], l)
        self.assertEqual(l.children[0].family, f)
        l.write_info(self.tmp_path('new').as_posix())
Esempio n. 2
0
    def test_isolate(self):
        from pyglottolog.languoids import Languoid

        l = Languoid.from_dir(self.tree.joinpath('isol1234'))
        self.assertTrue(l.isolate)
        self.assertIsNone(l.parent)
        self.assertIsNone(l.family)
Esempio n. 3
0
def test_factory(tmpdir, api_copy):
    f = Languoid.from_dir(api_copy.tree / 'abcd1234')
    assert f.category == 'Family'
    l = Languoid.from_dir(api_copy.tree / f.id / 'abcd1235')
    assert l.name == 'language'
    assert 'abcd1235' in repr(l)
    assert 'language' in '%s' % l
    assert l.level == Level.language
    assert l.latitude == pytest.approx(0.5)
    assert l.longitude == pytest.approx(0.5)
    l.latitude, l.longitude = 1.0, 1.0
    assert l.latitude == pytest.approx(1.0)
    assert l.longitude == pytest.approx(1.0)
    assert l.iso_code == 'abc'
    l.iso_code = 'cde'
    assert l.iso == 'cde'
    assert l.hid == 'abc'
    l.hid = 'abo'
    assert l.hid == 'abo'
    assert l.id == 'abcd1235'

    assert len(l.macroareas) == 2
    l.macroareas = [Macroarea.africa]
    assert l.macroareas == [Macroarea.africa]

    l.countries = api_copy.countries[:2]
    assert len(l.countries) == 2

    assert l.parent == f
    assert f.children[0] == l
    assert l.children[0].family == f
    l.write_info(str(tmpdir))
    assert (tmpdir / 'abcd1235').exists()
    assert isinstance(
        api_copy.languoid('abcd1235').iso_retirement.asdict(), dict)
    assert l.classification_comment is None
    l.endangerment = 'nearly extinct'
    assert l.endangerment == EndangermentStatus.critical
    assert l.names == {}
    l.cfg['altnames'] = {'glottolog': 'xyz'}
    assert 'glottolog' in l.names
    assert l.identifier == {}
    l.cfg['identifier'] = {'multitree': 'xyz'}
    assert 'multitree' in l.identifier
Esempio n. 4
0
    def test_factory(self):
        f = Languoid.from_dir(self.api.tree.joinpath('abcd1234'))
        self.assertEqual(f.category, 'Family')
        l = Languoid.from_dir(self.api.tree.joinpath(f.id, 'abcd1235'))
        self.assertEqual(l.name, 'language')
        self.assertIn('abcd1235', repr(l))
        self.assertIn('language', '%s' % l)
        self.assertEqual(l.level, Level.language)
        self.assertAlmostEqual(l.latitude, 0.5)
        self.assertAlmostEqual(l.longitude, 0.5)
        l.latitude, l.longitude = 1.0, 1.0
        self.assertAlmostEqual(l.latitude, 1.0)
        self.assertAlmostEqual(l.longitude, 1.0)
        self.assertEqual(l.iso_code, 'abc')
        l.iso_code = 'cde'
        self.assertEqual(l.iso, 'cde')
        self.assertEqual(l.hid, 'abc')
        l.hid = 'abo'
        self.assertEqual(l.hid, 'abo')
        self.assertEqual(l.id, 'abcd1235')

        self.assertEqual(len(l.macroareas), 2)
        l.macroareas = [Macroarea.africa]
        self.assertEqual(l.macroareas, [Macroarea.africa])

        l.countries = self.api.countries[:2]
        self.assertEqual(len(l.countries), 2)

        self.assertEqual(l.parent, f)
        self.assertEqual(f.children[0], l)
        self.assertEqual(l.children[0].family, f)
        l.write_info(self.tmp_path().as_posix())
        self.assertTrue(self.tmp_path('abcd1235').exists())
        self.assertIsInstance(
            self.api.languoid('abcd1235').iso_retirement.asdict(), dict)
        self.assertIsNone(l.classification_comment)
        l.endangerment = 'Critically endangered'
        self.assertEqual(l.endangerment, EndangermentStatus.critical)
        self.assertEqual(l.names, {})
        l.cfg['altnames'] = {'glottolog': 'xyz'}
        self.assertIn('glottolog', l.names)
        self.assertEqual(l.identifier, {})
        l.cfg['identifier'] = {'multitree': 'xyz'}
        self.assertIn('multitree', l.identifier)
Esempio n. 5
0
    def test_lff2tree(self):
        old, new = self.tmp_path('old'), self.tmp_path('new')
        old.mkdir()
        new.mkdir()

        _l = """# -*- coding: utf-8 -*-
Abkhaz-Adyge [abkh1242]
    Ubykh [ubyk1235][uby]
Abkhaz-Adyge [abkh1242], Abkhaz-Abaza [abkh1243]
    Abaza [abaz1241][abq]
    Abkhazian [abkh1244][abk]
Abkhaz-Adyge [abkh1242], Circassian [circ1239]
    Adyghe [adyg1241][ady]
    Kabardian [kaba1278][kbd]
"""

        _d = """# -*- coding: utf-8 -*-
Abaza [abaz1241]
    Ashkaraua [ashk1247][]
    Bezshagh [bezs1238][]
    Tapanta [tapa1256][]
Abkhazian [abkh1244]
    Abzhui [abzh1238][]
    Bzyb [bzyb1238][]
    Samurzakan [samu1242][]
"""

        def lffs():
            return {Level.language: lff(_l), Level.dialect: lff(_d)}

        lff2tree(old, builddir=self.tmp_path('build1'), lffs=lffs())
        lff2tree(old, new, builddir=self.tmp_path('build2'), lffs=lffs())
        tree2lff(
            new,
            out_paths={
                Level.language: self.tmp_path('lff'),
                Level.dialect: self.tmp_path('dff')
            }
        )
        with self.tmp_path('lff').open() as fp:
            self.assertEqual(fp.read(), _l)

        with self.tmp_path('dff').open() as fp:
            self.assertEqual(fp.read(), _d)

        lffs_ = {Level.language: lff(_l.replace('Abaza', 'Abazul')),
                 Level.dialect: lff(_d)}
        lff2tree(old, new, builddir=self.tmp_path('build2'), lffs=lffs_)
        l = Languoid.from_dir(new.joinpath('abkh1242', 'abkh1243', 'abaz1241'))
        self.assertEqual(l.name, 'Abazul')
        self.assertEqual(l.parent.name, 'Abkhaz-Abazul')
Esempio n. 6
0
    def test_lff2tree(self):
        old, new = self.tmp_path('old'), self.tmp_path('new')
        old.mkdir()
        new.mkdir()

        _l = """# -*- coding: utf-8 -*-
Abkhaz-Adyge [abkh1242]
    Ubykh [ubyk1235][uby]
Abkhaz-Adyge [abkh1242], Abkhaz-Abaza [abkh1243]
    Abaza [abaz1241][abq]
    Abkhazian [abkh1244][abk]
Abkhaz-Adyge [abkh1242], Circassian [circ1239]
    Adyghe [adyg1241][ady]
    Kabardian [kaba1278][kbd]
"""

        _d = """# -*- coding: utf-8 -*-
Abaza [abaz1241]
    Ashkaraua [ashk1247][]
    Bezshagh [bezs1238][]
    Tapanta [tapa1256][]
Abkhazian [abkh1244]
    Abzhui [abzh1238][]
    Bzyb [bzyb1238][]
    Samurzakan [samu1242][]
"""

        def lffs():
            return {Level.language: lff(_l), Level.dialect: lff(_d)}

        lff2tree(old, builddir=self.tmp_path('build1'), lffs=lffs())
        lff2tree(old, new, builddir=self.tmp_path('build2'), lffs=lffs())
        tree2lff(new,
                 out_paths={
                     Level.language: self.tmp_path('lff'),
                     Level.dialect: self.tmp_path('dff')
                 })
        with self.tmp_path('lff').open() as fp:
            self.assertEqual(fp.read(), _l)

        with self.tmp_path('dff').open() as fp:
            self.assertEqual(fp.read(), _d)

        lffs_ = {
            Level.language: lff(_l.replace('Abaza', 'Abazul')),
            Level.dialect: lff(_d)
        }
        lff2tree(old, new, builddir=self.tmp_path('build2'), lffs=lffs_)
        l = Languoid.from_dir(new.joinpath('abkh1242', 'abkh1243', 'abaz1241'))
        self.assertEqual(l.name, 'Abazul')
        self.assertEqual(l.parent.name, 'Abkhaz-Abazul')
Esempio n. 7
0
def test_isolate(api):
    l = Languoid.from_dir(api.tree / 'isol1234')
    assert l.isolate
    assert l.parent is None
    assert l.family is None
Esempio n. 8
0
def test_factory_without_api(api_copy):
    f = Languoid.from_dir(api_copy.tree / 'abcd1234', _api=api_copy)
    l = Languoid.from_dir(api_copy.tree / f.id / 'abcd1235')
    assert len(
        l.macroareas) == 0  # No API passed at initialization => no macroareas!
Esempio n. 9
0
 def test_isolate(self):
     l = Languoid.from_dir(self.api.tree.joinpath('isol1234'))
     self.assertTrue(l.isolate)
     self.assertIsNone(l.parent)
     self.assertIsNone(l.family)