[Python-checkins] r76453 - in python/branches/py3k: Lib/test/test_tarfile.py
lars.gustaebel
python-checkins at python.org
Mon Nov 23 16:48:33 CET 2009
Author: lars.gustaebel
Date: Mon Nov 23 16:48:33 2009
New Revision: 76453
Log:
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).
........
Modified:
python/branches/py3k/ (props changed)
python/branches/py3k/Lib/test/test_tarfile.py
Modified: python/branches/py3k/Lib/test/test_tarfile.py
==============================================================================
--- python/branches/py3k/Lib/test/test_tarfile.py (original)
+++ python/branches/py3k/Lib/test/test_tarfile.py Mon Nov 23 16:48:33 2009
@@ -309,6 +309,24 @@
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(b"")
+
+ 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):
More information about the Python-checkins
mailing list