summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_weakset.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_weakset.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_weakset.py')
-rw-r--r--Lib/test/test_weakset.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py
index 9b31d5f..d6c8859 100644
--- a/Lib/test/test_weakset.py
+++ b/Lib/test/test_weakset.py
@@ -1,5 +1,6 @@
import unittest
from weakref import WeakSet
+import copy
import string
from collections import UserString as ustr
from collections.abc import Set, MutableSet
@@ -15,6 +16,12 @@ class RefCycle:
def __init__(self):
self.cycle = self
+class WeakSetSubclass(WeakSet):
+ pass
+
+class WeakSetWithSlots(WeakSet):
+ __slots__ = ('x', 'y')
+
class TestWeakSet(unittest.TestCase):
@@ -447,6 +454,30 @@ class TestWeakSet(unittest.TestCase):
self.assertIsInstance(self.s, Set)
self.assertIsInstance(self.s, MutableSet)
+ def test_copying(self):
+ for cls in WeakSet, WeakSetWithSlots:
+ s = cls(self.items)
+ s.x = ['x']
+ s.z = ['z']
+
+ dup = copy.copy(s)
+ self.assertIsInstance(dup, cls)
+ self.assertEqual(dup, s)
+ self.assertIsNot(dup, s)
+ self.assertIs(dup.x, s.x)
+ self.assertIs(dup.z, s.z)
+ self.assertFalse(hasattr(dup, 'y'))
+
+ dup = copy.deepcopy(s)
+ self.assertIsInstance(dup, cls)
+ self.assertEqual(dup, s)
+ self.assertIsNot(dup, s)
+ self.assertEqual(dup.x, s.x)
+ self.assertIsNot(dup.x, s.x)
+ self.assertEqual(dup.z, s.z)
+ self.assertIsNot(dup.z, s.z)
+ self.assertFalse(hasattr(dup, 'y'))
+
if __name__ == "__main__":
unittest.main()