[Python-checkins] r56789 - sandbox/trunk/import_in_py/zipimport_/tests.py

brett.cannon python-checkins at python.org
Tue Aug 7 07:18:01 CEST 2007


Author: brett.cannon
Date: Tue Aug  7 07:18:00 2007
New Revision: 56789

Modified:
   sandbox/trunk/import_in_py/zipimport_/tests.py
Log:
Fix constructor tests.


Modified: sandbox/trunk/import_in_py/zipimport_/tests.py
==============================================================================
--- sandbox/trunk/import_in_py/zipimport_/tests.py	(original)
+++ sandbox/trunk/import_in_py/zipimport_/tests.py	Tue Aug  7 07:18:00 2007
@@ -3,21 +3,32 @@
 
 import contextlib
 import os
+import py_compile
 from test import test_support
 import unittest
 import zipfile
 
+
 @contextlib.contextmanager
 def temp_zipfile():
     """Create a temporary zip file for testing."""
-    path = test_support.TESTFN + '.zip'
-    zip_file = zipfile.ZipFile(path, 'w')
+    zip_path = test_support.TESTFN + '.zip'
+    zip_file = zipfile.ZipFile(zip_path, 'w')
     try:
-        zip_file.writestr('_top_level.py', 'attr = None')
+        for module_path in ['_top_level.py']:
+            with open(module_path, 'w') as temp_file:
+                temp_file.write('attr = None')
+            try:
+                py_compile.compile(module_path, doraise=True)
+                zip_file.write(module_path)
+                zip_file.write(module_path + 'c' if __debug__ else 'o')
+            finally:
+                test_support.unlink(module_path)
+                test_support.unlink(module_path + 'c' if __debug__ else 'o')
         zip_file.close()
-        yield path
+        yield zip_path
     finally:
-        os.unlink(path)
+        os.unlink(zip_path)
 
 
 class ZipImportErrorTests(unittest.TestCase):
@@ -41,7 +52,7 @@
                 self.assertRaises(zipimport.ZipImportError,
                         zipimport.zipimporter, test_support.TESTFN)
             finally:
-                os.unlink(test_support.TESTFN)
+                test_support.unlink(test_support.TESTFN)
 
     def test_zipfile(self):
         # A zipfile should return an instance of zipimporter.


More information about the Python-checkins mailing list