Update test_weakset from CPython 3.10.5
@@ -2,8 +2,10 @@ import unittest
from weakref import WeakSet
import string
from collections import UserString as ustr
+from collections.abc import Set, MutableSet
import gc
import contextlib
+from test import support
class Foo:
@@ -47,6 +49,7 @@ class TestWeakSet(unittest.TestCase):
self.assertEqual(len(self.s), len(self.d))
self.assertEqual(len(self.fs), 1)
del self.obj
+ support.gc_collect() # For PyPy or other GCs.
self.assertEqual(len(self.fs), 0)
def test_contains(self):
@@ -56,6 +59,7 @@ class TestWeakSet(unittest.TestCase):
self.assertNotIn(1, self.s)
self.assertIn(self.obj, self.fs)
del self.obj
+ support.gc_collect() # For PyPy or other GCs.
self.assertNotIn(ustr('F'), self.fs)
def test_union(self):
@@ -216,6 +220,7 @@ class TestWeakSet(unittest.TestCase):
self.assertEqual(self.s, dup)
self.assertRaises(TypeError, self.s.add, [])
self.fs.add(Foo())
+ support.gc_collect() # For PyPy or other GCs.
self.assertTrue(len(self.fs) == 1)
self.fs.add(self.obj)
self.assertTrue(len(self.fs) == 1)
@@ -411,6 +416,7 @@ class TestWeakSet(unittest.TestCase):
n1 = len(s)
del it
gc.collect()
+ gc.collect() # For PyPy or other GCs.
n2 = len(s)
# one item may be kept alive inside the iterator
self.assertIn(n1, (0, 1))
@@ -445,6 +451,10 @@ class TestWeakSet(unittest.TestCase):
def test_repr(self):
assert repr(self.s) == repr(self.s.data)
+ def test_abc(self):
+ self.assertIsInstance(self.s, Set)
+ self.assertIsInstance(self.s, MutableSet)
+
if __name__ == "__main__":
unittest.main()
