[pypy-svn] r35550 - pypy/dist/pypy/module/_weakref/test

arigo at codespeak.net arigo at codespeak.net
Sun Dec 10 15:23:13 CET 2006


Author: arigo
Date: Sun Dec 10 15:23:10 2006
New Revision: 35550

Modified:
   pypy/dist/pypy/module/_weakref/test/test_weakref.py
Log:
Weakrefs without support from the underlying GC don't really work, it
seems.  Here is an example that breaks on top of the framework GC when
run as 'py.test -A'.  The problem is that we don't know if the lifeline
is deleted at the same time as the object.  In the present case, because
of its __del__ the object is deleted one collection earlier than the
lifeline.



Modified: pypy/dist/pypy/module/_weakref/test/test_weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/test/test_weakref.py	(original)
+++ pypy/dist/pypy/module/_weakref/test/test_weakref.py	Sun Dec 10 15:23:10 2006
@@ -252,6 +252,23 @@
             # leads to the fact that the __del__ of _weakref.ref is not called.
             assert _weakref.getweakrefs(a)[0]() is a
 
+    def test_buggy_case(self):
+        import gc, weakref
+        gone = []
+        class A(object):
+            def __del__(self):
+                gone.append(True)
+        a = A()
+        w = weakref.ref(a)
+        del a
+        tries = 5
+        for i in range(5):
+            if not gone:
+                gc.collect()
+        if gone:
+            a1 = w()
+            assert a1 is None
+
 
 class AppTestProxy(object):
     def setup_class(cls):



More information about the Pypy-commit mailing list