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

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 03 Jul 2001 17:40:59 -0700


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

Modified Files:
      Tag: descr-branch
	test_descr.py 
Log Message:
Rudimentary test for __new__ override.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/Attic/test_descr.py,v
retrieving revision 1.1.2.25
retrieving revision 1.1.2.26
diff -C2 -r1.1.2.25 -r1.1.2.26
*** test_descr.py	2001/07/03 09:24:56	1.1.2.25
--- test_descr.py	2001/07/04 00:40:57	1.1.2.26
***************
*** 677,680 ****
--- 677,698 ----
      verify(a.x == 11)
  
+ def newslot():
+     if verbose: print "Testing __new__ slot override..."
+     class C(list):
+         def __new__(cls):
+             self = list.__new__(cls)
+             self.foo = 1
+             return self
+         def __init__(self):
+             self.foo = self.foo + 2
+     a = C()
+     verify(a.foo == 3)
+     verify(a.__class__ is C)
+     class D(C):
+         pass
+     b = D()
+     verify(b.foo == 3)
+     verify(b.__class__ is D)
+ 
  def all():
      lists()
***************
*** 699,702 ****
--- 717,721 ----
      classic()
      compattr()
+     newslot()
  
  all()