@@ -23,14 +23,16 @@ class PyclbrTest(TestCase):
2323
2424 def assertListEq (self , l1 , l2 , ignore ):
2525 ''' succeed iff {l1} - {ignore} == {l2} - {ignore} '''
26+ l1 .sort ()
27+ l2 .sort ()
2628 try :
2729 for p1 , p2 in (l1 , l2 ), (l2 , l1 ):
2830 for item in p1 :
2931 ok = (item in p2 ) or (item in ignore )
3032 if not ok :
3133 self .fail ("%r missing" % item )
3234 except :
33- print >> sys .stderr , "l1=%r, l2 =%r, ignore =%r" % (l1 , l2 , ignore )
35+ print >> sys .stderr , "l1=%r\n l2 =%r\n ignore =%r" % (l1 , l2 , ignore )
3436 raise
3537
3638 def assertHasattr (self , obj , attr , ignore ):
@@ -67,6 +69,16 @@ def checkModule(self, moduleName, module=None, ignore=()):
6769
6870 dict = pyclbr .readmodule_ex (moduleName )
6971
72+ def ismethod (obj , name ):
73+ if not isinstance (obj , MethodType ):
74+ return False
75+ if obj .im_self is not None :
76+ return False
77+ objname = obj .__name__
78+ if objname .startswith ("__" ) and not objname .endswith ("__" ):
79+ objname = "_%s%s" % (obj .im_class .__name__ , objname )
80+ return objname == name
81+
7082 # Make sure the toplevel functions and classes are the same.
7183 for name , value in dict .items ():
7284 if name in ignore :
@@ -89,7 +101,7 @@ def checkModule(self, moduleName, module=None, ignore=()):
89101
90102 actualMethods = []
91103 for m in py_item .__dict__ .keys ():
92- if type (getattr (py_item , m )) == MethodType :
104+ if ismethod (getattr (py_item , m ), m ) :
93105 actualMethods .append (m )
94106 foundMethods = []
95107 for m in value .methods .keys ():
@@ -98,11 +110,15 @@ def checkModule(self, moduleName, module=None, ignore=()):
98110 else :
99111 foundMethods .append (m )
100112
101- self .assertListEq (foundMethods , actualMethods , ignore )
102- self .assertEquals (py_item .__module__ , value .module )
113+ try :
114+ self .assertListEq (foundMethods , actualMethods , ignore )
115+ self .assertEquals (py_item .__module__ , value .module )
103116
104- self .assertEquals (py_item .__name__ , value .name , ignore )
105- # can't check file or lineno
117+ self .assertEquals (py_item .__name__ , value .name , ignore )
118+ # can't check file or lineno
119+ except :
120+ print >> sys .stderr , "class=%s" % py_item
121+ raise
106122
107123 # Now check for missing stuff.
108124 def defined_in (item , module ):
@@ -119,51 +135,29 @@ def defined_in(item, module):
119135
120136 def test_easy (self ):
121137 self .checkModule ('pyclbr' )
122- self .checkModule ('doctest' ,
123- ignore = ['_isclass' ,
124- '_isfunction' ,
125- '_ismodule' ,
126- '_classify_class_attrs' ])
127- self .checkModule ('rfc822' , ignore = ["get" ])
138+ self .checkModule ('doctest' )
139+ self .checkModule ('rfc822' )
128140 self .checkModule ('difflib' )
129141
130142 def test_others (self ):
131143 cm = self .checkModule
132144
133- # these are about the 20 longest modules.
134-
145+ # These were once about the 10 longest modules
135146 cm ('random' , ignore = ('_verify' ,)) # deleted
136-
137- cm ('cgi' , ignore = ('f' , 'g' , # nested declarations
138- 'log' )) # set with =, not def
139-
140- cm ('mhlib' , ignore = ('do' , # nested declaration
141- 'bisect' )) # imported method, set with =
142-
143- cm ('urllib' , ignore = ('getproxies_environment' , # set with =
144- 'getproxies_registry' , # set with =
145- 'open_https' )) # not on all platforms
146-
147- cm ('pickle' , ignore = ('g' ,)) # deleted declaration
148-
149- cm ('aifc' , ignore = ('openfp' ,)) # set with =
150-
151- cm ('Cookie' , ignore = ('__str__' , 'Cookie' )) # set with =
152-
153- cm ('sre_parse' , ignore = ('literal' , # nested def
154- 'makedict' , 'dump' # from sre_constants
155- ))
147+ cm ('cgi' , ignore = ('log' ,)) # set with = in module
148+ cm ('mhlib' )
149+ cm ('urllib' , ignore = ('getproxies_registry' ,
150+ 'open_https' )) # not on all platforms
151+ cm ('pickle' , ignore = ('g' ,)) # from types import *
152+ cm ('aifc' , ignore = ('openfp' ,)) # set with = in module
153+ cm ('Cookie' )
154+ cm ('sre_parse' , ignore = ('dump' ,)) # from sre_constants import *
155+ cm ('pdb' )
156+ cm ('pydoc' )
156157
157158 # Tests for modules inside packages
158159 cm ('email.Parser' )
159-
160- cm ('test.test_pyclbr' , ignore = ('defined_in' ,))
161-
162- # pydoc doesn't work because of string issues
163- # cm('pydoc', pydoc)
164-
165- # pdb plays too many dynamic games
166- # cm('pdb', pdb)
160+ cm ('test.test_pyclbr' )
167161
168162
169163def test_main ():
0 commit comments