def from_name_id_level(cls, tree, name, id, level, **kw): cfg = INI(interpolation=None) cfg.read_dict(dict(core=dict(name=name))) res = cls(cfg, kw.pop('lineage', []), id_=Glottocode(id), tree=tree) res.level = Level.get(level) for k, v in kw.items(): setattr(res, k, v) return res
def __init__(self, cfg, lineage=None, id_=None, directory=None, tree=None): """ :param cfg: :param lineage: list of ancestors, given as (id, name) pairs. """ assert (id_ and tree) or directory if id_ is None: id_ = Glottocode(directory.name) lineage = lineage or [] assert all([ Glottocode.pattern.match(id) and Level.get(level) for name, id, level in lineage ]) self.lineage = [(name, id, Level.get(level)) for name, id, level in lineage] self.cfg = cfg self.dir = directory or tree.joinpath( *[id for name, id, _ in self.lineage]) self._id = id_
def test_init(self): with self.assertRaises(ValueError): Glottocode('a2')