summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ordered_dict.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-04-06 17:00:14 (GMT)
committerGitHub <noreply@github.com>2022-04-06 17:00:14 (GMT)
commit884eba3c76916889fd6bff3b37b8552bfb4f9566 (patch)
tree51fd55d6170cdff327ac11d70f1e5ff1aa7e735a /Lib/test/test_ordered_dict.py
parentf82f9ce3239b9a7e6ffa278658dd9858f64a3c14 (diff)
downloadcpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.zip
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.gz
cpython-884eba3c76916889fd6bff3b37b8552bfb4f9566.tar.bz2
bpo-26579: Add object.__getstate__(). (GH-2821)
Copying and pickling instances of subclasses of builtin types bytearray, set, frozenset, collections.OrderedDict, collections.deque, weakref.WeakSet, and datetime.tzinfo now copies and pickles instance attributes implemented as slots.
Diffstat (limited to 'Lib/test/test_ordered_dict.py')
-rw-r--r--Lib/test/test_ordered_dict.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/Lib/test/test_ordered_dict.py b/Lib/test/test_ordered_dict.py
index d51296a..37447fd 100644
--- a/Lib/test/test_ordered_dict.py
+++ b/Lib/test/test_ordered_dict.py
@@ -287,6 +287,8 @@ class OrderedDictTests:
# and have a repr/eval round-trip
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
od = OrderedDict(pairs)
+ od.x = ['x']
+ od.z = ['z']
def check(dup):
msg = "\ncopy: %s\nod: %s" % (dup, od)
self.assertIsNot(dup, od, msg)
@@ -295,13 +297,27 @@ class OrderedDictTests:
self.assertEqual(len(dup), len(od))
self.assertEqual(type(dup), type(od))
check(od.copy())
- check(copy.copy(od))
- check(copy.deepcopy(od))
+ dup = copy.copy(od)
+ check(dup)
+ self.assertIs(dup.x, od.x)
+ self.assertIs(dup.z, od.z)
+ self.assertFalse(hasattr(dup, 'y'))
+ dup = copy.deepcopy(od)
+ check(dup)
+ self.assertEqual(dup.x, od.x)
+ self.assertIsNot(dup.x, od.x)
+ self.assertEqual(dup.z, od.z)
+ self.assertIsNot(dup.z, od.z)
+ self.assertFalse(hasattr(dup, 'y'))
# pickle directly pulls the module, so we have to fake it
with replaced_module('collections', self.module):
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
with self.subTest(proto=proto):
- check(pickle.loads(pickle.dumps(od, proto)))
+ dup = pickle.loads(pickle.dumps(od, proto))
+ check(dup)
+ self.assertEqual(dup.x, od.x)
+ self.assertEqual(dup.z, od.z)
+ self.assertFalse(hasattr(dup, 'y'))
check(eval(repr(od)))
update_test = OrderedDict()
update_test.update(od)
@@ -846,6 +862,23 @@ class CPythonOrderedDictSubclassTests(CPythonOrderedDictTests):
pass
+class PurePythonOrderedDictWithSlotsCopyingTests(unittest.TestCase):
+
+ module = py_coll
+ class OrderedDict(py_coll.OrderedDict):
+ __slots__ = ('x', 'y')
+ test_copying = OrderedDictTests.test_copying
+
+
+@unittest.skipUnless(c_coll, 'requires the C version of the collections module')
+class CPythonOrderedDictWithSlotsCopyingTests(unittest.TestCase):
+
+ module = c_coll
+ class OrderedDict(c_coll.OrderedDict):
+ __slots__ = ('x', 'y')
+ test_copying = OrderedDictTests.test_copying
+
+
class PurePythonGeneralMappingTests(mapping_tests.BasicTestMappingProtocol):
@classmethod