summaryrefslogtreecommitdiff
path: root/setuptools/tests/test_easy_install.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2014-12-30 09:51:57 -0500
committerJason R. Coombs <jaraco@jaraco.com>2014-12-30 09:51:57 -0500
commit470028e10ea01e57ece6df3c953a309e0017d068 (patch)
treefadc560af22acb7fcc40a3fc0b3322aa868215f8 /setuptools/tests/test_easy_install.py
parent292d4db0eb5c7591eed972ed9085362167816de0 (diff)
downloadpython-setuptools-git-470028e10ea01e57ece6df3c953a309e0017d068.tar.gz
Rewrite file operations using context managers.
Diffstat (limited to 'setuptools/tests/test_easy_install.py')
-rw-r--r--setuptools/tests/test_easy_install.py26
1 files changed, 9 insertions, 17 deletions
diff --git a/setuptools/tests/test_easy_install.py b/setuptools/tests/test_easy_install.py
index a8f274d5..0bb4c22f 100644
--- a/setuptools/tests/test_easy_install.py
+++ b/setuptools/tests/test_easy_install.py
@@ -128,9 +128,8 @@ class TestUserInstallTest(unittest.TestCase):
def setUp(self):
self.dir = tempfile.mkdtemp()
setup = os.path.join(self.dir, 'setup.py')
- f = open(setup, 'w')
- f.write(SETUP_PY)
- f.close()
+ with open(setup, 'w') as f:
+ f.write(SETUP_PY)
self.old_cwd = os.getcwd()
os.chdir(self.dir)
@@ -191,11 +190,8 @@ class TestUserInstallTest(unittest.TestCase):
new_location = tempfile.mkdtemp()
target = tempfile.mkdtemp()
egg_file = os.path.join(new_location, 'foo-1.0.egg-info')
- f = open(egg_file, 'w')
- try:
+ with open(egg_file, 'w') as f:
f.write('Name: foo\n')
- finally:
- f.close()
sys.path.append(target)
old_ppath = os.environ.get('PYTHONPATH')
@@ -358,12 +354,11 @@ def create_setup_requires_package(path):
test_setup_py = os.path.join(test_pkg, 'setup.py')
os.mkdir(test_pkg)
- f = open(test_setup_py, 'w')
- f.write(textwrap.dedent("""\
- import setuptools
- setuptools.setup(**%r)
- """ % test_setup_attrs))
- f.close()
+ with open(test_setup_py, 'w') as f:
+ f.write(textwrap.dedent("""\
+ import setuptools
+ setuptools.setup(**%r)
+ """ % test_setup_attrs))
foobar_path = os.path.join(path, 'foobar-0.1.tar.gz')
make_trivial_sdist(
@@ -392,11 +387,8 @@ def make_trivial_sdist(dist_path, setup_py):
MemFile = StringIO
setup_py_bytes = MemFile(setup_py.encode('utf-8'))
setup_py_file.size = len(setup_py_bytes.getvalue())
- dist = tarfile.open(dist_path, 'w:gz')
- try:
+ with tarfile.open(dist_path, 'w:gz') as dist:
dist.addfile(setup_py_file, fileobj=setup_py_bytes)
- finally:
- dist.close()
@contextlib.contextmanager