Skip to content

Update test/test_weakset.py from CPython 3.11.2 #4657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Changes from all commits
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
33 changes: 33 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,32 @@ def test_abc(self):
self.assertIsInstance(self.s, Set)
self.assertIsInstance(self.s, MutableSet)

# TODO: RUSTPYTHON
@unittest.expectedFailure
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()