summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2009-11-23 15:46:19 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2009-11-23 15:46:19 (GMT)
commit12adc655c8e1e8a620f99142a2fb6e2500d4931a (patch)
tree1347244b64553c07cfca3c9bb21811f640b15111 /Lib/test
parentdd866d57af2e1b82c155b4613c303099785ed62c (diff)
downloadcpython-12adc655c8e1e8a620f99142a2fb6e2500d4931a.zip
cpython-12adc655c8e1e8a620f99142a2fb6e2500d4931a.tar.gz
cpython-12adc655c8e1e8a620f99142a2fb6e2500d4931a.tar.bz2
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')
-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 20339dd..bc0ae58 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -310,6 +310,24 @@ class MiscReadTest(CommonReadTest):
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 empty file raises a ReadError.
+ empty = os.path.join(TEMPDIR, "empty")
+ open(empty, "wb").write("")
+
+ try:
+ tar = object.__new__(tarfile.TarFile)
+ try:
+ tar.__init__(empty)
+ except tarfile.ReadError:
+ self.assertTrue(tar.fileobj.closed)
+ else:
+ self.fail("ReadError not raised")
+ finally:
+ os.remove(empty)
+
class StreamReadTest(CommonReadTest):