(self)
| 424 | self.assertEqual(n2, 0) |
| 425 | |
| 426 | def test_len_race(self): |
| 427 | # Extended sanity checks for len() in the face of cyclic collection |
| 428 | self.addCleanup(gc.set_threshold, *gc.get_threshold()) |
| 429 | for th in range(1, 100): |
| 430 | N = 20 |
| 431 | gc.collect(0) |
| 432 | gc.set_threshold(th, th, th) |
| 433 | items = [RefCycle() for i in range(N)] |
| 434 | s = WeakSet(items) |
| 435 | del items |
| 436 | # All items will be collected at next garbage collection pass |
| 437 | it = iter(s) |
| 438 | try: |
| 439 | next(it) |
| 440 | except StopIteration: |
| 441 | pass |
| 442 | n1 = len(s) |
| 443 | del it |
| 444 | n2 = len(s) |
| 445 | self.assertGreaterEqual(n1, 0) |
| 446 | self.assertLessEqual(n1, N) |
| 447 | self.assertGreaterEqual(n2, 0) |
| 448 | self.assertLessEqual(n2, n1) |
| 449 | |
| 450 | def test_repr(self): |
| 451 | assert repr(self.s) == repr(self.s.data) |
nothing calls this directly
no test coverage detected