]> granicus.if.org Git - python/commitdiff
This test failed under python -O.
authorTim Peters <tim.peters@gmail.com>
Thu, 2 Aug 2001 17:23:11 +0000 (17:23 +0000)
committerTim Peters <tim.peters@gmail.com>
Thu, 2 Aug 2001 17:23:11 +0000 (17:23 +0000)
rewrite_file():  Delete both .pyc and .pyo leftovers, and explicitly close
the new source file after writing to it.

Lib/test/test_pkgimport.py

index 53e80b00847e836abca1d70f4c46877fbdd62fd2..bff404463be9e185b50fc185c8449acfec447e0c 100644 (file)
@@ -36,9 +36,13 @@ class TestImport(unittest.TestCase):
         self.remove_modules()
 
     def rewrite_file(self, contents):
-        compiled_path = self.module_path + 'c'
-        if os.path.exists(compiled_path): os.remove(compiled_path)
-        open(self.module_path, 'w').write(contents)
+        for extension in "co":
+            compiled_path = self.module_path + extension
+            if os.path.exists(compiled_path):
+                os.remove(compiled_path)
+        f = open(self.module_path, 'w')
+        f.write(contents)
+        f.close()
     
     def test_package_import__semantics(self):