[Python-checkins] cpython (merge 3.3 -> default): Issue #16645: Fix hardlink extracting test for tarfile.

serhiy.storchaka python-checkins at python.org
Sun Dec 30 19:22:27 CET 2012


http://hg.python.org/cpython/rev/f173c2e92b64
changeset:   81158:f173c2e92b64
parent:      81154:08c215115842
parent:      81157:e1a0901e4ef7
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sun Dec 30 20:18:58 2012 +0200
summary:
  Issue #16645: Fix hardlink extracting test for tarfile.

files:
  Lib/test/test_tarfile.py |  24 +++++++-----------------
  1 files changed, 7 insertions(+), 17 deletions(-)


diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -336,31 +336,21 @@
     @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")
+        with tarfile.open(tarname, errorlevel=1, encoding="iso8859-1") as tar:
+            tar.extract("ustar/regtype", TEMPDIR)
+            self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/regtype"))
 
-        try:
-            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")
-
+            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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list