[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.18,1.19

Guido van Rossum gvanrossum@users.sourceforge.net
Fri, 17 Aug 2001 14:27:55 -0700


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

Modified Files:
	test_descr.py 
Log Message:
Add test for weak references.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** test_descr.py	2001/08/17 13:58:31	1.18
--- test_descr.py	2001/08/17 21:27:53	1.19
***************
*** 834,838 ****
  
  def overloading():
!     if verbose: print "testing operator overloading..."
  
      class B(object):
--- 834,838 ----
  
  def overloading():
!     if verbose: print "Testing operator overloading..."
  
      class B(object):
***************
*** 891,895 ****
  
  def methods():
!     if verbose: print "testing methods..."
      class C(object):
          def __init__(self, x):
--- 891,895 ----
  
  def methods():
!     if verbose: print "Testing methods..."
      class C(object):
          def __init__(self, x):
***************
*** 913,917 ****
  def specials():
      # Test operators like __hash__ for which a built-in default exists
!     if verbose: print "testing special operators..."
      # Test the default behavior for static classes
      class C(object):
--- 913,917 ----
  def specials():
      # Test operators like __hash__ for which a built-in default exists
!     if verbose: print "Testing special operators..."
      # Test the default behavior for static classes
      class C(object):
***************
*** 1041,1044 ****
--- 1041,1073 ----
      verify(10 not in p10)
  
+ def weakrefs():
+     if verbose: print "Testing weak references..."
+     import weakref
+     class C(object):
+         pass
+     c = C()
+     r = weakref.ref(c)
+     verify(r() is c)
+     del c
+     verify(r() is None)
+     del r
+     class NoWeak(object):
+         __slots__ = ['foo']
+     no = NoWeak()
+     try:
+         weakref.ref(no)
+     except TypeError, msg:
+         verify(str(msg).find("weakly") >= 0)
+     else:
+         verify(0, "weakref.ref(no) should be illegal")
+     class Weak(object):
+         __slots__ = ['foo', '__weakref__']
+     yes = Weak()
+     r = weakref.ref(yes)
+     verify(r() is yes)
+     del yes
+     verify(r() is None)
+     del r
+ 
  def all():
      lists()
***************
*** 1069,1072 ****
--- 1098,1102 ----
      methods()
      specials()
+     weakrefs()
  
  all()