Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d804f53

Browse files
Backported test for the open of non-existent tarfile.
1 parent 2e27ddd commit d804f53

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/test_tarfile.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ def test_null_tarfile(self):
181181
self.assertRaises(tarfile.ReadError, tarfile.open, tmpname, self.mode)
182182
self.assertRaises(tarfile.ReadError, tarfile.open, tmpname)
183183

184+
def test_non_existent_tarfile(self):
185+
# Test for issue11513: prevent non-existent gzipped tarfiles raising
186+
# multiple exceptions.
187+
exctype = OSError if '|' in self.mode else IOError
188+
with self.assertRaisesRegexp(exctype, "xxx") as ex:
189+
tarfile.open("xxx", self.mode)
190+
self.assertEqual(ex.exception.errno, errno.ENOENT)
191+
184192
def test_ignore_zeros(self):
185193
# Test TarFile's ignore_zeros option.
186194
if self.mode.endswith(":gz"):

0 commit comments

Comments
 (0)