diff options
author | Benjamin Peterson <benjamin@python.org> | 2013-01-01 03:40:42 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2013-01-01 03:40:42 (GMT) |
commit | 1f7df8f2070391f28391e3594580c07e11b6b32b (patch) | |
tree | ec03dfe4f71df3840232731145b8f6736fc6a314 /Lib/test/test_tarfile.py | |
parent | b25d611f8d9140e83acbfffb6b0579939c88c033 (diff) | |
parent | 10e93a6d40502e100c68090730e0b3190df97854 (diff) | |
download | cpython-1f7df8f2070391f28391e3594580c07e11b6b32b.zip cpython-1f7df8f2070391f28391e3594580c07e11b6b32b.tar.gz cpython-1f7df8f2070391f28391e3594580c07e11b6b32b.tar.bz2 |
merge heads
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r-- | Lib/test/test_tarfile.py | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index a3685ea..af59e27 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -297,26 +297,21 @@ class MiscReadTest(CommonReadTest): 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")) - tar.extract("ustar/regtype", TEMPDIR) - try: tar.extract("ustar/lnktype", TEMPDIR) - except EnvironmentError, e: - if e.errno == errno.ENOENT: - self.fail("hardlink not extracted properly") - - data = open(os.path.join(TEMPDIR, "ustar/lnktype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) + 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 EnvironmentError, e: - if e.errno == errno.ENOENT: - self.fail("symlink not extracted properly") - - data = open(os.path.join(TEMPDIR, "ustar/symtype"), "rb").read() - self.assertEqual(md5sum(data), md5_regtype) + 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) def test_extractall(self): # Test if extractall() correctly restores directory permissions @@ -858,7 +853,7 @@ class WriteTest(WriteTestBase): tar = tarfile.open(tmpname, "r") for t in tar: - self.assert_(t.name == "." or t.name.startswith("./")) + self.assertTrue(t.name == "." or t.name.startswith("./")) tar.close() finally: os.chdir(cwd) |