mirror of
https://github.com/python/cpython.git
synced 2025-07-29 06:05:00 +00:00
#1326: document and test zipimporter.archive and zipimporter.prefix.
This commit is contained in:
parent
ae98f50eca
commit
6a57c08dc8
3 changed files with 55 additions and 13 deletions
|
@ -212,6 +212,7 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
z.close()
|
||||
|
||||
zi = zipimport.zipimporter(TEMP_ZIP)
|
||||
self.assertEquals(zi.archive, TEMP_ZIP)
|
||||
self.assertEquals(zi.is_package(TESTPACK), True)
|
||||
zi.load_module(TESTPACK)
|
||||
|
||||
|
@ -232,6 +233,37 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
z.close()
|
||||
os.remove(TEMP_ZIP)
|
||||
|
||||
def testZipImporterMethodsInSubDirectory(self):
|
||||
packdir = TESTPACK + os.sep
|
||||
packdir2 = packdir + TESTPACK2 + os.sep
|
||||
files = {packdir2 + "__init__" + pyc_ext: (NOW, test_pyc),
|
||||
packdir2 + TESTMOD + pyc_ext: (NOW, test_pyc)}
|
||||
|
||||
z = ZipFile(TEMP_ZIP, "w")
|
||||
try:
|
||||
for name, (mtime, data) in files.items():
|
||||
zinfo = ZipInfo(name, time.localtime(mtime))
|
||||
zinfo.compress_type = self.compression
|
||||
z.writestr(zinfo, data)
|
||||
z.close()
|
||||
|
||||
zi = zipimport.zipimporter(TEMP_ZIP + os.sep + packdir)
|
||||
self.assertEquals(zi.archive, TEMP_ZIP)
|
||||
self.assertEquals(zi.prefix, packdir)
|
||||
self.assertEquals(zi.is_package(TESTPACK2), True)
|
||||
zi.load_module(TESTPACK2)
|
||||
|
||||
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))
|
||||
self.assertEquals(zi.get_source(TESTPACK2), None)
|
||||
self.assertEquals(zi.get_source(mod_name), None)
|
||||
finally:
|
||||
z.close()
|
||||
os.remove(TEMP_ZIP)
|
||||
|
||||
def testGetData(self):
|
||||
z = ZipFile(TEMP_ZIP, "w")
|
||||
z.compression = self.compression
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue