[Python-checkins] r60845 - python/trunk/Lib/test/test_gc.py

amaury.forgeotdarc python-checkins at python.org
Fri Feb 15 23:44:20 CET 2008


Author: amaury.forgeotdarc
Date: Fri Feb 15 23:44:20 2008
New Revision: 60845

Modified:
   python/trunk/Lib/test/test_gc.py
Log:
Re-enable tests, they were failing since gc.collect() clears the various freelists.
They still remain fragile.

For example, a call to assertEqual currently does not make any allocation
(which surprised me at first).
But this can change when gc.collect also deletes the numerous "zombie frames" 
attached to each function.



Modified: python/trunk/Lib/test/test_gc.py
==============================================================================
--- python/trunk/Lib/test/test_gc.py	(original)
+++ python/trunk/Lib/test/test_gc.py	Fri Feb 15 23:44:20 2008
@@ -236,23 +236,33 @@
         gc.disable()
         gc.set_threshold(*thresholds)
 
+    # The following two tests are fragile:
+    # They precisely count the number of allocations,
+    # which is highly implementation-dependent.
+    # For example:
+    # - disposed tuples are not freed, but reused
+    # - the call to assertEqual somehow avoids building its args tuple
     def test_get_count(self):
-        return # disable temporarily
+        # Avoid future allocation of method object
+        assertEqual = self.assertEqual
         gc.collect()
-        self.assertEqual(gc.get_count(), (0, 0, 0))
+        assertEqual(gc.get_count(), (0, 0, 0))
         a = dict()
-        self.assertEqual(gc.get_count(), (1, 0, 0))
+        # since gc.collect(), we created two objects:
+        # the dict, and the tuple returned by get_count()
+        assertEqual(gc.get_count(), (2, 0, 0))
 
     def test_collect_generations(self):
-        return # disable temporarily
+        # Avoid future allocation of method object
+        assertEqual = self.assertEqual
         gc.collect()
         a = dict()
         gc.collect(0)
-        self.assertEqual(gc.get_count(), (0, 1, 0))
+        assertEqual(gc.get_count(), (0, 1, 0))
         gc.collect(1)
-        self.assertEqual(gc.get_count(), (0, 0, 1))
+        assertEqual(gc.get_count(), (0, 0, 1))
         gc.collect(2)
-        self.assertEqual(gc.get_count(), (0, 0, 0))
+        assertEqual(gc.get_count(), (0, 0, 0))
 
     def test_trashcan(self):
         class Ouch:


More information about the Python-checkins mailing list