diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2022-04-06 17:00:14 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-06 17:00:14 (GMT) |
commit | 884eba3c76916889fd6bff3b37b8552bfb4f9566 (patch) | |
tree | 51fd55d6170cdff327ac11d70f1e5ff1aa7e735a /Lib/test/test_set.py | |
parent | f82f9ce3239b9a7e6ffa278658dd9858f64a3c14 (diff) | |
download | cpython-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_set.py')
-rw-r--r-- | Lib/test/test_set.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/Lib/test/test_set.py b/Lib/test/test_set.py index 03b9119..3b57517 100644 --- a/Lib/test/test_set.py +++ b/Lib/test/test_set.py @@ -227,14 +227,17 @@ class TestJointOps: def test_pickling(self): for i in range(pickle.HIGHEST_PROTOCOL + 1): + if type(self.s) not in (set, frozenset): + self.s.x = ['x'] + self.s.z = ['z'] p = pickle.dumps(self.s, i) dup = pickle.loads(p) self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup)) if type(self.s) not in (set, frozenset): - self.s.x = 10 - p = pickle.dumps(self.s, i) - dup = pickle.loads(p) self.assertEqual(self.s.x, dup.x) + self.assertEqual(self.s.z, dup.z) + self.assertFalse(hasattr(self.s, 'y')) + del self.s.x, self.s.z def test_iterator_pickling(self): for proto in range(pickle.HIGHEST_PROTOCOL + 1): @@ -808,6 +811,21 @@ class TestFrozenSetSubclass(TestFrozenSet): # All empty frozenset subclass instances should have different ids self.assertEqual(len(set(map(id, efs))), len(efs)) + +class SetSubclassWithSlots(set): + __slots__ = ('x', 'y', '__dict__') + +class TestSetSubclassWithSlots(unittest.TestCase): + thetype = SetSubclassWithSlots + setUp = TestJointOps.setUp + test_pickling = TestJointOps.test_pickling + +class FrozenSetSubclassWithSlots(frozenset): + __slots__ = ('x', 'y', '__dict__') + +class TestFrozenSetSubclassWithSlots(TestSetSubclassWithSlots): + thetype = FrozenSetSubclassWithSlots + # Tests taken from test_sets.py ============================================= empty_set = set() |