diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2012-12-30 18:18:58 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2012-12-30 18:18:58 (GMT) |
commit | 2aa4e6cdec5392c1ef6e9573b66accba5b982b5b (patch) | |
tree | a7c49903ae0b089a153b07bd03e47b5a1531d341 /Lib/test/test_tarfile.py | |
parent | d7e2666449b7ab3a8f1d5042c4486d693f81deb0 (diff) | |
parent | 62c75f1e527d4f12dc72c3311cdd4ed23a567308 (diff) | |
download | cpython-2aa4e6cdec5392c1ef6e9573b66accba5b982b5b.zip cpython-2aa4e6cdec5392c1ef6e9573b66accba5b982b5b.tar.gz cpython-2aa4e6cdec5392c1ef6e9573b66accba5b982b5b.tar.bz2 |
Issue #16645: Fix hardlink extracting test for tarfile.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 22 |
1 files changed, 6 insertions, 16 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index 0c4328f..5bbd48e 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -336,31 +336,21 @@ class MiscReadTest(CommonReadTest): @support.skip_unless_symlink def test_extract_hardlink(self): # Test hardlink extraction (e.g. bug #857297). - tar = tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") - - try: + with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar: tar.extract("ustar/regtype", TEMPDIR) - try: - tar.extract("ustar/lnktype", TEMPDIR) - except OSError as e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype")) + tar.extract("ustar/lnktype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype")) with open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - try: - tar.extract("ustar/symtype", TEMPDIR) - except OSError as e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - + tar.extract("ustar/symtype", TEMPDIR) + self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype")) with open(os.path.join(TEMPDIR, "ustar/symtype"), "rb") as f: data = f.read() self.assertEqual(md5sum(data), md5_regtype) - finally: - tar.close() def test_extractall(self): # Test if extractall() correctly restores directory permissions |