summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_gc.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-10-30 21:43:19 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-10-30 21:43:19 (GMT)
commitd4156c16938fe1df957f4cf86420ae5da73dd3f8 (patch)
tree4fa395468950ad78eab189b1aab4bbcb53286d91 /Lib/test/test_gc.py
parentd2217a83d4e2ee9aec1a0bf590820aa77b7ed5e7 (diff)
downloadcpython-d4156c16938fe1df957f4cf86420ae5da73dd3f8.zip
cpython-d4156c16938fe1df957f4cf86420ae5da73dd3f8.tar.gz
cpython-d4156c16938fe1df957f4cf86420ae5da73dd3f8.tar.bz2
Issue #16351: New function gc.get_stats() returns per-generation collection statistics.
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r--Lib/test/test_gc.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index c59b72e..85dbc97 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -610,6 +610,32 @@ class GCTests(unittest.TestCase):
stderr = run_command(code % "gc.DEBUG_SAVEALL")
self.assertNotIn(b"uncollectable objects at shutdown", stderr)
+ def test_get_stats(self):
+ stats = gc.get_stats()
+ self.assertEqual(len(stats), 3)
+ for st in stats:
+ self.assertIsInstance(st, dict)
+ self.assertEqual(set(st),
+ {"collected", "collections", "uncollectable"})
+ self.assertGreaterEqual(st["collected"], 0)
+ self.assertGreaterEqual(st["collections"], 0)
+ self.assertGreaterEqual(st["uncollectable"], 0)
+ # Check that collection counts are incremented correctly
+ if gc.isenabled():
+ self.addCleanup(gc.enable)
+ gc.disable()
+ old = gc.get_stats()
+ gc.collect(0)
+ new = gc.get_stats()
+ self.assertEqual(new[0]["collections"], old[0]["collections"] + 1)
+ self.assertEqual(new[1]["collections"], old[1]["collections"])
+ self.assertEqual(new[2]["collections"], old[2]["collections"])
+ gc.collect(2)
+ new = gc.get_stats()
+ self.assertEqual(new[0]["collections"], old[0]["collections"] + 1)
+ self.assertEqual(new[1]["collections"], old[1]["collections"])
+ self.assertEqual(new[2]["collections"], old[2]["collections"] + 1)
+
class GCCallbackTests(unittest.TestCase):
def setUp(self):