annotate Lib/test/test_copy.py @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents c40f187af6dd
children 6768b2350c57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """Unit tests for the copy module."""
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 import copy
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
4 import copy_reg
54099
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
5 import weakref
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
6 import operator
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
7
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 import unittest
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 from test import test_support
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 class TestCopy(unittest.TestCase):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # Attempt full line coverage of copy.py from top to bottom
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
14
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 def test_exceptions(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 self.assert_(copy.Error is copy.error)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 self.assert_(issubclass(copy.Error, Exception))
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 # The copy() method
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 def test_copy_basic(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 x = 42
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 self.assertEqual(x, y)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
25
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 def test_copy_copy(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 def __copy__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 return C(self.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 self.assertEqual(y.__class__, x.__class__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 self.assertEqual(y.foo, x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
36
27754
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
37 def test_copy_registry(self):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
38 class C(object):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
39 def __new__(cls, foo):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
40 obj = object.__new__(cls)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
41 obj.foo = foo
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
42 return obj
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
43 def pickle_C(obj):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
44 return (C, (obj.foo,))
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
45 x = C(42)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
46 self.assertRaises(TypeError, copy.copy, x)
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
47 copy_reg.pickle(C, pickle_C, C)
27754
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
48 y = copy.copy(x)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
49
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
50 def test_copy_reduce_ex(self):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
51 class C(object):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
52 def __reduce_ex__(self, proto):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
53 return ""
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
54 def __reduce__(self):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
55 raise test_support.TestFailed, "shouldn't call this"
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
56 x = C()
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
57 y = copy.copy(x)
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
58 self.assert_(y is x)
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
59
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
60 def test_copy_reduce(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
61 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
62 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
63 return ""
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
64 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 self.assert_(y is x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
67
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 def test_copy_cant(self):
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
69 class C(object):
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
70 def __getattribute__(self, name):
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
71 if name.startswith("__reduce"):
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 raise AttributeError, name
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
73 return object.__getattribute__(self, name)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 self.assertRaises(copy.Error, copy.copy, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
76
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 # Type-specific _copy_xxx() methods
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
78
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 def test_copy_atomic(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 class Classic:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 class NewStyle(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 def f():
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 tests = [None, 42, 2L**100, 3.14, True, False, 1j,
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 "hello", u"hello\u1234", f.func_code,
29458
8bed55203559 Copy builtin functions as atomic. Fixes #746304. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29435
diff changeset
88 NewStyle, xrange(10), Classic, max]
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 for x in tests:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30801
diff changeset
90 self.assert_(copy.copy(x) is x, repr(x))
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
91
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 def test_copy_list(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 x = [1, 2, 3]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
95
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 def test_copy_tuple(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 x = (1, 2, 3)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
98 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
99
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
100 def test_copy_dict(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
101 x = {"foo": 1, "bar": 2}
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
102 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 def test_copy_inst_vanilla(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
106 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
112
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
113 def test_copy_inst_copy(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
114 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 def __copy__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 return C(self.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 def test_copy_inst_getinitargs(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
125 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
127 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
128 def __getinitargs__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
129 return (self.foo,)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
130 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
131 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
132 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
133 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
134
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
135 def test_copy_inst_getstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
136 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
137 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
139 def __getstate__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
140 return {"foo": self.foo}
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
145
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 def test_copy_inst_setstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
147 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
150 def __setstate__(self, state):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 self.foo = state["foo"]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
156
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 def test_copy_inst_getstate_setstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 def __getstate__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 return self.foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 def __setstate__(self, state):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
164 self.foo = state
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 self.assertEqual(copy.copy(x), x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
169
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 # The deepcopy() method
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
171
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 def test_deepcopy_basic(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
173 x = 42
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 def test_deepcopy_memo(self):
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
178 # Tests of reflexive objects are under type-specific sections below.
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
179 # This tests only repetitions of objects.
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
180 x = []
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
181 x = [x, x]
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
182 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
183 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
184 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
185 self.assert_(y[0] is not x[0])
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
186 self.assert_(y[0] is y[1])
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
187
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 def test_deepcopy_issubclass(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 # XXX Note: there's no way to test the TypeError coming out of
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 # issubclass() -- this can only happen when an extension
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 # module defines a "type" that doesn't formally inherit from
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 # type.
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 class Meta(type):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 __metaclass__ = Meta
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 self.assertEqual(copy.deepcopy(C), C)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
199 def test_deepcopy_deepcopy(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
200 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
201 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
202 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
203 def __deepcopy__(self, memo=None):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
204 return C(self.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
205 x = C(42)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
206 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
207 self.assertEqual(y.__class__, x.__class__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
208 self.assertEqual(y.foo, x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
209
27754
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
210 def test_deepcopy_registry(self):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
211 class C(object):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
212 def __new__(cls, foo):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
213 obj = object.__new__(cls)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
214 obj.foo = foo
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
215 return obj
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
216 def pickle_C(obj):
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
217 return (C, (obj.foo,))
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
218 x = C(42)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
219 self.assertRaises(TypeError, copy.deepcopy, x)
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 46865
diff changeset
220 copy_reg.pickle(C, pickle_C, C)
27754
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
221 y = copy.deepcopy(x)
6b1789ac2f95 Add support for copy_reg.dispatch_table.
Guido van Rossum <guido@python.org>
parents: 27736
diff changeset
222
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
223 def test_deepcopy_reduce_ex(self):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
224 class C(object):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
225 def __reduce_ex__(self, proto):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
226 return ""
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
227 def __reduce__(self):
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
228 raise test_support.TestFailed, "shouldn't call this"
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
229 x = C()
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
230 y = copy.deepcopy(x)
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
231 self.assert_(y is x)
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
232
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
233 def test_deepcopy_reduce(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
235 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
236 return ""
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
237 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 self.assert_(y is x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
240
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
241 def test_deepcopy_cant(self):
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
242 class C(object):
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
243 def __getattribute__(self, name):
27959
cc4ad9afa21d Use __reduce_ex__ in copy.py. The test_*copy_cant() tests are simpler again.
Guido van Rossum <guido@python.org>
parents: 27755
diff changeset
244 if name.startswith("__reduce"):
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
245 raise AttributeError, name
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
246 return object.__getattribute__(self, name)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
247 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
248 self.assertRaises(copy.Error, copy.deepcopy, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
249
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
250 # Type-specific _deepcopy_xxx() methods
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
251
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
252 def test_deepcopy_atomic(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
253 class Classic:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
254 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
255 class NewStyle(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
256 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
257 def f():
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
258 pass
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
259 tests = [None, 42, 2L**100, 3.14, True, False, 1j,
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 "hello", u"hello\u1234", f.func_code,
29458
8bed55203559 Copy builtin functions as atomic. Fixes #746304. Will backport to 2.2.
Martin v. Löwis <martin@v.loewis.de>
parents: 29435
diff changeset
261 NewStyle, xrange(10), Classic, max]
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 for x in tests:
31515
71a294bd7950 Replace backticks with repr() or "%r"
Walter Dörwald <walter@livinglogic.de>
parents: 30801
diff changeset
263 self.assert_(copy.deepcopy(x) is x, repr(x))
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 def test_deepcopy_list(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 x = [[1, 2], 3]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
267 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
269 self.assert_(x is not y)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
270 self.assert_(x[0] is not y[0])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
271
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
272 def test_deepcopy_reflexive_list(self):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
273 x = []
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
274 x.append(x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
275 y = copy.deepcopy(x)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
276 self.assertRaises(RuntimeError, cmp, y, x)
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
277 self.assert_(y is not x)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
278 self.assert_(y[0] is y)
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
279 self.assertEqual(len(y), 1)
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
280
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 def test_deepcopy_tuple(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 x = ([1, 2], 3)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
284 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 self.assert_(x is not y)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
286 self.assert_(x[0] is not y[0])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
287
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
288 def test_deepcopy_reflexive_tuple(self):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
289 x = ([],)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
290 x[0].append(x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
291 y = copy.deepcopy(x)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
292 self.assertRaises(RuntimeError, cmp, y, x)
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
293 self.assert_(y is not x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
294 self.assert_(y[0] is not x[0])
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
295 self.assert_(y[0][0] is y)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
296
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 def test_deepcopy_dict(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
298 x = {"foo": [1, 2], "bar": 3}
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
299 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
300 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
301 self.assert_(x is not y)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
302 self.assert_(x["foo"] is not y["foo"])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
303
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
304 def test_deepcopy_reflexive_dict(self):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
305 x = {}
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
306 x['foo'] = x
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
307 y = copy.deepcopy(x)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
308 self.assertRaises(RuntimeError, cmp, y, x)
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
309 self.assert_(y is not x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
310 self.assert_(y['foo'] is y)
30801
c42c40034536 Deleting cyclic object comparison.
Armin Rigo <arigo@tunes.org>
parents: 29458
diff changeset
311 self.assertEqual(len(y), 1)
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
312
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
313 def test_deepcopy_keepalive(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
314 memo = {}
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 x = 42
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 y = copy.deepcopy(x, memo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
317 self.assert_(memo[id(x)] is x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
318
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 def test_deepcopy_inst_vanilla(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
322 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
323 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
324 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
327 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
329
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 def test_deepcopy_inst_deepcopy(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
331 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 def __deepcopy__(self, memo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 return C(copy.deepcopy(self.foo, memo))
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
343
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
344 def test_deepcopy_inst_getinitargs(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
345 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
346 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
347 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
348 def __getinitargs__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 return (self.foo,)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
354 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
355 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
358 def test_deepcopy_inst_getstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
359 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
360 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
361 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 def __getstate__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 return {"foo": self.foo}
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
366 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
368 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
371
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
372 def test_deepcopy_inst_setstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
373 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
375 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 def __setstate__(self, state):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
377 self.foo = state["foo"]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
378 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
380 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
383 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
385
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
386 def test_deepcopy_inst_getstate_setstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
387 class C:
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
388 def __init__(self, foo):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
389 self.foo = foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
390 def __getstate__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
391 return self.foo
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 def __setstate__(self, state):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
393 self.foo = state
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
394 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
395 return cmp(self.foo, other.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
396 x = C([42])
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
397 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 self.assert_(y is not x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
401
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
402 def test_deepcopy_reflexive_inst(self):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
403 class C:
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
404 pass
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
405 x = C()
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
406 x.foo = x
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
407 y = copy.deepcopy(x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
408 self.assert_(y is not x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
409 self.assert_(y.foo is y)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
410
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 # _reconstruct()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
412
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 def test_reconstruct_string(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
415 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 return ""
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
417 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
418 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
419 self.assert_(y is x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
420 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 self.assert_(y is x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
422
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 def test_reconstruct_nostate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
425 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
426 return (C, ())
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
427 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
428 x.foo = 42
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
430 self.assert_(y.__class__ is x.__class__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
431 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
432 self.assert_(y.__class__ is x.__class__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
433
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
434 def test_reconstruct_state(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
435 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
436 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
437 return (C, (), self.__dict__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
438 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
439 return cmp(self.__dict__, other.__dict__)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 47189
diff changeset
440 __hash__ = None # Silence Py3k warning
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
441 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
442 x.foo = [42]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
443 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
444 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
445 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
446 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
447 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
448
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
449 def test_reconstruct_state_setstate(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
450 class C(object):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
451 def __reduce__(self):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 return (C, (), self.__dict__)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
453 def __setstate__(self, state):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
454 self.__dict__.update(state)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
455 def __cmp__(self, other):
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
456 return cmp(self.__dict__, other.__dict__)
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 47189
diff changeset
457 __hash__ = None # Silence Py3k warning
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
458 x = C()
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
459 x.foo = [42]
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
460 y = copy.copy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
462 y = copy.deepcopy(x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
463 self.assertEqual(y, x)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
464 self.assert_(y.foo is not x.foo)
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
465
29435
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
466 def test_reconstruct_reflexive(self):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
467 class C(object):
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
468 pass
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
469 x = C()
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
470 x.foo = x
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
471 y = copy.deepcopy(x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
472 self.assert_(y is not x)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
473 self.assert_(y.foo is y)
0ba7c101648a SF patch 707900, fixing bug 702858, by Steven Taschuk.
Guido van Rossum <guido@python.org>
parents: 29382
diff changeset
474
27727
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
475 # Additions for Python 2.3 and pickle protocol 2
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
476
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
477 def test_reduce_4tuple(self):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
478 class C(list):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
479 def __reduce__(self):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
480 return (C, (), self.__dict__, iter(self))
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
481 def __cmp__(self, other):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
482 return (cmp(list(self), list(other)) or
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
483 cmp(self.__dict__, other.__dict__))
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 47189
diff changeset
484 __hash__ = None # Silence Py3k warning
27727
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
485 x = C([[1, 2], 3])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
486 y = copy.copy(x)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
487 self.assertEqual(x, y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
488 self.assert_(x is not y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
489 self.assert_(x[0] is y[0])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
490 y = copy.deepcopy(x)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
491 self.assertEqual(x, y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
492 self.assert_(x is not y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
493 self.assert_(x[0] is not y[0])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
494
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
495 def test_reduce_5tuple(self):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
496 class C(dict):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
497 def __reduce__(self):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
498 return (C, (), self.__dict__, None, self.iteritems())
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
499 def __cmp__(self, other):
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
500 return (cmp(dict(self), list(dict)) or
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
501 cmp(self.__dict__, other.__dict__))
48213
7527da2b05e8 Issue 2235: Py3k warnings are now emitted for classes that will no longer inherit a__hash__ implementation from a parent class in Python 3.x. The standard library and test suite have been updated to not emit these warnings.
Nick Coghlan <ncoghlan@gmail.com>
parents: 47189
diff changeset
502 __hash__ = None # Silence Py3k warning
27727
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
503 x = C([("foo", [1, 2]), ("bar", 3)])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
504 y = copy.copy(x)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
505 self.assertEqual(x, y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
506 self.assert_(x is not y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
507 self.assert_(x["foo"] is y["foo"])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
508 y = copy.deepcopy(x)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
509 self.assertEqual(x, y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
510 self.assert_(x is not y)
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
511 self.assert_(x["foo"] is not y["foo"])
d502187b2b06 Support __reduce__ returning a 4-tuple or 5-tuple.
Guido van Rossum <guido@python.org>
parents: 27725
diff changeset
512
27733
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
513 def test_copy_slots(self):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
514 class C(object):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
515 __slots__ = ["foo"]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
516 x = C()
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
517 x.foo = [42]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
518 y = copy.copy(x)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
519 self.assert_(x.foo is y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
520
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
521 def test_deepcopy_slots(self):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
522 class C(object):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
523 __slots__ = ["foo"]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
524 x = C()
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
525 x.foo = [42]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
526 y = copy.deepcopy(x)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
527 self.assertEqual(x.foo, y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
528 self.assert_(x.foo is not y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
529
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
530 def test_copy_list_subclass(self):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
531 class C(list):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
532 pass
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
533 x = C([[1, 2], 3])
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
534 x.foo = [4, 5]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
535 y = copy.copy(x)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
536 self.assertEqual(list(x), list(y))
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
537 self.assertEqual(x.foo, y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
538 self.assert_(x[0] is y[0])
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
539 self.assert_(x.foo is y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
540
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
541 def test_deepcopy_list_subclass(self):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
542 class C(list):
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
543 pass
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
544 x = C([[1, 2], 3])
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
545 x.foo = [4, 5]
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
546 y = copy.deepcopy(x)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
547 self.assertEqual(list(x), list(y))
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
548 self.assertEqual(x.foo, y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
549 self.assert_(x[0] is not y[0])
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
550 self.assert_(x.foo is not y.foo)
e5e242cf46b1 Support all the new stuff supported by the new pickle code:
Guido van Rossum <guido@python.org>
parents: 27727
diff changeset
551
27736
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
552 def test_copy_tuple_subclass(self):
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
553 class C(tuple):
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
554 pass
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
555 x = C([1, 2, 3])
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
556 self.assertEqual(tuple(x), (1, 2, 3))
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
557 y = copy.copy(x)
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
558 self.assertEqual(tuple(y), (1, 2, 3))
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
559
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
560 def test_deepcopy_tuple_subclass(self):
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
561 class C(tuple):
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
562 pass
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
563 x = C([[1, 2], 3])
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
564 self.assertEqual(tuple(x), ([1, 2], 3))
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
565 y = copy.deepcopy(x)
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
566 self.assertEqual(tuple(y), ([1, 2], 3))
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
567 self.assert_(x is not y)
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
568 self.assert_(x[0] is not y[0])
db416bd18d4f Fix a bug in the way __getnewargs__ was handled.
Guido van Rossum <guido@python.org>
parents: 27733
diff changeset
569
29382
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
570 def test_getstate_exc(self):
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
571 class EvilState(object):
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
572 def __getstate__(self):
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
573 raise ValueError, "ain't got no stickin' state"
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
574 self.assertRaises(ValueError, copy.copy, EvilState())
585e303a9491 Fix SF #749831, copy raises SystemError when getstate raises exception
Neal Norwitz <nnorwitz@gmail.com>
parents: 28917
diff changeset
575
36656
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
576 def test_copy_function(self):
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
577 self.assertEqual(copy.copy(global_foo), global_foo)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
578 def foo(x, y): return x+y
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
579 self.assertEqual(copy.copy(foo), foo)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
580 bar = lambda: None
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
581 self.assertEqual(copy.copy(bar), bar)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
582
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
583 def test_deepcopy_function(self):
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
584 self.assertEqual(copy.deepcopy(global_foo), global_foo)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
585 def foo(x, y): return x+y
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
586 self.assertEqual(copy.deepcopy(foo), foo)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
587 bar = lambda: None
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
588 self.assertEqual(copy.deepcopy(bar), bar)
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
589
54099
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
590 def _check_weakref(self, _copy):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
591 class C(object):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
592 pass
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
593 obj = C()
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
594 x = weakref.ref(obj)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
595 y = _copy(x)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
596 self.assertTrue(y is x)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
597 del obj
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
598 y = _copy(x)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
599 self.assertTrue(y is x)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
600
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
601 def test_copy_weakref(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
602 self._check_weakref(copy.copy)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
603
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
604 def test_deepcopy_weakref(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
605 self._check_weakref(copy.deepcopy)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
606
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
607 def _check_copy_weakdict(self, _dicttype):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
608 class C(object):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
609 pass
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
610 a, b, c, d = [C() for i in xrange(4)]
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
611 u = _dicttype()
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
612 u[a] = b
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
613 u[c] = d
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
614 v = copy.copy(u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
615 self.assertFalse(v is u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
616 self.assertEqual(v, u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
617 self.assertEqual(v[a], b)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
618 self.assertEqual(v[c], d)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
619 self.assertEqual(len(v), 2)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
620 del c, d
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
621 self.assertEqual(len(v), 1)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
622 x, y = C(), C()
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
623 # The underlying containers are decoupled
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
624 v[x] = y
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
625 self.assertFalse(x in u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
626
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
627 def test_copy_weakkeydict(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
628 self._check_copy_weakdict(weakref.WeakKeyDictionary)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
629
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
630 def test_copy_weakvaluedict(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
631 self._check_copy_weakdict(weakref.WeakValueDictionary)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
632
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
633 def test_deepcopy_weakkeydict(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
634 class C(object):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
635 def __init__(self, i):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
636 self.i = i
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
637 a, b, c, d = [C(i) for i in xrange(4)]
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
638 u = weakref.WeakKeyDictionary()
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
639 u[a] = b
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
640 u[c] = d
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
641 # Keys aren't copied, values are
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
642 v = copy.deepcopy(u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
643 self.assertNotEqual(v, u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
644 self.assertEqual(len(v), 2)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
645 self.assertFalse(v[a] is b)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
646 self.assertFalse(v[c] is d)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
647 self.assertEqual(v[a].i, b.i)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
648 self.assertEqual(v[c].i, d.i)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
649 del c
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
650 self.assertEqual(len(v), 1)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
651
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
652 def test_deepcopy_weakvaluedict(self):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
653 class C(object):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
654 def __init__(self, i):
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
655 self.i = i
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
656 a, b, c, d = [C(i) for i in xrange(4)]
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
657 u = weakref.WeakValueDictionary()
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
658 u[a] = b
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
659 u[c] = d
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
660 # Keys are copied, values aren't
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
661 v = copy.deepcopy(u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
662 self.assertNotEqual(v, u)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
663 self.assertEqual(len(v), 2)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
664 (x, y), (z, t) = sorted(v.items(), key=lambda (k, v): k.i)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
665 self.assertFalse(x is a)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
666 self.assertEqual(x.i, a.i)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
667 self.assertTrue(y is b)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
668 self.assertFalse(z is c)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
669 self.assertEqual(z.i, c.i)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
670 self.assertTrue(t is d)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
671 del x, y, z, t
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
672 del d
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
673 self.assertEqual(len(v), 1)
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
674
c40f187af6dd Issue #2116: Weak references and weak dictionaries now support copy()ing and deepcopy()ing.
Antoine Pitrou <solipsis@pitrou.net>
parents: 48213
diff changeset
675
36656
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
676 def global_foo(x, y): return x+y
92ce8bb8b12a - Patch 1433928:
Guido van Rossum <guido@python.org>
parents: 31515
diff changeset
677
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 def test_main():
28917
1741af48fd9f Combine the functionality of test_support.run_unittest()
Walter Dörwald <walter@livinglogic.de>
parents: 27959
diff changeset
679 test_support.run_unittest(TestCopy)
27725
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
680
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
681 if __name__ == "__main__":
f2f06b6ecdd7 A test suite for the copy module. This should provide full code
Guido van Rossum <guido@python.org>
parents:
diff changeset
682 test_main()