MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_get_stats

Method test_get_stats

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected