mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-25711: Rewrite zipimport in pure Python. (GH-6809)
This commit is contained in:
parent
4ba3b50bfe
commit
79d1c2e6c9
23 changed files with 2998 additions and 3408 deletions
|
@ -551,7 +551,12 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
z.writestr(name, data)
|
||||
z.close()
|
||||
zi = zipimport.zipimporter(TEMP_ZIP)
|
||||
self.assertEqual(data, zi.get_data(FunnyStr(name)))
|
||||
try:
|
||||
data2 = zi.get_data(FunnyStr(name))
|
||||
except AttributeError:
|
||||
pass
|
||||
else:
|
||||
self.assertEqual(data2, data)
|
||||
finally:
|
||||
z.close()
|
||||
os.remove(TEMP_ZIP)
|
||||
|
@ -677,9 +682,9 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
|
||||
zipimport.zipimporter(filename)
|
||||
zipimport.zipimporter(os.fsencode(filename))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with self.assertRaises(TypeError):
|
||||
zipimport.zipimporter(bytearray(os.fsencode(filename)))
|
||||
with self.assertWarns(DeprecationWarning):
|
||||
with self.assertRaises(TypeError):
|
||||
zipimport.zipimporter(memoryview(os.fsencode(filename)))
|
||||
|
||||
@support.cpython_only
|
||||
|
@ -687,14 +692,14 @@ class UncompressedZipImportTestCase(ImportHooksBaseTestCase):
|
|||
# The interpreter shouldn't crash in case of calling methods of an
|
||||
# uninitialized zipimport.zipimporter object.
|
||||
zi = zipimport.zipimporter.__new__(zipimport.zipimporter)
|
||||
self.assertRaises(ValueError, zi.find_module, 'foo')
|
||||
self.assertRaises(ValueError, zi.find_loader, 'foo')
|
||||
self.assertRaises(ValueError, zi.load_module, 'foo')
|
||||
self.assertRaises(ValueError, zi.get_filename, 'foo')
|
||||
self.assertRaises(ValueError, zi.is_package, 'foo')
|
||||
self.assertRaises(ValueError, zi.get_data, 'foo')
|
||||
self.assertRaises(ValueError, zi.get_code, 'foo')
|
||||
self.assertRaises(ValueError, zi.get_source, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.find_module, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.find_loader, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.load_module, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.get_filename, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.is_package, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.get_data, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.get_code, 'foo')
|
||||
self.assertRaises((ValueError, AttributeError), zi.get_source, 'foo')
|
||||
|
||||
|
||||
@support.requires_zlib
|
||||
|
@ -712,7 +717,7 @@ class CompressedZipImportTestCase(UncompressedZipImportTestCase):
|
|||
zip_file.writestr('bar.py', b'print("hello world")', ZIP_DEFLATED)
|
||||
zi = zipimport.zipimporter(TEMP_ZIP)
|
||||
with support.swap_attr(zlib, 'decompress', bad_decompress):
|
||||
self.assertRaises(TypeError, zi.get_source, 'bar')
|
||||
self.assertRaises((TypeError, AttributeError), zi.get_source, 'bar')
|
||||
|
||||
|
||||
class BadFileZipImportTestCase(unittest.TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue