[Python-checkins] CVS: python/dist/src/Lib/test test_weakref.py,1.5,1.6

Fred L. Drake fdrake@users.sourceforge.net
Fri, 13 Apr 2001 10:18:17 -0700


Update of /cvsroot/python/python/dist/src/Lib/test
In directory usw-pr-cvs1:/tmp/cvs-serv13728/test

Modified Files:
	test_weakref.py 
Log Message:

Added regression test for SF bug #415660 (failure to invalidate all
references to an object before calling registered callbacks).

Change last uses of verify() to self.assert_().


Index: test_weakref.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_weakref.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** test_weakref.py	2001/04/10 19:09:35	1.5
--- test_weakref.py	2001/04/13 17:18:15	1.6
***************
*** 3,7 ****
  import weakref
  
! from test_support import run_unittest, verify
  
  
--- 3,7 ----
  import weakref
  
! from test_support import run_unittest
  
  
***************
*** 64,67 ****
--- 64,86 ----
                       "callback not called the right number of times")
  
+     def test_multiple_selfref_callbacks(self):
+         """Make sure all references are invalidated before callbacks
+         are called."""
+         #
+         # What's important here is that we're using the first
+         # reference in the callback invoked on the second reference
+         # (the most recently created ref is cleaned up first).  This
+         # tests that all references to the object are invalidated
+         # before any of the callbacks are invoked, so that we only
+         # have one invocation of _weakref.c:cleanup_helper() active
+         # for a particular object at a time.
+         #
+         def callback(object, self=self):
+             self.ref()
+         c = C()
+         self.ref = weakref.ref(c, callback)
+         ref1 = weakref.ref(c, callback)
+         del c
+ 
      def test_proxy_ref(self):
          o = C()
***************
*** 92,99 ****
          ref = weakref.ref(o, self.callback)
          del o
!         verify(self.cbcalled == 1,
!                "callback did not properly set 'cbcalled'")
!         verify(ref() is None,
!                "ref2 should be dead after deleting object reference")
  
      def test_ref_reuse(self):
--- 111,118 ----
          ref = weakref.ref(o, self.callback)
          del o
!         self.assert_(self.cbcalled == 1,
!                      "callback did not properly set 'cbcalled'")
!         self.assert_(ref() is None,
!                      "ref2 should be dead after deleting object reference")
  
      def test_ref_reuse(self):