Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 41ccfa15d7f5ab96147e2f44ba6f24dc61611eda 1 parent 5211f48
Russell Keith-Magee authored
59  tests/regressiontests/utils/module_loading.py
@@ -31,6 +31,15 @@ def setUp(self):
31 31
 
32 32
     def tearDown(self):
33 33
         sys.path = self.old_path
  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)
34 43
 
35 44
     def test_shallow_loader(self):
36 45
         "Module existence can be tested inside eggs"
@@ -89,51 +98,17 @@ def load_module(self, name):
89 98
         mod.__loader__ = self
90 99
         return mod
91 100
 
92  
-class CustomLoader(TestCase):
  101
+class CustomLoader(EggLoader):
  102
+    """The Custom Loader test is exactly the same as the EggLoader, but
  103
+    it uses a custom defined Loader and Finder that is intentionally
  104
+    split into two classes. Although the EggLoader combines both functions
  105
+    into one class, this isn't required.
  106
+    """
93 107
     def setUp(self):
94  
-        self.egg_dir = '%s/eggs' % os.path.dirname(__file__)
95  
-        self.old_path = sys.path
  108
+        super(CustomLoader, self).setUp()
96 109
         sys.path_hooks.insert(0, TestFinder)
97 110
         sys.path_importer_cache.clear()
98 111
 
99 112
     def tearDown(self):
100  
-        sys.path = self.old_path
  113
+        super(CustomLoader, self).tearDown()
101 114
         sys.path_hooks.pop(0)
102  
-
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')

0 notes on commit 41ccfa1

Please sign in to comment.
Something went wrong with that request. Please try again.