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.
This commit is contained in:
Amaury Forgeot d'Arc 2008-02-15 22:44:20 +00:00
parent f05fa33a6c
commit d8bcbf2b2e
1 changed files with 17 additions and 7 deletions

View File

@ -236,23 +236,33 @@ class GCTests(unittest.TestCase):
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: