mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-02 19:39:49 +09:00
Update test/test_weakset.py from CPython 3.11.2
This commit is contained in:
31
Lib/test/test_weakset.py
vendored
31
Lib/test/test_weakset.py
vendored
@@ -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):
|
||||
|
||||
@@ -455,6 +462,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()
|
||||
|
||||
Reference in New Issue
Block a user