[pypy-svn] r26385 - in pypy/dist/pypy/module/_weakref: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Apr 26 22:23:42 CEST 2006
Author: cfbolz
Date: Wed Apr 26 22:23:40 2006
New Revision: 26385
Modified:
pypy/dist/pypy/module/_weakref/interp__weakref.py
pypy/dist/pypy/module/_weakref/test/test_weakref.py
Log:
test weakref with callbacks. call callbacks from newest to oldest.
Modified: pypy/dist/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/dist/pypy/module/_weakref/interp__weakref.py (original)
+++ pypy/dist/pypy/module/_weakref/interp__weakref.py Wed Apr 26 22:23:40 2006
@@ -27,7 +27,6 @@
try:
w_self.space.call_function(w_self.w_callable, w_self)
except OperationError, e:
- print e
os.write(2, "XXX\n")
class WeakrefLifeline(object):
@@ -35,7 +34,8 @@
self.refs_w = []
def __del__(self):
- for w_ref in self.refs_w:
+ for i in range(len(self.refs_w) - 1, -1, -1):
+ w_ref = self.refs_w[i]
w_ref.invalidate()
def get_weakref(self, space, w_subtype, w_obj, w_callable):
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 Wed Apr 26 22:23:40 2006
@@ -11,8 +11,36 @@
pass
a = A()
ref = _weakref.ref(a)
- print ref()
assert ref() is a
del a
- print ref()
assert ref() is None
+
+ def test_callback(self):
+ import _weakref
+ class A:
+ pass
+ a1 = A()
+ a2 = A()
+ def callback(ref):
+ a2.ref = ref()
+ ref1 = _weakref.ref(a1, callback)
+ ref2 = _weakref.ref(a1)
+ del a1
+ assert ref1() is None
+ assert a2.ref is None
+
+ def test_callback_order(self):
+ import _weakref
+ class A:
+ pass
+ a1 = A()
+ a2 = A()
+ def callback1(ref):
+ a2.x = 42
+ def callback2(ref):
+ a2.x = 43
+ ref1 = _weakref.ref(a1, callback1)
+ ref2 = _weakref.ref(a1, callback2)
+ del a1
+ assert a2.x == 42
+
More information about the Pypy-commit
mailing list