]> granicus.if.org Git - python/commitdiff
Backported test for the open of non-existent tarfile.
authorSerhiy Storchaka <storchaka@gmail.com>
Mon, 13 Jan 2014 17:08:51 +0000 (19:08 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Mon, 13 Jan 2014 17:08:51 +0000 (19:08 +0200)
Lib/test/test_tarfile.py

index d3ad707e82736f8e8f06e3af53e6839e8e77569b..3e054ac5ee10d0cc68d4b9b9e8d9ae85fee5cbb4 100644 (file)
@@ -181,6 +181,14 @@ class CommonReadTest(ReadTest):
         self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
         self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
 
+    def test_non_existent_tarfile(self):
+        # Test for issue11513: prevent non-existent gzipped tarfiles raising
+        # multiple exceptions.
+        exctype = OSError if '|' in self.mode else IOError
+        with self.assertRaisesRegexp(exctype, "xxx") as ex:
+            tarfile.open("xxx", self.mode)
+        self.assertEqual(ex.exception.errno, errno.ENOENT)
+
     def test_ignore_zeros(self):
         # Test TarFile's ignore_zeros option.
         if self.mode.endswith(":gz"):