[pypy-svn] r58913 - in pypy/branch/2.5-merge: lib-python/modified-2.5.2/test pypy/module/_weakref
iko at codespeak.net
iko at codespeak.net
Fri Oct 10 16:34:53 CEST 2008
Author: iko
Date: Fri Oct 10 16:34:52 2008
New Revision: 58913
Modified:
pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_weakref.py
pypy/branch/2.5-merge/pypy/module/_weakref/interp__weakref.py
Log:
(iko, cfbolz)
Clean up test_weakref and exclude some more implementation details
Allow weakref.ref subclasses to have additional arguments to __init__
(fixes failing doctest)
Modified: pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_weakref.py
==============================================================================
--- pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_weakref.py (original)
+++ pypy/branch/2.5-merge/lib-python/modified-2.5.2/test/test_weakref.py Fri Oct 10 16:34:52 2008
@@ -69,9 +69,7 @@
ref1 = weakref.ref(o, self.callback)
ref2 = weakref.ref(o, self.callback)
del o
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(ref1() is None,
"expected reference to be invalidated")
self.assert_(ref2() is None,
@@ -103,17 +101,16 @@
ref1 = weakref.proxy(o, self.callback)
ref2 = weakref.proxy(o, self.callback)
del o
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
def check(proxy):
proxy.bar
self.assertRaises(weakref.ReferenceError, check, ref1)
self.assertRaises(weakref.ReferenceError, check, ref2)
- # Works only with refcounting
- # self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
+ if test_support.check_impl_detail:
+ # Works only with refcounting
+ self.assertRaises(weakref.ReferenceError, bool, weakref.proxy(C()))
self.assert_(self.cbcalled == 2)
def check_basic_ref(self, factory):
@@ -130,9 +127,7 @@
o = factory()
ref = weakref.ref(o, self.callback)
del o
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(self.cbcalled == 1,
"callback did not properly set 'cbcalled'")
@@ -158,7 +153,7 @@
self.assert_(weakref.getweakrefcount(o) == 2,
"wrong weak ref count for object")
del proxy
- gc.collect()
+ test_support.gc_collect()
self.assert_(weakref.getweakrefcount(o) == 1,
"wrong weak ref count for object after deleting proxy")
@@ -304,7 +299,7 @@
"got wrong number of weak reference objects")
del ref1, ref2, proxy1, proxy2
- gc.collect()
+ test_support.gc_collect()
self.assert_(weakref.getweakrefcount(o) == 0,
"weak reference objects not unlinked from"
" referent when discarded.")
@@ -318,7 +313,7 @@
ref1 = weakref.ref(o, self.callback)
ref2 = weakref.ref(o, self.callback)
del ref1
- gc.collect()
+ test_support.gc_collect()
self.assert_(weakref.getweakrefs(o) == [ref2],
"list of refs does not match")
@@ -326,14 +321,12 @@
ref1 = weakref.ref(o, self.callback)
ref2 = weakref.ref(o, self.callback)
del ref2
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(weakref.getweakrefs(o) == [ref1],
"list of refs does not match")
del ref1
- gc.collect()
+ test_support.gc_collect()
self.assert_(weakref.getweakrefs(o) == [],
"list of refs not cleared")
@@ -535,7 +528,8 @@
del c1, c2, C, D
gc.collect()
- def XXX_test_callback_in_cycle_resurrection(self):
+ @test_support.impl_detail
+ def test_callback_in_cycle_resurrection(self):
# We can't guarrantee the behaviour tested with our
# current weakref implementations.
# If an object and a weakref to it gets collected at the
@@ -585,8 +579,9 @@
gc.collect()
self.assertEqual(alist, [])
- def XXX_test_callbacks_on_callback(self):
- # See XXX_test_callback_in_cycle_resurrection above
+ @test_support.impl_detail
+ def test_callbacks_on_callback(self):
+ # See test_callback_in_cycle_resurrection above
import gc
# Set up weakref callbacks *on* weakref callbacks.
@@ -634,9 +629,10 @@
# gc.get/set_threshold does not exist in pypy
# The tests calling this function probaly don't test anything
# usefull anymore
+
+ if not test_support.check_impl_detail:
+ return
- #thresholds = gc.get_threshold()
- #gc.set_threshold(1, 1, 1)
gc.collect()
class A:
pass
@@ -657,7 +653,7 @@
weakref.ref(referenced, callback)
finally:
- pass #gc.set_threshold(*thresholds)
+ gc.set_threshold(*thresholds)
def test_ref_created_during_del(self):
# Bug #1377858
@@ -766,27 +762,21 @@
self.assert_(items1 == items2,
"cloning of weak-valued dictionary did not work!")
del items1, items2
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == self.COUNT)
del objects[0]
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == (self.COUNT - 1),
"deleting object did not cause dictionary update")
del objects, o
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == 0,
"deleting the values did not clear the dictionary")
# regression on SF bug #447152:
dict = weakref.WeakValueDictionary()
self.assertRaises(KeyError, dict.__getitem__, 1)
dict[2] = C()
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assertRaises(KeyError, dict.__getitem__, 2)
def test_weak_keys(self):
@@ -806,18 +796,14 @@
self.assert_(set(items1) == set(items2),
"cloning of weak-keyed dictionary did not work!")
del items1, items2
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == self.COUNT)
del objects[0]
- gc.collect()
- gc.collect()
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == (self.COUNT - 1),
"deleting object did not cause dictionary update")
del objects, o
- gc.collect()
+ test_support.gc_collect()
self.assert_(len(dict) == 0,
"deleting the keys did not clear the dictionary")
o = Object(42)
@@ -935,13 +921,13 @@
self.assert_(len(weakdict) == 2)
k, v = weakdict.popitem()
self.assert_(len(weakdict) == 1)
- if k is key1:
+ if k == key1:
self.assert_(v is value1)
else:
self.assert_(v is value2)
k, v = weakdict.popitem()
self.assert_(len(weakdict) == 0)
- if k is key1:
+ if k == key1:
self.assert_(v is value1)
else:
self.assert_(v is value2)
@@ -1068,7 +1054,7 @@
for o in objs:
d[o] = o.value
del o # now the only strong references to keys are in objs
- gc.collect()
+ test_support.gc_collect()
# Find the order in which iterkeys sees the keys.
objs = d.keys()
# Reverse it, so that the iteration implementation of __delitem__
@@ -1087,7 +1073,7 @@
for o in objs:
count += 1
del d[o]
- gc.collect()
+ test_support.gc_collect()
self.assertEqual(len(d), 0)
self.assertEqual(count, 2)
Modified: pypy/branch/2.5-merge/pypy/module/_weakref/interp__weakref.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/module/_weakref/interp__weakref.py (original)
+++ pypy/branch/2.5-merge/pypy/module/_weakref/interp__weakref.py Fri Oct 10 16:34:52 2008
@@ -143,7 +143,12 @@
return w_obj
-def descr__new__weakref(space, w_subtype, w_obj, w_callable=None):
+def descr__new__weakref(space, w_subtype, w_obj, __args__):
+ args_w, kw_w = __args__.unpack()
+ if args_w:
+ w_callable = args_w[0]
+ else:
+ w_callable = space.w_None
lifeline = w_obj.getweakref()
if lifeline is None:
lifeline = WeakrefLifeline(space)
@@ -183,7 +188,8 @@
__doc__ = """A weak reference to an object 'obj'. A 'callback' can given,
which is called with the weak reference as an argument when 'obj'
is about to be finalized.""",
- __new__ = interp2app(descr__new__weakref),
+ __new__ = interp2app(descr__new__weakref,
+ unwrap_spec=[ObjSpace, W_Root, W_Root, Arguments]),
__eq__ = interp2app(descr__eq__,
unwrap_spec=[ObjSpace, W_Weakref, W_Root]),
__ne__ = interp2app(descr__ne__,
More information about the Pypy-commit
mailing list