def test_0(): class Foo: def __encode__(self, encode): return "hello" foo = Foo() jelly.dumps(foo)
def test_1(): # the __encode__ method of an object must return something that is json serializable class Bar: pass class Foo: def __encode__(self, encode): return Bar() foo = Foo() with pytest.raises(TypeError) as excinfo: jelly.dumps(foo)
def test_2(): foo = Foo() s = jelly.dumps(foo) assert s == json.dumps( {"JELLY": { "class": "test_1.Foo", "state": { "a": "hello" } }})
def test_4(): foo = Bar() s = jelly.dumps(foo) assert s == json.dumps( {"JELLY": { "class": "test_1.Bar", "state": { "a": "hello" } }}) obj = jelly.loads(s) assert isinstance(obj, Bar) assert obj.a == "hello"