[Python-checkins] CVS: python/dist/src/Lib/test test_descr.py,1.30,1.31 test_pyclbr.py,1.2,1.3

Tim Peters tim_one@users.sourceforge.net
Mon, 03 Sep 2001 18:20:06 -0700


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

Modified Files:
	test_descr.py test_pyclbr.py 
Log Message:
builtin_dir():  Treat classic classes like types.  Use PyDict_Keys instead
of PyMapping_Keys because we know we have a real dict.  Tolerate that
objects may have an attr named "__dict__" that's not a dict (Py_None
popped up during testing).

test_descr.py, test_dir():  Test the new classic-class behavior; beef up
the new-style class test similarly.

test_pyclbr.py, checkModule():  dir(C) is no longer a synonym for
C.__dict__.keys() when C is a classic class (looks like the same thing
that burned distutils! -- should it be *made* a synoym again?  Then it
would be inconsistent with new-style class behavior.).


Index: test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** test_descr.py	2001/09/03 05:47:38	1.30
--- test_descr.py	2001/09/04 01:20:04	1.31
***************
*** 184,189 ****
          dir(arg)
  
!     # Check some details here because classic classes aren't working
!     # reasonably, and I want this to fail (eventually).
      class C:
          Cdata = 1
--- 184,188 ----
          dir(arg)
  
!     # Try classic classes.
      class C:
          Cdata = 1
***************
*** 203,223 ****
          Adata = 1
          def Amethod(self): pass
!     astuff = ['Adata', 'Amethod', '__doc__', '__module__']
!     # This isn't finding C's stuff at all.
      verify(dir(A) == astuff)
-     # But this is!  It's because a.__class__ exists but A.__class__ doesn't.
      a = A()
!     verify(dir(a) == astuff[:2] + cstuff)
  
!     # The story for new-style classes is quite different.
      class C(object):
          Cdata = 1
          def Cmethod(self): pass
      class A(C):
          Adata = 1
          def Amethod(self): pass
!     d = dir(A)
!     for expected in 'Cdata', 'Cmethod', 'Adata', 'Amethod':
!         verify(expected in d)
  
  binops = {
--- 202,244 ----
          Adata = 1
          def Amethod(self): pass
! 
!     astuff = ['Adata', 'Amethod'] + cstuff
      verify(dir(A) == astuff)
      a = A()
!     verify(dir(a) == astuff)
!     a.adata = 42
!     a.amethod = lambda self: 3
!     verify(dir(a) == astuff + ['adata', 'amethod'])
  
!     # The same, but with new-style classes.  Since these have object as a
!     # base class, a lot more gets sucked in.
!     def interesting(strings):
!         return [s for s in strings if not s.startswith('_')]
! 
      class C(object):
          Cdata = 1
          def Cmethod(self): pass
+ 
+     cstuff = ['Cdata', 'Cmethod']
+     verify(interesting(dir(C)) == cstuff)
+ 
+     c = C()
+     verify(interesting(dir(c)) == cstuff)
+ 
+     c.cdata = 2
+     c.cmethod = lambda self: 0
+     verify(interesting(dir(c)) == cstuff + ['cdata', 'cmethod'])
+ 
      class A(C):
          Adata = 1
          def Amethod(self): pass
! 
!     astuff = ['Adata', 'Amethod'] + cstuff
!     verify(interesting(dir(A)) == astuff)
!     a = A()
!     verify(interesting(dir(a)) == astuff)
!     a.adata = 42
!     a.amethod = lambda self: 3
!     verify(interesting(dir(a)) == astuff + ['adata', 'amethod'])
  
  binops = {

Index: test_pyclbr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyclbr.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** test_pyclbr.py	2001/08/13 22:25:24	1.2
--- test_pyclbr.py	2001/09/04 01:20:04	1.3
***************
*** 77,81 ****
  
                  actualMethods = []
!                 for m in dir(py_item):
                      if type(getattr(py_item, m)) == MethodType:
                          actualMethods.append(m)
--- 77,81 ----
  
                  actualMethods = []
!                 for m in py_item.__dict__.keys():
                      if type(getattr(py_item, m)) == MethodType:
                          actualMethods.append(m)