Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update test/test_weakset.py from CPython 3.11.2
  • Loading branch information
CPython Developers authored and dalinaum committed Mar 7, 2023
commit 7b6486cd301709896019f0d5c14cfae0da9d744e
31 changes: 31 additions & 0 deletions Lib/test/test_weakset.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):

Expand Down Expand Up @@ -455,6 +462,30 @@ def test_abc(self):
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()