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

Guido van Rossum gvanrossum@users.sourceforge.net
Tue, 22 May 2001 13:04:05 -0700


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

Modified Files:
      Tag: descr-branch
	test_descr.py 
Log Message:
Add a test that overrides __getattr__, __setattr__ and __delattr__.


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/Attic/test_descr.py,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -r1.1.2.7 -r1.1.2.8
*** test_descr.py	2001/05/10 21:47:06	1.1.2.7
--- test_descr.py	2001/05/22 20:04:03	1.1.2.8
***************
*** 309,312 ****
--- 309,338 ----
              verify(a[i][j] == i*j)
  
+ import sys
+ MT = type(sys)
+ 
+ def pymods():
+     if verbose: print "Testing Python subclass of module..."
+     log = []
+     class MM(MT):
+         def __getattr__(self, name):
+             log.append(("getattr", name))
+             return MT.__getattr__(self, name)
+         def __setattr__(self, name, value):
+             log.append(("setattr", name, value))
+             MT.__setattr__(self, name, value)
+         def __delattr__(self, name):
+             log.append(("delattr", name))
+             MT.__delattr__(self, name)
+     a = MM()
+     a.foo = 12
+     x = a.foo
+     del a.foo
+     verify(log == [('getattr', '__setattr__'),
+                    ("setattr", "foo", 12),
+                    ("getattr", "foo"),
+                    ('getattr', '__delattr__'),
+                    ("delattr", "foo")])
+ 
  def all():
      lists()
***************
*** 318,321 ****
--- 344,348 ----
      spamdicts()
      pydicts()
+     pymods()
  
  all()