def test_dump_method(): d = Database() name = 'test' code = 'def %s(self):\n return 1234' % name m = Method(d, code) actual = d.dump_method(m) expected = dict(name=name, code=code) assert actual == expected
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