(self, modname)
| 31 | class AllTest(unittest.TestCase): |
| 32 | |
| 33 | def check_all(self, modname): |
| 34 | names = {} |
| 35 | with warnings_helper.check_warnings( |
| 36 | (f".*{modname}", DeprecationWarning), |
| 37 | (".* (module|package)", DeprecationWarning), |
| 38 | (".* (module|package)", PendingDeprecationWarning), |
| 39 | ("", ResourceWarning), |
| 40 | ("", SyntaxWarning), |
| 41 | quiet=True): |
| 42 | try: |
| 43 | exec("import %s" % modname, names) |
| 44 | except: |
| 45 | # Silent fail here seems the best route since some modules |
| 46 | # may not be available or not initialize properly in all |
| 47 | # environments. |
| 48 | raise FailedImport(modname) |
| 49 | if not hasattr(sys.modules[modname], "__all__"): |
| 50 | raise NoAll(modname) |
| 51 | names = {} |
| 52 | with self.subTest(module=modname): |
| 53 | with warnings_helper.check_warnings( |
| 54 | ("", DeprecationWarning), |
| 55 | ("", ResourceWarning), |
| 56 | ("", SyntaxWarning), |
| 57 | quiet=True): |
| 58 | try: |
| 59 | exec("from %s import *" % modname, names) |
| 60 | except Exception as e: |
| 61 | # Include the module name in the exception string |
| 62 | self.fail("__all__ failure in {}: {}: {}".format( |
| 63 | modname, e.__class__.__name__, e)) |
| 64 | if "__builtins__" in names: |
| 65 | del names["__builtins__"] |
| 66 | if '__annotations__' in names: |
| 67 | del names['__annotations__'] |
| 68 | if "__warningregistry__" in names: |
| 69 | del names["__warningregistry__"] |
| 70 | keys = set(names) |
| 71 | all_list = sys.modules[modname].__all__ |
| 72 | all_set = set(all_list) |
| 73 | self.assertCountEqual(all_set, all_list, "in module {}".format(modname)) |
| 74 | self.assertEqual(keys, all_set, "in module {}".format(modname)) |
| 75 | # Verify __dir__ is non-empty and doesn't produce an error |
| 76 | self.assertTrue(dir(sys.modules[modname])) |
| 77 | |
| 78 | def walk_modules(self, basedir, modpath): |
| 79 | for fn in sorted(os.listdir(basedir)): |
no test coverage detected