[Python-checkins] r52715 - sandbox/trunk/import_in_py/test_importer.py

brett.cannon python-checkins at python.org
Fri Nov 10 00:34:56 CET 2006


Author: brett.cannon
Date: Fri Nov 10 00:34:55 2006
New Revision: 52715

Modified:
   sandbox/trunk/import_in_py/test_importer.py
Log:
Update a test to use a mock module.


Modified: sandbox/trunk/import_in_py/test_importer.py
==============================================================================
--- sandbox/trunk/import_in_py/test_importer.py	(original)
+++ sandbox/trunk/import_in_py/test_importer.py	Fri Nov 10 00:34:55 2006
@@ -128,15 +128,7 @@
         
 class TestPyPycFiles(unittest.TestCase):
     
-    """Base class to help in generating a fresh source and bytecode file.
-
-    XXX refactor:
-    * better attribute names.
-    * file names that cannot be imported normally.
-    * Can easily be used by other classes that also need to generate a package.
-    * Ditch need for separate methods.
-
-    """
+    """Base class to help in generating a fresh source and bytecode file."""
     
     def create_files(self, faked_names=True):
         """Generate the path to a temporary file to test with.
@@ -763,17 +755,18 @@
     def test_parent_path(self):
         # If a parent module has __path__ defined it should be passed as an
         # argument during importing.
+        pkg_name = '<pkg>'
+        module_name = '<module>'
         test_path = ['<test path>']
-        # XXX mock
-        pkg_module = imp.new_module('_test_pkg')
+        pkg_module = mock_importer.MockModule(pkg_name)
         pkg_module.__path__ = test_path
-        sys.modules['_test_pkg'] = pkg_module
+        sys.modules[pkg_name] = pkg_module
         succeed_importer = mock_importer.SucceedImporter()
         sys.meta_path.append(succeed_importer)
-        module_name = '_test_pkg.module'
-        lookup_args = (module_name, test_path)
-        self.importer(module_name)
-        self.failUnless(module_name in sys.modules)
+        full_module_name = '.'.join([pkg_name, module_name])
+        lookup_args = (full_module_name, test_path)
+        self.importer(full_module_name)
+        self.failUnless(full_module_name in sys.modules)
         self.failUnlessEqual(succeed_importer.find_request, lookup_args)
         self.failUnlessEqual(succeed_importer.load_request, lookup_args)
 


More information about the Python-checkins mailing list