Issue #20243: TarFile no longer raise ReadError when opened in write mode.
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 8767d51..e817f61 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -979,6 +979,22 @@
os.unlink(temparchive)
shutil.rmtree(tempdir)
+ def test_open_nonwritable_fileobj(self):
+ for exctype in IOError, EOFError, RuntimeError:
+ class BadFile(StringIO.StringIO):
+ 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 StreamWriteTest(WriteTestBase):
mode = "w|"