Back to index

python3.2  3.2.2
Public Member Functions
test.test_pyclbr.PyclbrTest Class Reference
Inheritance diagram for test.test_pyclbr.PyclbrTest:
Inheritance graph
[legend]
Collaboration diagram for test.test_pyclbr.PyclbrTest:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def assertListEq
def assertHasattr
def assertHaskey
def assertEqualsOrIgnored
def checkModule
def test_easy
def test_decorators
def test_others

Detailed Description

Definition at line 21 of file test_pyclbr.py.


Member Function Documentation

def test.test_pyclbr.PyclbrTest.assertEqualsOrIgnored (   self,
  a,
  b,
  ignore 
)
succeed iff a == b or a in ignore or b in ignore 

Definition at line 45 of file test_pyclbr.py.

00045 
00046     def assertEqualsOrIgnored(self, a, b, ignore):
00047         ''' succeed iff a == b or a in ignore or b in ignore '''
00048         if a not in ignore and b not in ignore:
00049             self.assertEqual(a, b)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_pyclbr.PyclbrTest.assertHasattr (   self,
  obj,
  attr,
  ignore 
)
succeed iff hasattr(obj,attr) or attr in ignore. 

Definition at line 30 of file test_pyclbr.py.

00030 
00031     def assertHasattr(self, obj, attr, ignore):
00032         ''' succeed iff hasattr(obj,attr) or attr in ignore. '''
00033         if attr in ignore: return
00034         if not hasattr(obj, attr): print("???", attr)
00035         self.assertTrue(hasattr(obj, attr),
00036                         'expected hasattr(%r, %r)' % (obj, attr))
00037 

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_pyclbr.PyclbrTest.assertHaskey (   self,
  obj,
  key,
  ignore 
)
succeed iff key in obj or key in ignore. 

Definition at line 38 of file test_pyclbr.py.

00038 
00039     def assertHaskey(self, obj, key, ignore):
00040         ''' succeed iff key in obj or key in ignore. '''
00041         if key in ignore: return
00042         if key not in obj:
00043             print("***",key, file=sys.stderr)
00044         self.assertIn(key, obj)

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_pyclbr.PyclbrTest.assertListEq (   self,
  l1,
  l2,
  ignore 
)
succeed iff {l1} - {ignore} == {l2} - {ignore} 

Definition at line 23 of file test_pyclbr.py.

00023 
00024     def assertListEq(self, l1, l2, ignore):
00025         ''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
00026         missing = (set(l1) ^ set(l2)) - set(ignore)
00027         if missing:
00028             print("l1=%r\nl2=%r\nignore=%r" % (l1, l2, ignore), file=sys.stderr)
00029             self.fail("%r missing" % missing.pop())

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_pyclbr.PyclbrTest.checkModule (   self,
  moduleName,
  module = None,
  ignore = () 
)
succeed iff pyclbr.readmodule_ex(modulename) corresponds
    to the actual module object, module.  Any identifiers in
    ignore are ignored.   If no module is provided, the appropriate
    module is loaded with __import__.

Definition at line 50 of file test_pyclbr.py.

