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

brett.cannon python-checkins at python.org
Sat Aug 25 06:19:10 CEST 2007


Author: brett.cannon
Date: Sat Aug 25 06:19:10 2007
New Revision: 57452

Modified:
   sandbox/trunk/import_in_py/zipimport_/tests.py
   sandbox/trunk/import_in_py/zipimport_/zipimport.py
Log:
Test get_source.  Also add test stubs for load_module.


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	Sat Aug 25 06:19:10 2007
@@ -151,8 +151,17 @@
 
     """Test zipimporter.get_source()."""
 
-    def test_get_source(self):
-        raise NotImplementedError
+    def test_get_top_level_source(self):
+        with temp_zipfile(bytecode=False) as zip_path:
+            importer = zipimport.zipimporter(zip_path)
+            importer.find_module('_top_level')
+            self.assertEqual(example_code, importer.get_source('_top_level'))
+
+    def test_pkg_source(self):
+        with temp_zipfile(bytecode=False) as zip_path:
+            importer = zipimport.zipimporter(zip_path)
+            importer.find_module('_pkg')
+            self.assertEqual(example_code, importer.get_source('_pkg'))
 
 
 class GetCode(unittest.TestCase):
@@ -167,9 +176,24 @@
 
     """Test zipimporter.load_module()."""
 
-    def test_basic(self):
+    def test_mod_time(self):
+        raise NotImplementedError
+
+    def test_top_level(self):
+        raise NotImplementedError
+
+    def test_pkg(self):
+        raise NotImplementedError
+
+    def test_submodule(self):
+        raise NotImplementedError
+
+    def test_subpkg(self):
         raise NotImplementedError
- 
+
+    def test_subsubmodule(self):
+        raise NotImplementedError
+
 
 def test_main():
     test_support.run_unittest(ZipImportErrorTests, ZipImportCreation,

Modified: sandbox/trunk/import_in_py/zipimport_/zipimport.py
==============================================================================
--- sandbox/trunk/import_in_py/zipimport_/zipimport.py	(original)
+++ sandbox/trunk/import_in_py/zipimport_/zipimport.py	Sat Aug 25 06:19:10 2007
@@ -127,7 +127,7 @@
             raise ZipImportError("%s is not known" % fullname)
         if info[0] is None:
             return None
-        with importlib.closing(zipfile.ZipFile(self._zip_path)) as zip_:
+        with contextlib.closing(zipfile.ZipFile(self._zip_path)) as zip_:
             return zip_.open(info[0], 'U').read()
 
     def is_package(self, fullname):


More information about the Python-checkins mailing list