Support all the new stuff supported by the new pickle code:
- subclasses of list or dict
- __reduce__ returning a 4-tuple or 5-tuple
- slots
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index a42b149..846e675 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -41,11 +41,13 @@
self.assert_(y is x)
def test_copy_cant(self):
- class C(object):
+ class Meta(type):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
+ class C:
+ __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.copy, x)
@@ -189,11 +191,13 @@
self.assert_(y is x)
def test_deepcopy_cant(self):
- class C(object):
+ class Meta(type):
def __getattribute__(self, name):
if name == "__reduce__":
raise AttributeError, name
return object.__getattribute__(self, name)
+ class C:
+ __metaclass__ = Meta
x = C()
self.assertRaises(copy.Error, copy.deepcopy, x)
@@ -411,6 +415,45 @@
self.assert_(x is not y)
self.assert_(x["foo"] is not y["foo"])
+ def test_copy_slots(self):
+ class C(object):
+ __slots__ = ["foo"]
+ x = C()
+ x.foo = [42]
+ y = copy.copy(x)
+ self.assert_(x.foo is y.foo)
+
+ def test_deepcopy_slots(self):
+ class C(object):
+ __slots__ = ["foo"]
+ x = C()
+ x.foo = [42]
+ y = copy.deepcopy(x)
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x.foo is not y.foo)
+
+ def test_copy_list_subclass(self):
+ class C(list):
+ pass
+ x = C([[1, 2], 3])
+ x.foo = [4, 5]
+ y = copy.copy(x)
+ self.assertEqual(list(x), list(y))
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x[0] is y[0])
+ self.assert_(x.foo is y.foo)
+
+ def test_deepcopy_list_subclass(self):
+ class C(list):
+ pass
+ x = C([[1, 2], 3])
+ x.foo = [4, 5]
+ y = copy.deepcopy(x)
+ self.assertEqual(list(x), list(y))
+ self.assertEqual(x.foo, y.foo)
+ self.assert_(x[0] is not y[0])
+ self.assert_(x.foo is not y.foo)
+
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCopy))