[Python-checkins] python/dist/src/Lib/test test_weakref.py, 1.33, 1.34

fdrake at users.sourceforge.net fdrake at users.sourceforge.net
Tue Feb 3 14:57:14 EST 2004


Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4631/Lib/test

Modified Files:
	test_weakref.py 
Log Message:
- add tests that exercise fixes for the PyWeakref_NewRef() and
  PyWeakref_NewProxy() constructors from the C API
- elaborate the getweakrefcount() and getweakrefs() tests slightly


Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.33
retrieving revision 1.34
diff -C2 -d -r1.33 -r1.34
*** test_weakref.py	11 Dec 2003 12:33:54 -0000	1.33
--- test_weakref.py	3 Feb 2004 19:56:46 -0000	1.34
***************
*** 184,187 ****
--- 184,219 ----
          self.assertEqual(L3[2:5], p3[2:5])
  
+     # The PyWeakref_* C API is documented as allowing either NULL or
+     # None as the value for the callback, where either means "no
+     # callback".  The "no callback" ref and proxy objects are supposed
+     # to be shared so long as they exist by all callers so long as
+     # they are active.  In Python 2.3.3 and earlier, this guaranttee
+     # was not honored, and was broken in different ways for
+     # PyWeakref_NewRef() and PyWeakref_NewProxy().  (Two tests.)
+ 
+     def test_shared_ref_without_callback(self):
+         self.check_shared_without_callback(weakref.ref)
+ 
+     def test_shared_proxy_without_callback(self):
+         self.check_shared_without_callback(weakref.proxy)
+ 
+     def check_shared_without_callback(self, makeref):
+         o = Object(1)
+         p1 = makeref(o, None)
+         p2 = makeref(o, None)
+         self.assert_(p1 is p2, "both callbacks were None in the C API")
+         del p1, p2
+         p1 = makeref(o)
+         p2 = makeref(o, None)
+         self.assert_(p1 is p2, "callbacks were NULL, None in the C API")
+         del p1, p2
+         p1 = makeref(o)
+         p2 = makeref(o)
+         self.assert_(p1 is p2, "both callbacks were NULL in the C API")
+         del p1, p2
+         p1 = makeref(o, None)
+         p2 = makeref(o)
+         self.assert_(p1 is p2, "callbacks were None, NULL in the C API")
+ 
      def test_callable_proxy(self):
          o = Callable()
***************
*** 250,253 ****
--- 282,290 ----
                       "got wrong number of weak reference objects")
  
+         del ref1, ref2, proxy1, proxy2
+         self.assert_(weakref.getweakrefcount(o) == 0,
+                      "weak reference objects not unlinked from"
+                      " referent when discarded.")
+ 
          # assumes ints do not support weakrefs
          self.assert_(weakref.getweakrefcount(1) == 0,
***************
*** 269,272 ****
--- 306,313 ----
                       "list of refs does not match")
  
+         del ref1
+         self.assert_(weakref.getweakrefs(o) == [],
+                      "list of refs not cleared")
+ 
          # assumes ints do not support weakrefs
          self.assert_(weakref.getweakrefs(1) == [],




More information about the Python-checkins mailing list