MCPcopy
hub / github.com/django/django / test_shallow_loader

Method test_shallow_loader

tests/utils_tests/test_module_loading.py:88–107  ·  view source on GitHub ↗

Module existence can be tested inside eggs

(self)

Source from the content-addressed store, hash-verified

86 sys.modules.pop("egg_module", None)
87
88 def test_shallow_loader(self):
89 "Module existence can be tested inside eggs"
90 egg_name = "%s/test_egg.egg" % self.egg_dir
91 with extend_sys_path(egg_name):
92 egg_module = import_module("egg_module")
93
94 # An importable child
95 self.assertTrue(module_has_submodule(egg_module, "good_module"))
96 mod = import_module("egg_module.good_module")
97 self.assertEqual(mod.content, "Good Module")
98
99 # A child that exists, but will generate an import error if loaded
100 self.assertTrue(module_has_submodule(egg_module, "bad_module"))
101 with self.assertRaises(ImportError):
102 import_module("egg_module.bad_module")
103
104 # A child that doesn't exist
105 self.assertFalse(module_has_submodule(egg_module, "no_such_module"))
106 with self.assertRaises(ImportError):
107 import_module("egg_module.no_such_module")
108
109 def test_deep_loader(self):
110 "Modules deep inside an egg can still be tested for existence"

Callers

nothing calls this directly

Calls 2

extend_sys_pathFunction · 0.90
module_has_submoduleFunction · 0.90

Tested by

no test coverage detected