MCPcopy
hub / github.com/django/django / test_loader

Method test_loader

tests/utils_tests/test_module_loading.py:17–50  ·  view source on GitHub ↗

Normal module existence can be tested

(self)

Source from the content-addressed store, hash-verified

15
16class DefaultLoader(unittest.TestCase):
17 def test_loader(self):
18 "Normal module existence can be tested"
19 test_module = import_module("utils_tests.test_module")
20 test_no_submodule = import_module("utils_tests.test_no_submodule")
21
22 # An importable child
23 self.assertTrue(module_has_submodule(test_module, "good_module"))
24 mod = import_module("utils_tests.test_module.good_module")
25 self.assertEqual(mod.content, "Good Module")
26
27 # A child that exists, but will generate an import error if loaded
28 self.assertTrue(module_has_submodule(test_module, "bad_module"))
29 with self.assertRaises(ImportError):
30 import_module("utils_tests.test_module.bad_module")
31
32 # A child that doesn't exist
33 self.assertFalse(module_has_submodule(test_module, "no_such_module"))
34 with self.assertRaises(ImportError):
35 import_module("utils_tests.test_module.no_such_module")
36
37 # A child that doesn't exist, but is the name of a package on the path
38 self.assertFalse(module_has_submodule(test_module, "django"))
39 with self.assertRaises(ImportError):
40 import_module("utils_tests.test_module.django")
41
42 # Don't be confused by caching of import misses
43 import types # NOQA: causes attempted import of utils_tests.types
44
45 self.assertFalse(module_has_submodule(sys.modules["utils_tests"], "types"))
46
47 # A module which doesn't have a __path__ (so no submodules)
48 self.assertFalse(module_has_submodule(test_no_submodule, "anything"))
49 with self.assertRaises(ImportError):
50 import_module("utils_tests.test_no_submodule.anything")
51
52 def test_has_sumbodule_with_dotted_path(self):
53 """Nested module existence can be tested."""

Callers

nothing calls this directly

Calls 1

module_has_submoduleFunction · 0.90

Tested by

no test coverage detected