summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-09-06 11:14:49 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-09-06 11:14:49 (GMT)
commit5fbadb63ef2a3d7645396e1f11fe9303883c7e65 (patch)
tree75d288ce9278350ed4dd3730de0d822999e76340 /Lib/test/test_shutil.py
parentdcaf4ccf3f1d8040313f68b77424d39691389164 (diff)
parent2a23adf4405bcd903aabf445dd54867d95f494a1 (diff)
downloadcpython-5fbadb63ef2a3d7645396e1f11fe9303883c7e65.zip
cpython-5fbadb63ef2a3d7645396e1f11fe9303883c7e65.tar.gz
cpython-5fbadb63ef2a3d7645396e1f11fe9303883c7e65.tar.bz2
Use support.change_cwd() in tests.
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py44
1 files changed, 7 insertions, 37 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 5183c3c..b1e4aa1 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -12,8 +12,6 @@ import errno
import functools
import subprocess
from contextlib import ExitStack
-from test import support
-from test.support import TESTFN
from os.path import splitdrive
from distutils.spawn import find_executable, spawn
from shutil import (_make_tarball, _make_zipfile, make_archive,
@@ -974,12 +972,8 @@ class TestShutil(unittest.TestCase):
base_name = os.path.join(tmpdir2, 'archive')
# working with relative paths to avoid tar warnings
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
_make_tarball(splitdrive(base_name)[1], '.')
- finally:
- os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
@@ -987,12 +981,8 @@ class TestShutil(unittest.TestCase):
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
_make_tarball(splitdrive(base_name)[1], '.', compress=None)
- finally:
- os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
@@ -1024,12 +1014,8 @@ class TestShutil(unittest.TestCase):
'Need the tar command to run')
def test_tarfile_vs_tar(self):
tmpdir, tmpdir2, base_name = self._create_files()
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
_make_tarball(base_name, 'dist')
- finally:
- os.chdir(old_dir)
# check if the compressed tarball was created
tarball = base_name + '.tar.gz'
@@ -1039,14 +1025,10 @@ class TestShutil(unittest.TestCase):
tarball2 = os.path.join(tmpdir, 'archive2.tar.gz')
tar_cmd = ['tar', '-cf', 'archive2.tar', 'dist']
gzip_cmd = ['gzip', '-f9', 'archive2.tar']
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
with captured_stdout() as s:
spawn(tar_cmd)
spawn(gzip_cmd)
- finally:
- os.chdir(old_dir)
self.assertTrue(os.path.exists(tarball2))
# let's compare both tarballs
@@ -1054,23 +1036,15 @@ class TestShutil(unittest.TestCase):
# trying an uncompressed one
base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
_make_tarball(base_name, 'dist', compress=None)
- finally:
- os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
# now for a dry_run
base_name = os.path.join(tmpdir2, 'archive')
- old_dir = os.getcwd()
- os.chdir(tmpdir)
- try:
+ with support.change_cwd(tmpdir):
_make_tarball(base_name, 'dist', compress=None, dry_run=True)
- finally:
- os.chdir(old_dir)
tarball = base_name + '.tar'
self.assertTrue(os.path.exists(tarball))
@@ -1130,15 +1104,11 @@ class TestShutil(unittest.TestCase):
@unittest.skipUnless(UID_GID_SUPPORT, "Requires grp and pwd support")
def test_tarfile_root_owner(self):
tmpdir, tmpdir2, base_name = self._create_files()
- old_dir = os.getcwd()
- os.chdir(tmpdir)
group = grp.getgrgid(0)[0]
owner = pwd.getpwuid(0)[0]
- try:
+ with support.change_cwd(tmpdir):
archive_name = _make_tarball(base_name, 'dist', compress=None,
owner=owner, group=group)
- finally:
- os.chdir(old_dir)
# check if the compressed tarball was created
self.assertTrue(os.path.exists(archive_name))