summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_copy.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-06 18:18:23 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-06 18:18:23 (GMT)
commit90e05b0e25a3e69d23054c5f05cbe5b6ec475ca5 (patch)
treecfe618cc676c9c692ac861100885d8351a73eac1 /Lib/test/test_copy.py
parent93cf58b015f797c9ad2de56f00bce5754cd764d6 (diff)
downloadcpython-90e05b0e25a3e69d23054c5f05cbe5b6ec475ca5.zip
cpython-90e05b0e25a3e69d23054c5f05cbe5b6ec475ca5.tar.gz
cpython-90e05b0e25a3e69d23054c5f05cbe5b6ec475ca5.tar.bz2
Support __reduce__ returning a 4-tuple or 5-tuple.
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r--Lib/test/test_copy.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_copy.py b/Lib/test/test_copy.py
index 90ef3fa..a42b149 100644
--- a/Lib/test/test_copy.py
+++ b/Lib/test/test_copy.py
@@ -375,6 +375,42 @@ class TestCopy(unittest.TestCase):
self.assertEqual(y, x)
self.assert_(y.foo is not x.foo)
+ # Additions for Python 2.3 and pickle protocol 2
+
+ def test_reduce_4tuple(self):
+ class C(list):
+ def __reduce__(self):
+ return (C, (), self.__dict__, iter(self))
+ def __cmp__(self, other):
+ return (cmp(list(self), list(other)) or
+ cmp(self.__dict__, other.__dict__))
+ x = C([[1, 2], 3])
+ y = copy.copy(x)
+ self.assertEqual(x, y)
+ self.assert_(x is not y)
+ self.assert_(x[0] is y[0])
+ y = copy.deepcopy(x)
+ self.assertEqual(x, y)
+ self.assert_(x is not y)
+ self.assert_(x[0] is not y[0])
+
+ def test_reduce_5tuple(self):
+ class C(dict):
+ def __reduce__(self):
+ return (C, (), self.__dict__, None, self.iteritems())
+ def __cmp__(self, other):
+ return (cmp(dict(self), list(dict)) or
+ cmp(self.__dict__, other.__dict__))
+ x = C([("foo", [1, 2]), ("bar", 3)])
+ y = copy.copy(x)
+ self.assertEqual(x, y)
+ self.assert_(x is not y)
+ self.assert_(x["foo"] is y["foo"])
+ y = copy.deepcopy(x)
+ self.assertEqual(x, y)
+ self.assert_(x is not y)
+ self.assert_(x["foo"] is not y["foo"])
+
def test_main():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCopy))