Example #1
0
    def test_dump_load_dict(self):
        from lingpy3.jsonlib import load, dump

        d = {'a': 2, 'z': 1}
        out = dump(d, outdir=self.tmp_path())
        self.assertEqual(d, load(out))
        d2 = OrderedDict([('z', 1), ('a', 2)])
        out2 = dump(d2, outdir=self.tmp_path())
        self.assertEqual(out.name, out2.name)
Example #2
0
def run_and_dump(name, obj, __checksum__=None, **kw):
    adapter = get_adapter(obj, interfaces.IOperation, name=name)
    if __checksum__:
        cached = path_from_checksum(__checksum__, outdir=CACHE_DIR)
        if cached.exists():
            return load(cached, cls=adapter.returns), __checksum__
    res = adapter(**kw)
    out = dump(res, outdir=CACHE_DIR)
    return res, as_unicode(out.stem)
Example #3
0
    def test_DiacriticsVowelsTones(self):
        from lingpy3.sequence.soundclassmodel import DiacriticsVowelsTones

        with patch('lingpy3.sequence.soundclassmodel.Cache', dict):
            DiacriticsVowelsTones.from_name('dvt')

        dvt = DiacriticsVowelsTones.from_name('dvt')
        self.assertEqual(
            dvt,
            jsonlib.load(jsonlib.dump(dvt, outdir=self.tmp_path()),
                         cls=DiacriticsVowelsTones))
Example #4
0
 def __call__(self, args):
     opargs, opkw = _args_kw(args.name)
     readargs, readkw = _args_kw(args.object)
     oname, if_, input_ = readargs
     input_ = text_type(input_)
     if Path(path_component(input_)).exists():
         # We heuristically interpret the input as filename, if a file with that name
         # exists.
         input_ = Path(path_component(input_))
     res = run(
         opargs[0],
         read(oname, getattr(interfaces, if_), input_, **readkw),
         **opkw)
     p = jsonlib.dump(res, outdir=Path(args.output))
     print('Result written to <%s>' % as_unicode(p))
     return p
Example #5
0
    def test_dump_load_custom(self):
        from lingpy3.jsonlib import load, dump

        wl = make_wordlist()
        out = dump(wl, outdir=self.tmp_path())
        self.assertEqual(wl, load(out, Wordlist))