Author: russellm Date: 2010-05-04 09:48:43 -0500 (Tue, 04 May 2010) New Revision: 13095
Modified: django/trunk/tests/regressiontests/utils/module_loading.py Log: Fixed #13469 -- Cleaned up the test case from r13085, and added some cache cleanup that matters for Python 2.3. Thanks to Karen and Alex for their help. Modified: django/trunk/tests/regressiontests/utils/module_loading.py =================================================================== --- django/trunk/tests/regressiontests/utils/module_loading.py 2010-05-04 14:00:30 UTC (rev 13094) +++ django/trunk/tests/regressiontests/utils/module_loading.py 2010-05-04 14:48:43 UTC (rev 13095) @@ -31,7 +31,16 @@ def tearDown(self): sys.path = self.old_path + sys.path_importer_cache.clear() + sys.modules.pop('egg_module.sub1.sub2.bad_module', None) + sys.modules.pop('egg_module.sub1.sub2.good_module', None) + sys.modules.pop('egg_module.sub1.sub2', None) + sys.modules.pop('egg_module.sub1', None) + sys.modules.pop('egg_module.bad_module', None) + sys.modules.pop('egg_module.good_module', None) + sys.modules.pop('egg_module', None) + def test_shallow_loader(self): "Module existence can be tested inside eggs" egg_name = '%s/test_egg.egg' % self.egg_dir @@ -89,51 +98,17 @@ mod.__loader__ = self return mod -class CustomLoader(TestCase): +class CustomLoader(EggLoader): + """The Custom Loader test is exactly the same as the EggLoader, but + it uses a custom defined Loader and Finder that is intentionally + split into two classes. Although the EggLoader combines both functions + into one class, this isn't required. + """ def setUp(self): - self.egg_dir = '%s/eggs' % os.path.dirname(__file__) - self.old_path = sys.path + super(CustomLoader, self).setUp() sys.path_hooks.insert(0, TestFinder) sys.path_importer_cache.clear() def tearDown(self): - sys.path = self.old_path + super(CustomLoader, self).tearDown() sys.path_hooks.pop(0) - - def test_shallow_loader(self): - "Module existence can be tested with a custom loader" - egg_name = '%s/test_egg.egg' % self.egg_dir - sys.path.append(egg_name) - egg_module = import_module('egg_module') - - # An importable child - self.assertTrue(module_has_submodule(egg_module, 'good_module')) - mod = import_module('egg_module.good_module') - self.assertEqual(mod.content, 'Good Module') - - # A child that exists, but will generate an import error if loaded - self.assertTrue(module_has_submodule(egg_module, 'bad_module')) - self.assertRaises(ImportError, import_module, 'egg_module.bad_module') - - # A child that doesn't exist - self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) - self.assertRaises(ImportError, import_module, 'egg_module.no_such_module') - - def test_deep_loader(self): - "Modules existence can be tested deep inside a custom loader" - egg_name = '%s/test_egg.egg' % self.egg_dir - sys.path.append(egg_name) - egg_module = import_module('egg_module.sub1.sub2') - - # An importable child - self.assertTrue(module_has_submodule(egg_module, 'good_module')) - mod = import_module('egg_module.sub1.sub2.good_module') - self.assertEqual(mod.content, 'Deep Good Module') - - # A child that exists, but will generate an import error if loaded - self.assertTrue(module_has_submodule(egg_module, 'bad_module')) - self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.bad_module') - - # A child that doesn't exist - self.assertFalse(module_has_submodule(egg_module, 'no_such_module')) - self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module') -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-upda...@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.