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

brett.cannon python-checkins at python.org
Wed Aug 22 01:20:15 CEST 2007


Author: brett.cannon
Date: Wed Aug 22 01:20:14 2007
New Revision: 57272

Modified:
   sandbox/trunk/import_in_py/tests/test_fs_loader.py
Log:
Add a (failing) test for the loader to continue to work even when the state of
the filesystem has changed since the initialization of the source loader.

Discovered thanks to test_runpy, the test that keeps on giving me pain and
agony.


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	Wed Aug 22 01:20:14 2007
@@ -117,6 +117,21 @@
         self.assertRaises(ImportError, loader.load_module, self.module_name)
         self.assert_(self.module_name not in sys.modules)
 
+    def test_file_deletion_post_init(self):
+        # Loading from source (with no bytecode), deleting the source (because
+        # bytecode was generated), and then loading again should work.
+        test_support.unlink(self.pyc_path)
+        if self.module_name in sys.modules:
+            del sys.modules[self.module_name]
+        loader = importlib._PyFileLoader(self.module_name, self.py_path, False)
+        found = loader.load_module(self.module_name)
+        self.verify_package(found, self.module_name)
+        del sys.modules[self.module_name]
+        os.unlink(self.py_path)
+        assert os.path.exists(self.pyc_path)
+        found = loader.load_module(self.module_name)
+        self.verify_package(found, self.module_name)
+
 
 def log_call(instance, method_name):
     """Log a method call."""


More information about the Python-checkins mailing list