summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_weakref.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_weakref.py')
-rw-r--r--Lib/test/test_weakref.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/Lib/test/test_weakref.py b/Lib/test/test_weakref.py
index f732d7b..00cd7ae 100644
--- a/Lib/test/test_weakref.py
+++ b/Lib/test/test_weakref.py
@@ -1,3 +1,4 @@
+import gc
import sys
import unittest
import UserList
@@ -591,6 +592,37 @@ class ReferencesTestCase(TestBase):
gc.collect()
self.assertEqual(alist, [])
+ def test_gc_during_ref_creation(self):
+ self.check_gc_during_creation(weakref.ref)
+
+ def test_gc_during_proxy_creation(self):
+ self.check_gc_during_creation(weakref.proxy)
+
+ def check_gc_during_creation(self, makeref):
+ thresholds = gc.get_threshold()
+ gc.set_threshold(1, 1, 1)
+ gc.collect()
+ class A:
+ pass
+
+ def callback(*args):
+ pass
+
+ referenced = A()
+
+ a = A()
+ a.a = a
+ a.wr = makeref(referenced)
+
+ try:
+ # now make sure the object and the ref get labeled as
+ # cyclic trash:
+ a = A()
+ a.wrc = weakref.ref(referenced, callback)
+
+ finally:
+ gc.set_threshold(*thresholds)
+
class Object:
def __init__(self, arg):
self.arg = arg