示例#1
0
    def test_copy(self):
        class MyMutableObject(object):
            def __init__(self):
                self.attribute = None

        foo = MyMutableObject()
        foo.attribute = True

        a = Json()
        a.immutable = 42
        a.mutable = foo

        b = a.copy()

        # immutable object should not change
        b.immutable = 21
        self.assertEqual(a.immutable, 42)

        # mutable object should change
        b.mutable.attribute = False
        self.assertEqual(a.mutable.attribute, b.mutable.attribute)

        # changing child of b should not affect a
        b.child = "new stuff"
        self.assertTrue(isinstance(a.child, Json))