Issue #20243: TarFile no longer raise ReadError when opened in write mode.

This commit is contained in:
Serhiy Storchaka 2014-01-18 16:14:10 +02:00
parent 9fbec7ad5e
commit c2d01423e0
3 changed files with 36 additions and 11 deletions

View file

@ -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