def test_WeakObject(self):
"""
Tests basic extended weak object support.
"""
obj = TestClass()
ref = weakref.ref(obj)
objref = weakobj.objectref(obj)
objref2 = weakobj.objectref(obj)
self.assertEquals(objref, objref2)
self.assertEquals(objref.foo(), obj.foo())
# Delete what should be the only reference to the original object.
del obj
self.assertEqual(ref(), None)
try:
objref.foo()
except weakref.ReferenceError:
pass
else:
self.fail('Weak object should be invalidated')
评论列表
文章目录