diff options
author | Lars Gustäbel <lars@gustaebel.de> | 2009-11-23 16:01:56 +0000 |
---|---|---|
committer | Lars Gustäbel <lars@gustaebel.de> | 2009-11-23 16:01:56 +0000 |
commit | 55fa13cb69edb6db608a9aef17f8a5f27c0e3990 (patch) | |
tree | df2cab224afb125f01b9b251f2056d12bfe8271b | |
parent | 07361c19a7639416bf9fc4631ce5fcc7c4b21125 (diff) | |
download | cpython-git-55fa13cb69edb6db608a9aef17f8a5f27c0e3990.tar.gz |
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).
........
-rw-r--r-- | Lib/test/test_tarfile.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 75cc0e73d6..e2682c44cc 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -264,6 +264,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("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): |