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=())
| 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 = [] |
no test coverage detected