[Python-checkins] python/dist/src/Lib/test test_pyclbr.py,1.12,1.13
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Mon, 02 Dec 2002 06:54:23 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv3774/test
Modified Files:
test_pyclbr.py
Log Message:
Moderately heavy reorganization of pyclbr to fix package-related bugs.
- The _modules cache now uses the full module name.
- The meaning of the (internal!!!) inpackage argument is changed: it
now is the parent package name, or None. readmodule() doesn't
support this argument any more.
- The meaning of the path argument is changed: when inpackage is set,
the module *must* be found in this path (as is the case for the real
package search).
- Miscellaneous cleanup, e.g. fixed __all__, changed some comments and
doc strings, etc.
- Adapted the unit tests to the new semantics (nothing much changed,
really). Added some debugging code to the unit tests that print
helpful extra info to stderr when a test fails (interpreting the
test failures turned out to be hard without these).
Index: test_pyclbr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_pyclbr.py,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** test_pyclbr.py 23 Jul 2002 19:03:59 -0000 1.12
--- test_pyclbr.py 2 Dec 2002 14:54:20 -0000 1.13
***************
*** 7,10 ****
--- 7,11 ----
from types import ClassType, FunctionType, MethodType
import pyclbr
+ from unittest import TestCase
# This next line triggers an error on old versions of pyclbr.
***************
*** 19,32 ****
# members to ignore.
! class PyclbrTest(unittest.TestCase):
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
! for p1, p2 in (l1, l2), (l2, l1):
! for item in p1:
! ok = (item in p2) or (item in ignore)
! if not ok:
! self.fail("%r missing" % item)
!
def assertHasattr(self, obj, attr, ignore):
--- 20,36 ----
# members to ignore.
! class PyclbrTest(TestCase):
def assertListEq(self, l1, l2, ignore):
''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
! try:
! for p1, p2 in (l1, l2), (l2, l1):
! for item in p1:
! ok = (item in p2) or (item in ignore)
! if not ok:
! self.fail("%r missing" % item)
! except:
! print >>sys.stderr, "l1=%r, l2=%r, ignore=%r" % (l1, l2, ignore)
! raise
def assertHasattr(self, obj, attr, ignore):
***************
*** 41,45 ****
''' succeed iff obj.has_key(key) or key in ignore. '''
if key in ignore: return
! if not obj.has_key(key): print "***",key
self.failUnless(obj.has_key(key))
--- 45,50 ----
''' succeed iff obj.has_key(key) or key in ignore. '''
if key in ignore: return
! if not obj.has_key(key):
! print >>sys.stderr, "***",key
self.failUnless(obj.has_key(key))
***************
*** 57,61 ****
if module == None:
! module = __import__(moduleName, globals(), {}, [])
dict = pyclbr.readmodule_ex(moduleName)
--- 62,68 ----
if module == None:
! # Import it.
! # ('<silly>' is to work around an API silliness in __import__)
! module = __import__(moduleName, globals(), {}, ['<silly>'])
dict = pyclbr.readmodule_ex(moduleName)
***************
*** 75,79 ****
for base in value.super ]
! self.assertListEq(real_bases, pyclbr_bases, ignore)
actualMethods = []
--- 82,90 ----
for base in value.super ]
! try:
! self.assertListEq(real_bases, pyclbr_bases, ignore)
! except:
! print >>sys.stderr, "class=%s" % py_item
! raise
actualMethods = []
***************
*** 95,102 ****
# Now check for missing stuff.
for name in dir(module):
item = getattr(module, name)
! if type(item) in (ClassType, FunctionType):
! self.assertHaskey(dict, name, ignore)
def test_easy(self):
--- 106,120 ----
# Now check for missing stuff.
+ def defined_in(item, module):
+ if isinstance(item, ClassType):
+ return item.__module__ == module.__name__
+ if isinstance(item, FunctionType):
+ return item.func_globals is module.__dict__
+ return False
for name in dir(module):
item = getattr(module, name)
! if isinstance(item, (ClassType, FunctionType)):
! if defined_in(item, module):
! self.assertHaskey(dict, name, ignore)
def test_easy(self):
***************
*** 137,142 ****
))
! cm('test.test_pyclbr',
! module=sys.modules[__name__])
# pydoc doesn't work because of string issues
--- 155,162 ----
))
! # Tests for modules inside packages
! cm('email.Parser')
!
! cm('test.test_pyclbr', ignore=('defined_in',))
# pydoc doesn't work because of string issues