Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-25711: Rewrite zipimport in pure Python.
  • Loading branch information
serhiy-storchaka committed Jul 8, 2018
commit c09021102592228fbcf30debf9bda20ea0f780d2
22 changes: 11 additions & 11 deletions Lib/test/test_zipimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,24 +677,24 @@ def testBytesPath(self):

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
def testUninitializedZipimporter(self):
# 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')
Comment thread
warsaw marked this conversation as resolved.
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
Expand All @@ -712,7 +712,7 @@ def bad_decompress(*args):
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')
Comment thread
warsaw marked this conversation as resolved.


class BadFileZipImportTestCase(unittest.TestCase):
Expand Down
Loading