Exemple #1
0
def test_closure_func():
    subject = indent(5)
    result = subject(10)
    serialized = serializer.dumps(subject, "json")
    restored = serializer.loads(serialized, "json")

    restored_result = restored(10)

    assert_restored_object(subject)
    assert result == restored_result
Exemple #2
0
def test_inheritance():
    subject = ChildCls

    assert_vars(subject)

    serialized = serializer.dumps(subject, "json")
    restored = serializer.loads(serialized, "json")

    assert restored.__bases__[0].__name__ == subject.__bases__[0].__name__
    assert restored.__bases__[1].__name__ == subject.__bases__[1].__name__
    assert type(restored).__name__ == type(subject).__name__
Exemple #3
0
def assert_restored_object(obj):
    for language in serializer.get_formats():
        serialized = serializer.dumps(obj, language)
        restored = serializer.loads(serialized, language)

        attrs = type_to_attrs[type(obj)]

        for attr in attrs:
            if attr in ("__closure__", "__module__"):
                continue

            assert getattr(obj, attr) == getattr(restored, attr)
Exemple #4
0
def test_indent_func():
    subject = indent
    x_result = subject(5)
    y_result = x_result(10)

    serialized = serializer.dumps(subject, "json")
    restored = serializer.loads(serialized, "json")

    restored_x_result = restored(5)
    restored_y_result = restored_x_result(10)

    assert_restored_object(subject)
    assert_restored_object(x_result)

    assert y_result == restored_y_result
Exemple #5
0
def test_globals_func():
    subject = f_globals
    import math

    globals()["math"] = math
    globals()["x"] = 5
    result = subject()

    del math

    serialized = serializer.dumps(subject, "json")

    del globals()["math"]
    del globals()["x"]

    restored = serializer.loads(serialized, "json")

    restored_result = restored()

    assert_restored_object(subject)
    assert result == restored_result