summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2009-11-23 16:04:57 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2009-11-23 16:04:57 (GMT)
commit45711a723707b309c14c38da4dbf593fa4a57a80 (patch)
tree033385f144ce54d82a426727062b46ec2d9f6bb6 /Lib/test/test_tarfile.py
parent4c3805958fd55443266db80eddca5102729bcedd (diff)
downloadcpython-45711a723707b309c14c38da4dbf593fa4a57a80.zip
cpython-45711a723707b309c14c38da4dbf593fa4a57a80.tar.gz
cpython-45711a723707b309c14c38da4dbf593fa4a57a80.tar.bz2
Merged revisions 76453 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ................ r76453 | lars.gustaebel | 2009-11-23 16:48:33 +0100 (Mon, 23 Nov 2009) | 10 lines Merged revisions 76452 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r76452 | lars.gustaebel | 2009-11-23 16:46:19 +0100 (Mon, 23 Nov 2009) | 3 lines Add a testcase that checks if the TarFile constructor successfully closes the internal file object in case of an error (issue #7341). ........ ................
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index d0dd71e..2746448 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -263,6 +263,24 @@ class MiscReadTest(ReadTest):
self.assertEqual(tarinfo.mtime, os.path.getmtime(path))
tar.close()
+ def test_init_close_fobj(self):
+ # Issue #7341: Close the internal file object in the TarFile
+ # constructor in case of an error. For the test we rely on
+ # the fact that opening an invalid file raises a ReadError.
+ invalid = os.path.join(TEMPDIR, "invalid")
+ open(invalid, "wb").write(b"foo")
+
+ try:
+ tar = object.__new__(tarfile.TarFile)
+ try:
+ tar.__init__(invalid)
+ except tarfile.ReadError:
+ self.assertTrue(tar.fileobj.closed)
+ else:
+ self.fail("ReadError not raised")
+ finally:
+ os.remove(invalid)
+
class StreamReadTest(ReadTest):