MCPcopy Index your code
hub / github.com/python/cpython / test_len_cycles

Method test_len_cycles

Lib/test/test_weakset.py:406–424  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

WeakSetClass · 0.90
assertInMethod · 0.80
RefCycleClass · 0.70
collectMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected