Beispiel #1
0
def test_0():
    class Foo:
        def __encode__(self, encode):
            return "hello"

    foo = Foo()

    jelly.dumps(foo)
Beispiel #2
0
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)
Beispiel #3
0
def test_2():

    foo = Foo()

    s = jelly.dumps(foo)

    assert s == json.dumps(
        {"JELLY": {
            "class": "test_1.Foo",
            "state": {
                "a": "hello"
            }
        }})
Beispiel #4
0
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"