summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2019-02-23 03:02:06 (GMT)
committerInada Naoki <methane@users.noreply.github.com>2019-02-23 03:02:06 (GMT)
commit175421b58cc97a2555e474f479f30a6c5d2250b0 (patch)
tree05724237baa3c2334c7a0cd07081009cf9a7dc5b /Lib
parentdf5cdc11123a35065bbf1636251447d0bfe789a5 (diff)
downloadcpython-175421b58cc97a2555e474f479f30a6c5d2250b0.zip
cpython-175421b58cc97a2555e474f479f30a6c5d2250b0.tar.gz
cpython-175421b58cc97a2555e474f479f30a6c5d2250b0.tar.bz2
bpo-36016: Add generation option to gc.getobjects() (GH-11909)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_gc.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index 16b2242..65e74d4 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -766,6 +766,38 @@ class GCTests(unittest.TestCase):
gc.unfreeze()
self.assertEqual(gc.get_freeze_count(), 0)
+ def test_get_objects(self):
+ gc.collect()
+ l = []
+ l.append(l)
+ self.assertIn(l, gc.get_objects(generation=0))
+ self.assertNotIn(l, gc.get_objects(generation=1))
+ self.assertNotIn(l, gc.get_objects(generation=2))
+ gc.collect(generation=0)
+ self.assertNotIn(l, gc.get_objects(generation=0))
+ self.assertIn(l, gc.get_objects(generation=1))
+ self.assertNotIn(l, gc.get_objects(generation=2))
+ gc.collect(generation=1)
+ self.assertNotIn(l, gc.get_objects(generation=0))
+ self.assertNotIn(l, gc.get_objects(generation=1))
+ self.assertIn(l, gc.get_objects(generation=2))
+ gc.collect(generation=2)
+ self.assertNotIn(l, gc.get_objects(generation=0))
+ self.assertNotIn(l, gc.get_objects(generation=1))
+ self.assertIn(l, gc.get_objects(generation=2))
+ del l
+ gc.collect()
+
+ def test_get_objects_arguments(self):
+ gc.collect()
+ self.assertEqual(len(gc.get_objects()),
+ len(gc.get_objects(generation=None)))
+
+ self.assertRaises(ValueError, gc.get_objects, 1000)
+ self.assertRaises(ValueError, gc.get_objects, -1000)
+ self.assertRaises(TypeError, gc.get_objects, "1")
+ self.assertRaises(TypeError, gc.get_objects, 1.234)
+
class GCCallbackTests(unittest.TestCase):
def setUp(self):