diff options
author | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-14 11:50:48 (GMT) |
---|---|---|
committer | Nick Coghlan <ncoghlan@gmail.com> | 2008-12-14 11:50:48 (GMT) |
commit | f088e5e6cc0e7ad7991a910be13510ca33e91958 (patch) | |
tree | bc4281856af88400076b08b3e6d4431565017e3e /Lib/test/test_zipimport.py | |
parent | 80a0c7f62366235059bd2e5892554fa75c7670ca (diff) | |
download | cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.zip cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.tar.gz cpython-f088e5e6cc0e7ad7991a910be13510ca33e91958.tar.bz2 |
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
........
Diffstat (limited to 'Lib/test/test_zipimport.py')
-rw-r--r-- | Lib/test/test_zipimport.py | 32 |
1 files changed, 24 insertions, 8 deletions
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 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): 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 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase): 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) |