diff options
Diffstat (limited to 'Lib/test/test_gc.py')
-rw-r--r-- | Lib/test/test_gc.py | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py index e8f52a5..7eb104a 100644 --- a/Lib/test/test_gc.py +++ b/Lib/test/test_gc.py @@ -1,7 +1,6 @@ -import _testcapi import unittest from test.support import (verbose, refcount_test, run_unittest, - strip_python_stderr) + strip_python_stderr, cpython_only) from test.script_helper import assert_python_ok, make_script, temp_dir import sys @@ -14,6 +13,15 @@ try: except ImportError: threading = None +try: + from _testcapi import with_tp_del +except ImportError: + def with_tp_del(cls): + class C(object): + def __new__(cls, *args, **kwargs): + raise TypeError('requires _testcapi.with_tp_del') + return C + ### Support code ############################################################################### @@ -41,7 +49,7 @@ class GC_Detector(object): # gc collects it. self.wr = weakref.ref(C1055820(666), it_happened) -@_testcapi.with_tp_del +@with_tp_del class Uncollectable(object): """Create a reference cycle with multiple __del__ methods. @@ -143,10 +151,11 @@ class GCTests(unittest.TestCase): del a self.assertNotEqual(gc.collect(), 0) + @cpython_only def test_legacy_finalizer(self): # A() is uncollectable if it is part of a cycle, make sure it shows up # in gc.garbage. - @_testcapi.with_tp_del + @with_tp_del class A: def __tp_del__(self): pass class B: @@ -168,10 +177,11 @@ class GCTests(unittest.TestCase): self.fail("didn't find obj in garbage (finalizer)") gc.garbage.remove(obj) + @cpython_only def test_legacy_finalizer_newclass(self): # A() is uncollectable if it is part of a cycle, make sure it shows up # in gc.garbage. - @_testcapi.with_tp_del + @with_tp_del class A(object): def __tp_del__(self): pass class B(object): @@ -570,6 +580,7 @@ class GCTests(unittest.TestCase): # would be damaged, with an empty __dict__. self.assertEqual(x, None) + @cpython_only def test_garbage_at_shutdown(self): import subprocess code = """if 1: @@ -764,6 +775,7 @@ class GCCallbackTests(unittest.TestCase): info = v[2] self.assertEqual(info["generation"], 2) + @cpython_only def test_collect_garbage(self): self.preclean() # Each of these cause four objects to be garbage: Two |