summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-09-03 22:49:01 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-09-03 22:49:01 (GMT)
commit57004c696aa883b4dae5516b6babd92e3f8b7de7 (patch)
tree6c6421909548f73c1ffe00270aadd6eb59946a78 /Lib/test/test_tarfile.py
parent19c899c1b143a4d1de09d6dad73e8b10e28ab037 (diff)
downloadcpython-57004c696aa883b4dae5516b6babd92e3f8b7de7.zip
cpython-57004c696aa883b4dae5516b6babd92e3f8b7de7.tar.gz
cpython-57004c696aa883b4dae5516b6babd92e3f8b7de7.tar.bz2
Issue #21440: Backport changeset 4ebf97299b18 to branch 3.4, use
support.rmtree() and support.unlink() in test_zipfile & test_tarfile
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py39
1 files changed, 19 insertions, 20 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 82aa840..e527e40 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -1,7 +1,6 @@
import sys
import os
import io
-import shutil
from hashlib import md5
import unittest
@@ -480,16 +479,16 @@ class MiscReadTestBase(CommonReadTest):
# Test hardlink extraction (e.g. bug #857297).
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"))
+ self.addCleanup(support.unlink, os.path.join(TEMPDIR, "ustar/regtype"))
tar.extract("ustar/lnktype", TEMPDIR)
- self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/lnktype"))
+ self.addCleanup(support.unlink, 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)
tar.extract("ustar/symtype", TEMPDIR)
- self.addCleanup(os.remove, os.path.join(TEMPDIR, "ustar/symtype"))
+ self.addCleanup(support.unlink, 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)
@@ -522,7 +521,7 @@ class MiscReadTestBase(CommonReadTest):
self.assertEqual(tarinfo.mtime, file_mtime, errmsg)
finally:
tar.close()
- shutil.rmtree(DIR)
+ support.rmtree(DIR)
def test_extract_directory(self):
dirtype = "ustar/dirtype"
@@ -537,7 +536,7 @@ class MiscReadTestBase(CommonReadTest):
if sys.platform != "win32":
self.assertEqual(os.stat(extracted).st_mode & 0o777, 0o755)
finally:
- shutil.rmtree(DIR)
+ support.rmtree(DIR)
def test_init_close_fobj(self):
# Issue #7341: Close the internal file object in the TarFile
@@ -901,7 +900,7 @@ class GNUReadTest(LongnameTest, ReadTest, unittest.TestCase):
fobj.seek(4096)
fobj.truncate()
s = os.stat(name)
- os.remove(name)
+ support.unlink(name)
return s.st_blocks == 0
else:
return False
@@ -1034,7 +1033,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- os.rmdir(path)
+ support.rmdir(path)
@unittest.skipUnless(hasattr(os, "link"),
"Missing hardlink implementation")
@@ -1054,8 +1053,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- os.remove(target)
- os.remove(link)
+ support.unlink(target)
+ support.unlink(link)
@support.skip_unless_symlink
def test_symlink_size(self):
@@ -1069,7 +1068,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- os.remove(path)
+ support.unlink(path)
def test_add_self(self):
# Test for #1257255.
@@ -1116,7 +1115,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- shutil.rmtree(tempdir)
+ support.rmtree(tempdir)
def test_filter(self):
tempdir = os.path.join(TEMPDIR, "filter")
@@ -1152,7 +1151,7 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- shutil.rmtree(tempdir)
+ support.rmtree(tempdir)
# Guarantee that stored pathnames are not modified. Don't
# remove ./ or ../ or double slashes. Still make absolute
@@ -1180,9 +1179,9 @@ class WriteTest(WriteTestBase, unittest.TestCase):
tar.close()
if not dir:
- os.remove(foo)
+ support.unlink(foo)
else:
- os.rmdir(foo)
+ support.rmdir(foo)
self.assertEqual(t.name, cmp_path or path.replace(os.sep, "/"))
@@ -1213,8 +1212,8 @@ class WriteTest(WriteTestBase, unittest.TestCase):
finally:
tar.close()
finally:
- os.unlink(temparchive)
- shutil.rmtree(tempdir)
+ support.unlink(temparchive)
+ support.rmtree(tempdir)
def test_pathnames(self):
self._test_pathname("foo")
@@ -1314,7 +1313,7 @@ class StreamWriteTest(WriteTestBase, unittest.TestCase):
# Test for issue #8464: Create files with correct
# permissions.
if os.path.exists(tmpname):
- os.remove(tmpname)
+ support.unlink(tmpname)
original_umask = os.umask(0o022)
try:
@@ -1668,7 +1667,7 @@ class AppendTestBase:
def setUp(self):
self.tarname = tmpname
if os.path.exists(self.tarname):
- os.remove(self.tarname)
+ support.unlink(self.tarname)
def _create_testtar(self, mode="w:"):
with tarfile.open(tarname, encoding="iso8859-1") as src:
@@ -2175,7 +2174,7 @@ def setUpModule():
def tearDownModule():
if os.path.exists(TEMPDIR):
- shutil.rmtree(TEMPDIR)
+ support.rmtree(TEMPDIR)
if __name__ == "__main__":
unittest.main()