summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRussell Keith-Magee <russell@keith-magee.com>2010-05-04 14:48:43 +0000
committerRussell Keith-Magee <russell@keith-magee.com>2010-05-04 14:48:43 +0000
commit41ccfa15d7f5ab96147e2f44ba6f24dc61611eda (patch)
tree8e74767f1468d390c65c92543fb755d884fcbe9a /tests
parent5211f48ae3cc0d87a260dbf5c3ab8bdae664c4b6 (diff)
downloaddjango-41ccfa15d7f5ab96147e2f44ba6f24dc61611eda.tar.gz
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.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13095 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/utils/module_loading.py59
1 files changed, 17 insertions, 42 deletions
diff --git a/tests/regressiontests/utils/module_loading.py b/tests/regressiontests/utils/module_loading.py
index 7b233f8e14..b7df6d68b1 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.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')