mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Do not close external file objects passed to tarfile.open(mode='w:bz2')
when the TarFile is closed.
This commit is contained in:
parent
0902cac4b3
commit
b1a54a3530
3 changed files with 17 additions and 3 deletions
|
@ -529,7 +529,19 @@ class PaxReadTest(LongnameTest):
|
|||
self.assertEqual(float(tarinfo.pax_headers["ctime"]), 1041808783.0)
|
||||
|
||||
|
||||
class WriteTest(unittest.TestCase):
|
||||
class WriteTestBase(unittest.TestCase):
|
||||
# Put all write tests in here that are supposed to be tested
|
||||
# in all possible mode combinations.
|
||||
|
||||
def test_fileobj_no_close(self):
|
||||
fobj = StringIO.StringIO()
|
||||
tar = tarfile.open(fileobj=fobj, mode=self.mode)
|
||||
tar.addfile(tarfile.TarInfo("foo"))
|
||||
tar.close()
|
||||
self.assert_(fobj.closed is False, "external fileobjs must never closed")
|
||||
|
||||
|
||||
class WriteTest(WriteTestBase):
|
||||
|
||||
mode = "w:"
|
||||
|
||||
|
@ -652,7 +664,7 @@ class WriteTest(unittest.TestCase):
|
|||
shutil.rmtree(tempdir)
|
||||
|
||||
|
||||
class StreamWriteTest(unittest.TestCase):
|
||||
class StreamWriteTest(WriteTestBase):
|
||||
|
||||
mode = "w|"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue