def test_basic(): foo = Foo() flat_foo, refs = flatten(foo) foo_copy = expand(flat_foo, refs) assert foo == foo_copy
def encode(cls, obj): """Birch has circular references and must be flattened.""" flat_obj, refs = flatten(obj) return { '__mlspl_type': [type(obj).__module__, type(obj).__name__], 'dict': flat_obj.__dict__, 'refs': refs }
def test_loop(): loop1 = Loop() loop2 = Loop() loop1.next = loop2 loop2.next = loop1 flat_loop, refs = flatten(loop1) foo_copy = expand(flat_loop, refs) assert foo_copy == foo_copy.next.next assert foo_copy.next == foo_copy.next.next.next