mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #20243: TarFile no longer raise ReadError when opened in write mode.
This commit is contained in:
commit
aee0e63ed0
3 changed files with 35 additions and 10 deletions
|
@ -1157,6 +1157,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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue