]> granicus.if.org Git - python/commitdiff
Issue #23696: Chain ZipImportError to the OSError
authorVictor Stinner <victor.stinner@gmail.com>
Fri, 20 Mar 2015 09:52:25 +0000 (10:52 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Fri, 20 Mar 2015 09:52:25 +0000 (10:52 +0100)
Lib/test/test_zipimport.py
Modules/zipimport.c

index 1e351c8c8a16e30cfdc5e0ebb18e33f766b234ea..5b8d77cae7b748486d176092b8a977cd1927063d 100644 (file)
@@ -450,7 +450,10 @@ class BadFileZipImportTestCase(unittest.TestCase):
         fd = os.open(TESTMOD, os.O_CREAT, 000)
         try:
             os.close(fd)
-            self.assertZipFailure(TESTMOD)
+
+            with self.assertRaises(zipimport.ZipImportError) as cm:
+                zipimport.zipimporter(TESTMOD)
+            self.assertIsInstance(cm.exception.__context__, PermissionError)
         finally:
             # If we leave "the read-only bit" set on Windows, nothing can
             # delete TESTMOD, and later tests suffer bogus failures.
index e83214c16cfe4ce19c52ecc316ccedbfd8d4965d..38dc0c42907f61e77f94c89aec763f60ccc2db38 100644 (file)
@@ -875,8 +875,12 @@ read_directory(PyObject *archive)
 
     fp = _Py_fopen_obj(archive, "rb");
     if (fp == NULL) {
-        if (PyErr_ExceptionMatches(PyExc_OSError))
+        if (PyErr_ExceptionMatches(PyExc_OSError)) {
+            PyObject *exc, *val, *tb;
+            PyErr_Fetch(&exc, &val, &tb);
             PyErr_Format(ZipImportError, "can't open Zip file: %R", archive);
+            _PyErr_ChainExceptions(exc, val, tb);
+        }
         return NULL;
     }