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

Method test_collect_garbage

Lib/test/test_gc.py:1351–1383  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1349
1350 @cpython_only
1351 def test_collect_garbage(self):
1352 self.preclean()
1353 # Each of these cause two objects to be garbage:
1354 Uncollectable()
1355 Uncollectable()
1356 C1055820(666)
1357 gc.collect()
1358 for v in self.visit:
1359 if v[1] != "stop":
1360 continue
1361 info = v[2]
1362 self.assertEqual(info["collected"], 1)
1363 self.assertEqual(info["uncollectable"], 4)
1364
1365 # We should now have the Uncollectables in gc.garbage
1366 self.assertEqual(len(gc.garbage), 4)
1367 for e in gc.garbage:
1368 self.assertIsInstance(e, Uncollectable)
1369
1370 # Now, let our callback handle the Uncollectable instances
1371 self.cleanup=True
1372 self.visit = []
1373 gc.garbage[:] = []
1374 gc.collect()
1375 for v in self.visit:
1376 if v[1] != "stop":
1377 continue
1378 info = v[2]
1379 self.assertEqual(info["collected"], 0)
1380 self.assertEqual(info["uncollectable"], 2)
1381
1382 # Uncollectables should be gone
1383 self.assertEqual(len(gc.garbage), 0)
1384
1385
1386 @requires_subprocess()

Callers

nothing calls this directly

Calls 6

precleanMethod · 0.95
UncollectableClass · 0.85
C1055820Class · 0.85
assertIsInstanceMethod · 0.80
collectMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected