[Python-checkins] r57205 - sandbox/trunk/import_in_py/tests/test_fs_loader.py

brett.cannon python-checkins at python.org
Mon Aug 20 02:58:38 CEST 2007


Author: brett.cannon
Date: Mon Aug 20 02:58:37 2007
New Revision: 57205

Modified:
   sandbox/trunk/import_in_py/tests/test_fs_loader.py
Log:
Implement a test to verify partially initialized modules are deleted.  Also
stick in a ton of stub tests that need to get written.


Modified: sandbox/trunk/import_in_py/tests/test_fs_loader.py
==============================================================================
--- sandbox/trunk/import_in_py/tests/test_fs_loader.py	(original)
+++ sandbox/trunk/import_in_py/tests/test_fs_loader.py	Mon Aug 20 02:58:37 2007
@@ -75,12 +75,20 @@
         self.assert_(not self.loader.get_source(self.testing_module))
 
 
-class PyFileLoaderTests(LoaderBasics, TestPyPycPackages):
+class BasicPyFileLoaderTests(LoaderBasics, TestPyPycPackages):
+
+    """Very basic tests for the source loader."""
+
+    def setUp(self):
+        TestPyPycPackages.setUp(self, faked_names=False)
 
     def test_basic(self):
         loader = importlib._PyFileLoader(self.module_name, self.py_path, False)
         self.basic_test(loader, self.module_name, self.py_path)
 
+    def test_pkg_basic(self):
+        raise NotImplementedError
+
     def test_reload(self):
         loader = importlib._PyFileLoader(self.module_name, self.py_path, False)
         self.reload_test(loader, self.module_name)
@@ -91,9 +99,55 @@
         self.ImportError_on_bad_name(loader, self.module_name + 'sdfasdf',
                                         extra_methods)
 
+    def test_no_stale_module_on_failure(self):
+        # A failure during loading should not leave a partially initialized
+        # module in sys.modules.
+        def fail_loading(loader, name, *args):
+            sys.modules[name] = 'Should not exist'
+            raise ImportError('initial failed load')
+        loader = importlib._PyFileLoader(self.module_name, self.py_path, False)
+        loader._handler = fail_loading
+        self.assertRaises(ImportError, loader.load_module, self.module_name)
+        self.assert_(self.module_name not in sys.modules)
+
+
+class PyFileLoaderLoadingTests(TestPyPycPackages):
+
+    """Test that the source loader uses the proper file.
+
+    Make sure all tests are run both against a top-level module and a package
+    where appropriate.
+
+    """
+
+    def setUp(self):
+        TestPyPycPackages.setUp(self, faked_names=False)
+
+    def test_pyc_over_py(self):
+        # If a bytecode file is good, don't even bother with the source.
+        raise NotImplementedError
+
+    def test_only_good_pyc(self):
+        # Should be able to load even if only bytecode is available.
+        raise NotImplementedError
+
+    def test_only_py(self):
+        # Having only source should be fine.
+        raise NotImplementedError
+
+    def test_stale_pyc(self):
+        # If a bytecode file is stale, regenerate it and use the source.
+        raise NotImplementedError
+
+    def test_bad_magic(self):
+        # If the magic cookie for bytecode is bad, use the source and
+        # regenerate the bytecode.
+        raise NotImplementedError
+
 
 def test_main():
-    test_support.run_unittest(ExtensionFileLoaderTests, PyFileLoaderTests)
+    test_support.run_unittest(ExtensionFileLoaderTests, BasicPyFileLoaderTests,
+                                PyFileLoaderLoadingTests)
 
 
 if __name__ == '__main__':


More information about the Python-checkins mailing list