summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_copy.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-02-06 19:53:22 (GMT)
committerGuido van Rossum <guido@python.org>2003-02-06 19:53:22 (GMT)
commitc7557589063d07ecf8a65e88e6e396f0f750821b (patch)
treeab44a22cff3bd00fc218b2a51ad2d2763646e510 /Lib/test/test_copy.py
parent01892664561cab9ff9ae62c4595137d22c39ac6c (diff)
downloadcpython-c7557589063d07ecf8a65e88e6e396f0f750821b.zip
cpython-c7557589063d07ecf8a65e88e6e396f0f750821b.tar.gz
cpython-c7557589063d07ecf8a65e88e6e396f0f750821b.tar.bz2
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
Diffstat (limited to 'Lib/test/test_copy.py')
-rw-r--r--Lib/test/test_copy.py47
1 files changed, 45 insertions, 2 deletions
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 @@ class TestCopy(unittest.TestCase):
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 @@ class TestCopy(unittest.TestCase):
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 @@ class TestCopy(unittest.TestCase):
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))