def test_load_object(): d = Database() id = 18 p = Property('property', 'Test property.', bool, False) m = Method(d, 'import re\ndef method(self, a, b):\n return (a, b, re)') data = dict( id=id, methods=[d.dump_method(m)], properties=[d.dump_property(p)], parents=[] ) o = d.load_object(data) assert d.objects[id] is o assert d.max_id == (id + 1) assert len(o._methods) == 1 m.func = None for method in (m, o._methods[m.name]): method.created.clear() o._methods[m.name].func = None # Otherwise they'll never match. assert o._methods[m.name] == m assert not o._properties assert not o._parents assert not o._children data = dict(id=1, location=2) o = d.load_object(data) assert o._location == 2
def test_custom_object(): d = Database(object_class=CustomObject) o = d.create_object() assert isinstance(o, d.object_class) o = d.load_object(dict(id=1, methods=[])) assert isinstance(o, CustomObject)
def test_load_object_malformed(): d = Database() with raises(LoadObjectError) as err: d.load_object(d) assert err.value.args[0] is d assert isinstance(err.value.__cause__, AttributeError)