00050 
00051     def checkModule(self, moduleName, module=None, ignore=()):
00052         ''' succeed iff pyclbr.readmodule_ex(modulename) corresponds
00053             to the actual module object, module.  Any identifiers in
00054             ignore are ignored.   If no module is provided, the appropriate
00055             module is loaded with __import__.'''
00056 
00057         ignore = set(ignore) | set(['object'])
00058 
00059         if module is None:
00060             # Import it.
00061             # ('<silly>' is to work around an API silliness in __import__)
00062             module = __import__(moduleName, globals(), {}, ['<silly>'])
00063 
00064         dict = pyclbr.readmodule_ex(moduleName)
00065 
00066         def ismethod(oclass, obj, name):
00067             classdict = oclass.__dict__
00068             if isinstance(obj, MethodType):
00069                 # could be a classmethod
00070                 if (not isinstance(classdict[name], ClassMethodType) or
00071                     obj.__self__ is not oclass):
00072                     return False
00073             elif not isinstance(obj, FunctionType):
00074                 return False
00075 
00076             objname = obj.__name__
00077             if objname.startswith("__") and not objname.endswith("__"):
00078                 objname = "_%s%s" % (oclass.__name__, objname)
00079             return objname == name
00080 
00081         # Make sure the toplevel functions and classes are the same.
00082         for name, value in dict.items():
00083             if name in ignore:
00084                 continue
00085             self.assertHasattr(module, name, ignore)
00086             py_item = getattr(module, name)
00087             if isinstance(value, pyclbr.Function):
00088                 self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
00089                 if py_item.__module__ != moduleName:
00090                     continue   # skip functions that came from somewhere else
00091                 self.assertEqual(py_item.__module__, value.module)
00092             else:
00093                 self.assertIsInstance(py_item, type)
00094                 if py_item.__module__ != moduleName:
00095                     continue   # skip classes that came from somewhere else
00096 
00097                 real_bases = [base.__name__ for base in py_item.__bases__]
00098                 pyclbr_bases = [ getattr(base, 'name', base)
00099                                  for base in value.super ]
00100 
00101                 try:
00102                     self.assertListEq(real_bases, pyclbr_bases, ignore)
00103                 except:
00104                     print("class=%s" % py_item, file=sys.stderr)
00105                     raise
00106 
00107                 actualMethods = []
00108                 for m in py_item.__dict__.keys():
00109                     if ismethod(py_item, getattr(py_item, m), m):
00110                         actualMethods.append(m)
00111                 foundMethods = []
00112                 for m in value.methods.keys():
00113                     if m[:2] == '__' and m[-2:] != '__':
00114                         foundMethods.append('_'+name+m)
00115                     else:
00116                         foundMethods.append(m)
00117 
00118                 try:
00119                     self.assertListEq(foundMethods, actualMethods, ignore)
00120                     self.assertEqual(py_item.__module__, value.module)
00121 
00122                     self.assertEqualsOrIgnored(py_item.__name__, value.name,
00123                                                ignore)
00124                     # can't check file or lineno
00125                 except:
00126                     print("class=%s" % py_item, file=sys.stderr)
00127                     raise
00128 
00129         # Now check for missing stuff.
00130         def defined_in(item, module):
00131             if isinstance(item, type):
00132                 return item.__module__ == module.__name__
00133             if isinstance(item, FunctionType):
00134                 return item.__globals__ is module.__dict__
00135             return False
00136         for name in dir(module):
00137             item = getattr(module, name)
00138             if isinstance(item,  (type, FunctionType)):
00139                 if defined_in(item, module):
00140                     self.assertHaskey(dict, name, ignore)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 148 of file test_pyclbr.py.

00148 
00149     def test_decorators(self):
00150         # XXX: See comment in pyclbr_input.py for a test that would fail
00151         #      if it were not commented out.
00152         #
00153         self.checkModule('test.pyclbr_input', ignore=['om'])

Here is the call graph for this function:

Definition at line 141 of file test_pyclbr.py.

00141 
00142     def test_easy(self):
00143         self.checkModule('pyclbr')
00144         self.checkModule('ast')
00145         self.checkModule('doctest', ignore=("TestResults", "_SpoofOut",
00146                                             "DocTestCase"))
00147         self.checkModule('difflib', ignore=("Match",))

Here is the call graph for this function:

Definition at line 154 of file test_pyclbr.py.

00154 
00155     def test_others(self):
00156         cm = self.checkModule
00157 
00158         # These were once about the 10 longest modules
00159         cm('random', ignore=('Random',))  # from _random import Random as CoreGenerator
00160         cm('cgi', ignore=('log',))      # set with = in module
00161         cm('pickle')
00162         cm('aifc', ignore=('openfp',))  # set with = in module
00163         cm('sre_parse', ignore=('dump',)) # from sre_constants import *
00164         cm('pdb')
00165         cm('pydoc')
00166 
00167         # Tests for modules inside packages
00168         cm('email.parser')
00169         cm('test.test_pyclbr')
00170 

Here is the call graph for this function:


The documentation for this class was generated from the following file: