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

Method test_get_stats

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

Source from the content-addressed store, hash-verified

842 self.assertEqual(out.strip(), b'__del__ called')
843
844 def test_get_stats(self):
845 stats = gc.get_stats()
846 self.assertEqual(len(stats), 3)
847 for st in stats:
848 self.assertIsInstance(st, dict)
849 self.assertEqual(
850 set(st),
851 {"collected", "collections", "uncollectable", "candidates", "duration"}
852 )
853 self.assertGreaterEqual(st["collected"], 0)
854 self.assertGreaterEqual(st["collections"], 0)
855 self.assertGreaterEqual(st["uncollectable"], 0)
856 self.assertGreaterEqual(st["candidates"], 0)
857 self.assertGreaterEqual(st["duration"], 0)
858 # Check that collection counts are incremented correctly
859 if gc.isenabled():
860 self.addCleanup(gc.enable)
861 gc.disable()
862 old = gc.get_stats()
863 gc.collect(0)
864 new = gc.get_stats()
865 self.assertEqual(new[0]["collections"], old[0]["collections"] + 1)
866 self.assertEqual(new[1]["collections"], old[1]["collections"])
867 self.assertEqual(new[2]["collections"], old[2]["collections"])
868 self.assertGreater(new[0]["duration"], old[0]["duration"])
869 self.assertEqual(new[1]["duration"], old[1]["duration"])
870 self.assertEqual(new[2]["duration"], old[2]["duration"])
871 for stat in ["collected", "uncollectable", "candidates"]:
872 self.assertGreaterEqual(new[0][stat], old[0][stat])
873 self.assertEqual(new[1][stat], old[1][stat])
874 self.assertEqual(new[2][stat], old[2][stat])
875 gc.collect(2)
876 old, new = new, gc.get_stats()
877 self.assertEqual(new[0]["collections"], old[0]["collections"])
878 self.assertEqual(new[1]["collections"], old[1]["collections"])
879 self.assertEqual(new[2]["collections"], old[2]["collections"] + 1)
880 self.assertEqual(new[0]["duration"], old[0]["duration"])
881 self.assertEqual(new[1]["duration"], old[1]["duration"])
882 self.assertGreater(new[2]["duration"], old[2]["duration"])
883 for stat in ["collected", "uncollectable", "candidates"]:
884 self.assertEqual(new[0][stat], old[0][stat])
885 self.assertEqual(new[1][stat], old[1][stat])
886 self.assertGreaterEqual(new[2][stat], old[2][stat])
887
888 def test_freeze(self):
889 gc.freeze()

Callers

nothing calls this directly

Calls 9

setFunction · 0.85
assertIsInstanceMethod · 0.80
assertGreaterEqualMethod · 0.80
addCleanupMethod · 0.80
assertGreaterMethod · 0.80
get_statsMethod · 0.45
assertEqualMethod · 0.45
disableMethod · 0.45
collectMethod · 0.45

Tested by

no test coverage detected