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