def test_ObjDict_load(): """Test :func:`~utilipy.utils.collections.ObjDict.load`.""" od = ObjDict(name="name", a=1, b=None, c="c") with tempfile.TemporaryDirectory() as tempdir: tempath = os.path.join(tempdir, "temp.pkl") od.dump( tempath, protocol=None, fopt="b", fix_imports=True, ) new_od = ObjDict.load( tempath, fopt="b", fix_imports=True, encoding="ASCII", errors="strict", ) # /with # test equality between new and old assert new_od.name == od.name assert new_od.items() == od.items()
def test_ObjDict__reduce__(): """Test :func:`~utilipy.utils.collections.ObjDict.__reduce__`.""" od = ObjDict(name="name", a=1, b=None, c="c") reduced = od.__reduce__() assert reduced[0] == od.__class__ assert reduced[1] == (od.name,) assert reduced[2] == OrderedDict(od.items())
def test_ObjDict_items(): """Test :func:`~utilipy.utils.collections.ObjDict.items`.""" _c = ObjDict("inner", a="A") od = ObjDict(name="name", a=1, b=None, c=_c) # test standard (without keys) assert list(od.items()) == [ ("a", 1), ("b", None), ("c", _c), ] # test when provide keys assert list(od.items("a", "b")) == [ ("a", 1), ("b", None), ] return