From 125ea947df52d9a3e7a306ebefee9c6b7247f60f Mon Sep 17 00:00:00 2001 From: Russell Keith-Magee Date: Tue, 4 May 2010 14:55:04 +0000 Subject: [PATCH] [1.1.X] 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. Backport of r13095 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@13096 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/utils/module_loading.py | 59 ++++++------------- 1 file changed, 17 insertions(+), 42 deletions(-) diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py index c65c23bb14..7abad398ce 100644 --- a/tests/regressiontests/utils/module_loading.py +++ b/tests/regressiontests/utils/module_loading.py @@ -31,6 +31,15 @@ class EggLoader(TestCase): 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" @@ -89,51 +98,17 @@ class TestLoader(object): 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.failUnless(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.failUnless(module_has_submodule(egg_module, 'bad_module')) - self.assertRaises(ImportError, import_module, 'egg_module.bad_module') - - # A child that doesn't exist - self.failIf(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.failUnless(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.failUnless(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.failIf(module_has_submodule(egg_module, 'no_such_module')) - self.assertRaises(ImportError, import_module, 'egg_module.sub1.sub2.no_such_module')