From c2d01423e02d9721f897812cf6a93e64c7d75c15 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Sat, 18 Jan 2014 16:14:10 +0200 Subject: Issue #20243: TarFile no longer raise ReadError when opened in write mode. --- Lib/test/test_tarfile.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Lib/test/test_tarfile.py') diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ceaa3aa494..f22b908797 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -1155,6 +1155,22 @@ class WriteTest(WriteTestBase, unittest.TestCase): finally: os.chdir(cwd) + def test_open_nonwritable_fileobj(self): + for exctype in OSError, EOFError, RuntimeError: + class BadFile(io.BytesIO): + first = True + def write(self, data): + if self.first: + self.first = False + raise exctype + + f = BadFile() + with self.assertRaises(exctype): + tar = tarfile.open(tmpname, self.mode, fileobj=f, + format=tarfile.PAX_FORMAT, + pax_headers={'non': 'empty'}) + self.assertFalse(f.closed) + class GzipWriteTest(GzipTest, WriteTest): pass -- cgit v1.2.1