Merged revisions 67750-67751 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r67750 | nick.coghlan | 2008-12-14 20:54:50 +1000 (Sun, 14 Dec 2008) | 1 line
Fix several issues relating to access to source code inside zipfiles. Initial work by Alexander Belopolsky. See Misc/NEWS in this checkin for details.
........
r67751 | nick.coghlan | 2008-12-14 21:09:40 +1000 (Sun, 14 Dec 2008) | 1 line
Add file that was missed from r67750
........
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 754476a..5637467 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -211,16 +211,24 @@
zi = zipimport.zipimporter(TEMP_ZIP)
self.assertEquals(zi.archive, TEMP_ZIP)
self.assertEquals(zi.is_package(TESTPACK), True)
- zi.load_module(TESTPACK)
+ mod = zi.load_module(TESTPACK)
+ self.assertEquals(zi._get_filename(TESTPACK), mod.__file__)
self.assertEquals(zi.is_package(packdir + '__init__'), False)
self.assertEquals(zi.is_package(packdir + TESTPACK2), True)
self.assertEquals(zi.is_package(packdir2 + TESTMOD), False)
- mod_name = packdir2 + TESTMOD
- mod = __import__(module_path_to_dotted_name(mod_name))
+ mod_path = packdir2 + TESTMOD
+ mod_name = module_path_to_dotted_name(mod_path)
+ pkg = __import__(mod_name)
+ mod = sys.modules[mod_name]
self.assertEquals(zi.get_source(TESTPACK), None)
- self.assertEquals(zi.get_source(mod_name), None)
+ self.assertEquals(zi.get_source(mod_path), None)
+ self.assertEquals(zi._get_filename(mod_path), mod.__file__)
+ # To pass in the module name instead of the path, we must use the right importer
+ loader = mod.__loader__
+ self.assertEquals(loader.get_source(mod_name), None)
+ self.assertEquals(loader._get_filename(mod_name), mod.__file__)
# test prefix and archivepath members
zi2 = zipimport.zipimporter(TEMP_ZIP + os.sep + TESTPACK)
@@ -248,15 +256,23 @@
self.assertEquals(zi.archive, TEMP_ZIP)
self.assertEquals(zi.prefix, packdir)
self.assertEquals(zi.is_package(TESTPACK2), True)
- zi.load_module(TESTPACK2)
+ mod = zi.load_module(TESTPACK2)
+ self.assertEquals(zi._get_filename(TESTPACK2), mod.__file__)
self.assertEquals(zi.is_package(TESTPACK2 + os.sep + '__init__'), False)
self.assertEquals(zi.is_package(TESTPACK2 + os.sep + TESTMOD), False)
- mod_name = TESTPACK2 + os.sep + TESTMOD
- mod = __import__(module_path_to_dotted_name(mod_name))
+ mod_path = TESTPACK2 + os.sep + TESTMOD
+ mod_name = module_path_to_dotted_name(mod_path)
+ pkg = __import__(mod_name)
+ mod = sys.modules[mod_name]
self.assertEquals(zi.get_source(TESTPACK2), None)
- self.assertEquals(zi.get_source(mod_name), None)
+ self.assertEquals(zi.get_source(mod_path), None)
+ self.assertEquals(zi._get_filename(mod_path), mod.__file__)
+ # To pass in the module name instead of the path, we must use the right importer
+ loader = mod.__loader__
+ self.assertEquals(loader.get_source(mod_name), None)
+ self.assertEquals(loader._get_filename(mod_name), mod.__file__)
finally:
z.close()
os.remove(TEMP_ZIP)