summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2015-01-01 11:07:02 -0500
committerJason R. Coombs <jaraco@jaraco.com>2015-01-01 11:07:02 -0500
commit17f9e3abbd8b6ed2e1bb941f9f37659d9bf757f0 (patch)
tree85358589079d563d8c8e1631b49dd56160370858
parentaee1868928e70bc6fdbd91649d596380646bf481 (diff)
downloadpython-setuptools-git-17f9e3abbd8b6ed2e1bb941f9f37659d9bf757f0.tar.gz
More context managers
-rw-r--r--setuptools/tests/test_windows_wrappers.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/setuptools/tests/test_windows_wrappers.py b/setuptools/tests/test_windows_wrappers.py
index 92e9f882..29aa9c6d 100644
--- a/setuptools/tests/test_windows_wrappers.py
+++ b/setuptools/tests/test_windows_wrappers.py
@@ -112,8 +112,7 @@ class TestCLI(WrapperTester):
"""
sample_directory = str(tmpdir)
self.create_script(sample_directory)
- f = open(os.path.join(sample_directory, 'foo-script.py'), 'w')
- f.write(textwrap.dedent("""
+ tmpl = textwrap.dedent("""
#!%(python_exe)s -Oi
import sys
input = repr(sys.stdin.read())
@@ -123,8 +122,9 @@ class TestCLI(WrapperTester):
if __debug__:
print('non-optimized')
sys.ps1 = '---'
- """).lstrip() % dict(python_exe=nt_quote_arg(sys.executable)))
- f.close()
+ """).lstrip()
+ with open(os.path.join(sample_directory, 'foo-script.py'), 'w') as f:
+ f.write(tmpl % dict(python_exe=nt_quote_arg(sys.executable)))
cmd = [os.path.join(sample_directory, 'foo.exe')]
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout, stderr = proc.communicate()
@@ -169,6 +169,6 @@ class TestGUI(WrapperTester):
stdout, stderr = proc.communicate()
assert not stdout
assert not stderr
- f_out = open(os.path.join(sample_directory, 'test_output.txt'), 'rb')
- assert f_out.read().decode('ascii') == repr('Test Argument')
- f_out.close()
+ with open(os.path.join(sample_directory, 'test_output.txt'), 'rb') as f_out:
+ actual = f_out.read().decode('ascii')
+ assert actual == repr('Test Argument')