diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-14 18:37:52 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-14 18:37:52 (GMT) |
commit | 93963569487bd3d13962c92d64a128e27330cf02 (patch) | |
tree | 6966ad6d6148e5ede6183a80a62890470f10d612 /Lib/test | |
parent | b710d7e4c320fb299cf1ab2ec12e3821dc338bc8 (diff) | |
download | cpython-93963569487bd3d13962c92d64a128e27330cf02.zip cpython-93963569487bd3d13962c92d64a128e27330cf02.tar.gz cpython-93963569487bd3d13962c92d64a128e27330cf02.tar.bz2 |
Backout c89febab4648 following private feedback by Guido.
(Issue #17807: Generators can now be finalized even when they are part of a reference cycle)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_generators.py | 53 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 2 |
2 files changed, 1 insertions, 54 deletions
diff --git a/Lib/test/test_generators.py b/Lib/test/test_generators.py index 4e92117..edf3443 100644 --- a/Lib/test/test_generators.py +++ b/Lib/test/test_generators.py @@ -1,55 +1,3 @@ -import gc -import sys -import unittest -import weakref - -from test import support - - -class FinalizationTest(unittest.TestCase): - - def test_frame_resurrect(self): - # A generator frame can be resurrected by a generator's finalization. - def gen(): - nonlocal frame - try: - yield - finally: - frame = sys._getframe() - - g = gen() - wr = weakref.ref(g) - next(g) - del g - support.gc_collect() - self.assertIs(wr(), None) - self.assertTrue(frame) - del frame - support.gc_collect() - - def test_refcycle(self): - # A generator caught in a refcycle gets finalized anyway. - old_garbage = gc.garbage[:] - finalized = False - def gen(): - nonlocal finalized - try: - g = yield - yield 1 - finally: - finalized = True - - g = gen() - next(g) - g.send(g) - self.assertGreater(sys.getrefcount(g), 2) - self.assertFalse(finalized) - del g - support.gc_collect() - self.assertTrue(finalized) - self.assertEqual(gc.garbage, old_garbage) - - tutorial_tests = """ Let's try a simple generator: @@ -1932,7 +1880,6 @@ __test__ = {"tut": tutorial_tests, # so this works as expected in both ways of running regrtest. def test_main(verbose=None): from test import support, test_generators - support.run_unittest(__name__) support.run_doctest(test_generators, verbose) # This part isn't needed for regrtest, but for running the test directly. diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 8314977..4749f24 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -764,7 +764,7 @@ class SizeofTest(unittest.TestCase): nfrees = len(x.f_code.co_freevars) extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\ ncells + nfrees - 1 - check(x, vsize('13P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P')) + check(x, vsize('12P3i' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P')) # function def func(): pass check(func, size('12P')) |