From aee1868928e70bc6fdbd91649d596380646bf481 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Thu, 1 Jan 2015 11:03:18 -0500 Subject: Simplify script creation with context managers and leveraging local variables for the template population. --- setuptools/tests/test_windows_wrappers.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/setuptools/tests/test_windows_wrappers.py b/setuptools/tests/test_windows_wrappers.py index 91012917..92e9f882 100644 --- a/setuptools/tests/test_windows_wrappers.py +++ b/setuptools/tests/test_windows_wrappers.py @@ -37,20 +37,16 @@ class WrapperTester: """ sample_directory = tempdir - script = cls.script_tmpl % dict(python_exe=nt_quote_arg - (sys.executable)) + python_exe = nt_quote_arg(sys.executable) + script = cls.script_tmpl % locals() - f = open(os.path.join(sample_directory, cls.script_name), 'w') - f.write(script) - f.close() + with open(os.path.join(sample_directory, cls.script_name), 'w') as f: + f.write(script) # also copy cli.exe to the sample directory - - f = open(os.path.join(sample_directory, cls.wrapper_name), 'wb') - f.write( - pkg_resources.resource_string('setuptools', cls.wrapper_source) - ) - f.close() + with open(os.path.join(sample_directory, cls.wrapper_name), 'wb') as f: + w = pkg_resources.resource_string('setuptools', cls.wrapper_source) + f.write(w) class TestCLI(WrapperTester): -- cgit v1.2.3