(self)
| 404 | self.assertEqual(len(s), 0) |
| 405 | |
| 406 | def test_len_cycles(self): |
| 407 | N = 20 |
| 408 | items = [RefCycle() for i in range(N)] |
| 409 | s = WeakSet(items) |
| 410 | del items |
| 411 | it = iter(s) |
| 412 | try: |
| 413 | next(it) |
| 414 | except StopIteration: |
| 415 | pass |
| 416 | gc.collect() |
| 417 | n1 = len(s) |
| 418 | del it |
| 419 | gc.collect() |
| 420 | gc.collect() # For PyPy or other GCs. |
| 421 | n2 = len(s) |
| 422 | # one item may be kept alive inside the iterator |
| 423 | self.assertIn(n1, (0, 1)) |
| 424 | self.assertEqual(n2, 0) |
| 425 | |
| 426 | def test_len_race(self): |
| 427 | # Extended sanity checks for len() in the face of cyclic collection |
nothing calls this directly
no test coverage detected