summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorMiss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com>2020-10-15 15:51:48 (GMT)
committerGitHub <noreply@github.com>2020-10-15 15:51:48 (GMT)
commitaeb66c1abbf4ec214e2e80eb972546996d1a1571 (patch)
treec7f9027d0ad5e025fc63d8f48fff5d87533dd6bd /Lib/test
parent47ca6799725bb4c40953bb26ebcd726d1d766361 (diff)
downloadcpython-aeb66c1abbf4ec214e2e80eb972546996d1a1571.zip
cpython-aeb66c1abbf4ec214e2e80eb972546996d1a1571.tar.gz
cpython-aeb66c1abbf4ec214e2e80eb972546996d1a1571.tar.bz2
bpo-41984: GC track all user classes (GH-22701/GH-22707)
(cherry picked from commit c13b847a6f913b72eeb71651ff626390b738d973)
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_finalization.py23
-rw-r--r--Lib/test/test_gc.py6
2 files changed, 24 insertions, 5 deletions
diff --git a/Lib/test/test_finalization.py b/Lib/test/test_finalization.py
index 35d7913..1d13443 100644
--- a/Lib/test/test_finalization.py
+++ b/Lib/test/test_finalization.py
@@ -16,6 +16,15 @@ except ImportError:
raise TypeError('requires _testcapi.with_tp_del')
return C
+try:
+ from _testcapi import without_gc
+except ImportError:
+ def without_gc(cls):
+ class C:
+ def __new__(cls, *args, **kwargs):
+ raise TypeError('requires _testcapi.without_gc')
+ return C
+
from test import support
@@ -94,9 +103,11 @@ class SimpleBase(NonGCSimpleBase):
assert self.id_ == id(self)
+@without_gc
class NonGC(NonGCSimpleBase):
__slots__ = ()
+@without_gc
class NonGCResurrector(NonGCSimpleBase):
__slots__ = ()
@@ -109,8 +120,14 @@ class NonGCResurrector(NonGCSimpleBase):
class Simple(SimpleBase):
pass
-class SimpleResurrector(NonGCResurrector, SimpleBase):
- pass
+# Can't inherit from NonGCResurrector, in case importing without_gc fails.
+class SimpleResurrector(SimpleBase):
+
+ def side_effect(self):
+ """
+ Resurrect self by storing self in a class-wide list.
+ """
+ self.survivors.append(self)
class TestBase:
@@ -178,6 +195,7 @@ class SimpleFinalizationTest(TestBase, unittest.TestCase):
self.assert_survivors([])
self.assertIs(wr(), None)
+ @support.cpython_only
def test_non_gc(self):
with SimpleBase.test():
s = NonGC()
@@ -191,6 +209,7 @@ class SimpleFinalizationTest(TestBase, unittest.TestCase):
self.assert_del_calls(ids)
self.assert_survivors([])
+ @support.cpython_only
def test_non_gc_resurrect(self):
with SimpleBase.test():
s = NonGCResurrector()
diff --git a/Lib/test/test_gc.py b/Lib/test/test_gc.py
index f52db1e..58d4613 100644
--- a/Lib/test/test_gc.py
+++ b/Lib/test/test_gc.py
@@ -576,9 +576,9 @@ class GCTests(unittest.TestCase):
self.assertTrue(gc.is_tracked(UserInt()))
self.assertTrue(gc.is_tracked([]))
self.assertTrue(gc.is_tracked(set()))
- self.assertFalse(gc.is_tracked(UserClassSlots()))
- self.assertFalse(gc.is_tracked(UserFloatSlots()))
- self.assertFalse(gc.is_tracked(UserIntSlots()))
+ self.assertTrue(gc.is_tracked(UserClassSlots()))
+ self.assertTrue(gc.is_tracked(UserFloatSlots()))
+ self.assertTrue(gc.is_tracked(UserIntSlots()))
def test_bug1055820b(self):
# Corresponds to temp2b.py in the bug report.