summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_zipimport.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2018-09-18 19:22:29 (GMT)
committerGitHub <noreply@github.com>2018-09-18 19:22:29 (GMT)
commit79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b (patch)
tree024dfc74ad7bd5290180638b1290301ef928426f /Lib/test/test_zipimport.py
parent4ba3b50bfe6d50cd82d208023ea23e203ab50589 (diff)
downloadcpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.zip
cpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.tar.gz
cpython-79d1c2e6c9d1bc1cf41ec3041801ca1a2b9a995b.tar.bz2
bpo-25711: Rewrite zipimport in pure Python. (GH-6809)
Diffstat (limited to 'Lib/test/test_zipimport.py')
-rw-r--r--Lib/test/test_zipimport.py29
1 files changed, 17 insertions, 12 deletions
diff --git a/Lib/test/test_zipimport.py b/Lib/test/test_zipimport.py
index 901bebd..cad73ea 100644
--- a/Lib/test/test_zipimport.py
+++ b/Lib/test/test_zipimport.py
@@ -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):