diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-06 19:15:57 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-05-06 19:15:57 (GMT) |
commit | 5f454a07a054eb0db7499d8dbd537ff8ce7bda18 (patch) | |
tree | 08557fde41d4a25d1961b38face3ca46bb8c695d /Lib/test/test_gc.py | |
parent | 1df37c657d7b32cfc7e765f13323415ef1c5be31 (diff) | |
download | cpython-5f454a07a054eb0db7499d8dbd537ff8ce7bda18.zip cpython-5f454a07a054eb0db7499d8dbd537ff8ce7bda18.tar.gz cpython-5f454a07a054eb0db7499d8dbd537ff8ce7bda18.tar.bz2 |
Issue #1545463: Global variables caught in reference cycles are now garbage-collected at shutdown.
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index 85dbc97..6b52e5a 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,6 +1,8 @@ import unittest from test.support import (verbose, refcount_test, run_unittest, strip_python_stderr) +from test.script_helper import assert_python_ok, make_script, temp_dir + import sys import time import gc @@ -610,6 +612,40 @@ class GCTests(unittest.TestCase): stderr = run_command(code % "gc.DEBUG_SAVEALL") self.assertNotIn(b"uncollectable objects at shutdown", stderr) + def test_gc_main_module_at_shutdown(self): + # Create a reference cycle through the __main__ module and check + # it gets collected at interpreter shutdown. + code = """if 1: + import weakref + class C: + def __del__(self): + print('__del__ called') + l = [C()] + l.append(l) + """ + rc, out, err = assert_python_ok('-c', code) + self.assertEqual(out.strip(), b'__del__ called') + + def test_gc_ordinary_module_at_shutdown(self): + # Same as above, but with a non-__main__ module. + with temp_dir() as script_dir: + module = """if 1: + import weakref + class C: + def __del__(self): + print('__del__ called') + l = [C()] + l.append(l) + """ + code = """if 1: + import sys + sys.path.insert(0, %r) + import gctest + """ % (script_dir,) + make_script(script_dir, 'gctest', module) + rc, out, err = assert_python_ok('-c', code) + self.assertEqual(out.strip(), b'__del__ called') + def test_get_stats(self): stats = gc.get_stats() self.assertEqual(len(stats), 3) |