MCPcopy Index your code
hub / github.com/python/cpython / checkModule

Method checkModule

Lib/test/test_pyclbr.py:70–166  ·  view source on GitHub ↗

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__.

(self, moduleName, module=None, ignore=())

Source from the content-addressed store, hash-verified

68 self.assertEqual(a, b)
69
70 def checkModule(self, moduleName, module=None, ignore=()):
71 ''' succeed iff pyclbr.readmodule_ex(modulename) corresponds
72 to the actual module object, module. Any identifiers in
73 ignore are ignored. If no module is provided, the appropriate
74 module is loaded with __import__.'''
75
76 ignore = set(ignore) | set(['object'])
77
78 if module is None:
79 # Import it.
80 # ('<silly>' is to work around an API silliness in __import__)
81 module = __import__(moduleName, globals(), {}, ['<silly>'])
82
83 dict = pyclbr.readmodule_ex(moduleName)
84
85 def ismethod(oclass, obj, name):
86 classdict = oclass.__dict__
87 if isinstance(obj, MethodType):
88 # could be a classmethod
89 if (not isinstance(classdict[name], ClassMethodType) or
90 obj.__self__ is not oclass):
91 return False
92 elif not isinstance(obj, FunctionType):
93 return False
94
95 objname = obj.__name__
96 if objname.startswith("__") and not objname.endswith("__"):
97 if stripped_typename := oclass.__name__.lstrip('_'):
98 objname = f"_{stripped_typename}{objname}"
99 return objname == name
100
101 # Make sure the toplevel functions and classes are the same.
102 for name, value in dict.items():
103 if name in ignore:
104 continue
105 self.assertHasAttr(module, name)
106 py_item = getattr(module, name)
107 if isinstance(value, pyclbr.Function):
108 self.assertIsInstance(py_item, (FunctionType, BuiltinFunctionType))
109 if py_item.__module__ != moduleName:
110 continue # skip functions that came from somewhere else
111 self.assertEqual(py_item.__module__, value.module)
112 else:
113 self.assertIsInstance(py_item, type)
114 if py_item.__module__ != moduleName:
115 continue # skip classes that came from somewhere else
116
117 real_bases = [base.__name__ for base in py_item.__bases__]
118 pyclbr_bases = [ getattr(base, 'name', base)
119 for base in value.super ]
120
121 try:
122 self.assertListEq(real_bases, pyclbr_bases, ignore)
123 except:
124 print("class=%s" % py_item, file=sys.stderr)
125 raise
126
127 actualMethods = []

Callers 2

test_easyMethod · 0.95
test_casesMethod · 0.95

Calls 15

assertListEqMethod · 0.95
assertEqualsOrIgnoredMethod · 0.95
assertHaskeyMethod · 0.95
setFunction · 0.85
__import__Function · 0.85
ismethodFunction · 0.85
listClass · 0.85
assertHasAttrMethod · 0.80
assertIsInstanceMethod · 0.80
itemsMethod · 0.45
assertEqualMethod · 0.45
keysMethod · 0.45

Tested by

no test coverage detected