def test_glottocode_from_name(self):
        from pyglottolog.languoids import Glottocode, Glottocodes

        gc = Glottocode.from_name('a', dry_run=True)
        # only a dry-run, so not really added to glottocodes:
        self.assertNotIn(gc, Glottocodes())
        self.assertEqual(gc.split()[0], 'aaaa')
Exemple #2
0
def new_languoid(args):
    """Create a new languoid directory for a languoid specified by name and level.

    glottolog new_languoid <name> <level>
    """
    assert args.args[1] in ['family', 'language', 'dialect']
    lang = Languoid.from_name_id_level(
        args.args[0],
        Glottocode.from_name(args.args[0]),
        args.args[1],
        **dict(prop.split('=') for prop in args.args[2:]))
    #
    # FIXME: how to specify parent? Just mv there?
    #
    print("Info written to %s" % lang.write_info())
Exemple #3
0
def recode(args):
    """Assign a new glottocode to an existing languoid.

    glottolog recode <code>
    """
    lang = find_languoid(glottocode=args.args[0])
    if not lang:
        raise ParserError('languoid not found')
    lang.id = Glottocode.from_name(lang.name)
    new_dir = lang.dir.parent.joinpath(lang.id)
    copytree(lang.dir, new_dir)
    lang.write_info(new_dir)
    remove(new_dir.joinpath('%s.ini' % args.args[0]))
    rmtree(lang.dir)
    print("%s -> %s" % (args.args[0], lang.id))
def test_Glottocode():
    with pytest.raises(ValueError):
        Glottocode('a2')
Exemple #5
0
def test_Glottocode_ordering():
    assert sorted([Glottocode('abcd1235'),
                   Glottocode('abcd1234')])[0] == Glottocode('abcd1234')
    assert Glottocode('zzzz9999') > Glottocode('abcd1234')
    assert Glottocode('abcd1234') <= Glottocode('abcd1234')
Exemple #6
0
def test_Glottocode_validation():
    with pytest.raises(ValueError):
        Glottocode('a2')
    def test_init(self):
        from pyglottolog.languoids import Glottocode

        with self.assertRaises(ValueError):
            Glottocode('a2')