| 34 | sys.path_importer_cache.clear() |
| 35 | |
| 36 | sys.modules.pop('egg_module.sub1.sub2.bad_module', None) |
| 37 | sys.modules.pop('egg_module.sub1.sub2.good_module', None) |
| 38 | sys.modules.pop('egg_module.sub1.sub2', None) |
| 39 | sys.modules.pop('egg_module.sub1', None) |
| 40 | sys.modules.pop('egg_module.bad_module', None) |
| 41 | sys.modules.pop('egg_module.good_module', None) |
| 42 | sys.modules.pop('egg_module', None) |
103 | | def test_shallow_loader(self): |
104 | | "Module existence can be tested with a custom loader" |
105 | | egg_name = '%s/test_egg.egg' % self.egg_dir |
106 | | sys.path.append(egg_name) |
107 | | egg_module = import_module('egg_module') |
108 | | |
109 | | # An importable child |
110 | | self.assertTrue(module_has_submodule(egg_module, 'good_module')) |
111 | | mod = import_module('egg_module.good_module') |
112 | | self.assertEqual(mod.content, 'Good Module') |
113 | | |
114 | | # A child that exists, but will generate an import error if loaded |
115 | | self.assertTrue(module_has_submodule(egg_module, 'bad_module')) |
116 | | self.assertRaises(ImportError, import_module, 'egg_module.bad_module') |
117 | | |
118 | | # A child that doesn't exist |
119 | | self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) |
120 | | self.assertRaises(ImportError, import_module, 'egg_module.no_such_module') |
121 | | |
122 | | def test_deep_loader(self): |
123 | | "Modules existence can be tested deep inside a custom loader" |
124 | | egg_name = '%s/test_egg.egg' % self.egg_dir |
125 | | sys.path.append(egg_name) |
126 | | egg_module = import_module('egg_module.sub1.sub2') |
127 | | |
128 | | # An importable child |
129 | | self.assertTrue(module_has_submodule(egg_module, 'good_module')) |
130 | | mod = import_module('egg_module.sub1.sub2.good_module') |
131 | | self.assertEqual(mod.content, 'Deep Good Module') |
132 | | |
133 | | # A child that exists, but will generate an import error if loaded |
134 | | self.assertTrue(module_has_submodule(egg_module, 'bad_module')) |
135 | | self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.bad_module') |
136 | | |
137 | | # A child that doesn't exist |
138 | | self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) |
139 | | self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module') |
| 113 | sys.modules.pop('egg_module.sub1.sub2.bad_module', None) |
| 114 | sys.modules.pop('egg_module.sub1.sub2.good_module', None) |
| 115 | sys.modules.pop('egg_module.sub1.sub2', None) |
| 116 | sys.modules.pop('egg_module.sub1', None) |
| 117 | sys.modules.pop('egg_module.bad_module', None) |
| 118 | sys.modules.pop('egg_module.good_module', None) |
| 119 | sys.modules.pop('egg_module', None) |