import sys
import os
import io
-import shutil
from hashlib import md5
import unittest
# 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)
self.assertEqual(tarinfo.mtime, file_mtime, errmsg)
finally:
tar.close()
- shutil.rmtree(DIR)
+ support.rmtree(DIR)
def test_extract_directory(self):
dirtype = "ustar/dirtype"
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
fobj.seek(4096)
fobj.truncate()
s = os.stat(name)
- os.remove(name)
+ support.unlink(name)
return s.st_blocks == 0
else:
return False
finally:
tar.close()
finally:
- os.rmdir(path)
+ support.rmdir(path)
@unittest.skipUnless(hasattr(os, "link"),
"Missing hardlink implementation")
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):
finally:
tar.close()
finally:
- os.remove(path)
+ support.unlink(path)
def test_add_self(self):
# Test for #1257255.
finally:
tar.close()
finally:
- shutil.rmtree(tempdir)
+ support.rmtree(tempdir)
def test_filter(self):
tempdir = os.path.join(TEMPDIR, "filter")
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
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, "/"))
finally:
tar.close()
finally:
- os.unlink(temparchive)
- shutil.rmtree(tempdir)
+ support.unlink(temparchive)
+ support.rmtree(tempdir)
def test_pathnames(self):
self._test_pathname("foo")
# 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:
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:
def tearDownModule():
if os.path.exists(TEMPDIR):
- shutil.rmtree(TEMPDIR)
+ support.rmtree(TEMPDIR)
if __name__ == "__main__":
unittest.main()
import sys
import importlib.util
import time
-import shutil
import struct
import zipfile
import unittest
from tempfile import TemporaryFile
from random import randint, random, getrandbits
-from test.support import (TESTFN, findfile, unlink,
+from test.support import (TESTFN, findfile, unlink, rmtree,
requires_zlib, requires_bz2, requires_lzma,
captured_stdout, check_warnings)
self.assertNotIn('mod2.txt', names)
finally:
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
def test_write_python_directory_filtered(self):
os.mkdir(TESTFN2)
self.assertNotIn('mod2.py', names)
finally:
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
def test_write_non_pyfile(self):
with TemporaryFile() as t, zipfile.PyZipFile(t, "w") as zipfp:
self.assertNotIn('mod1.pyo', names)
finally:
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
class ExtractTests(unittest.TestCase):
os.remove(writtenfile)
# remove the test file subdirectories
- shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+ rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
def test_extract_all(self):
with zipfile.ZipFile(TESTFN2, "w", zipfile.ZIP_STORED) as zipfp:
os.remove(outfile)
# remove the test file subdirectories
- shutil.rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
+ rmtree(os.path.join(os.getcwd(), 'ziptest2dir'))
def check_file(self, filename, content):
self.assertTrue(os.path.isfile(filename))
msg='extract %r: %r != %r' %
(arcname, writtenfile, correctfile))
self.check_file(correctfile, content)
- shutil.rmtree('target')
+ rmtree('target')
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
zipfp.extractall(targetpath)
self.check_file(correctfile, content)
- shutil.rmtree('target')
+ rmtree('target')
correctfile = os.path.join(os.getcwd(), *fixedname.split('/'))
self.assertEqual(writtenfile, correctfile,
msg="extract %r" % arcname)
self.check_file(correctfile, content)
- shutil.rmtree(fixedname.split('/')[0])
+ rmtree(fixedname.split('/')[0])
with zipfile.ZipFile(TESTFN2, 'r') as zipfp:
zipfp.extractall()
self.check_file(correctfile, content)
- shutil.rmtree(fixedname.split('/')[0])
+ rmtree(fixedname.split('/')[0])
os.remove(TESTFN2)
self.assertTrue(zipf.filelist[0].filename.endswith("x/"))
def tearDown(self):
- shutil.rmtree(TESTFN2)
+ rmtree(TESTFN2)
if os.path.exists(TESTFN):
unlink(TESTFN)