diff options
Diffstat (limited to 'Lib/test/test_tarfile.py')
| -rw-r--r-- | Lib/test/test_tarfile.py | 16 | 
1 files changed, 16 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index e0c91035bc..b53f3ac399 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -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  | 
