summaryrefslogtreecommitdiffstats
path: root/src/engine/SCons/ActionTests.py
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2019-02-14 19:42:00 (GMT)
committerMats Wichmann <mats@linux.com>2019-02-14 22:13:16 (GMT)
commit887f4a1b06ceed33ee6ba4c5589a32a607d6b001 (patch)
tree48de09819749eea0e8d134386892397809122769 /src/engine/SCons/ActionTests.py
parent334e11d04bb3be2f0ed93f929548e6cdc84c3158 (diff)
downloadSCons-887f4a1b06ceed33ee6ba4c5589a32a607d6b001.zip
SCons-887f4a1b06ceed33ee6ba4c5589a32a607d6b001.tar.gz
SCons-887f4a1b06ceed33ee6ba4c5589a32a607d6b001.tar.bz2
Clean up some tests: use context managers
Plenty of complaints coming from Python 3.8alpha on unclosed files. Targeted those areas which intersect with PyPy failures - this changeset reduces the PyPy fails by 17 on the local test environment. So this affects both Issue #3299 and the PyPy support project. Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'src/engine/SCons/ActionTests.py')
-rw-r--r--src/engine/SCons/ActionTests.py25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py
index 3e83b50..efe6e98 100644
--- a/src/engine/SCons/ActionTests.py
+++ b/src/engine/SCons/ActionTests.py
@@ -62,25 +62,28 @@ test = TestCmd.TestCmd(workdir='')
test.write('act.py', """\
import os, string, sys
-f = open(sys.argv[1], 'w')
-f.write("act.py: '" + "' '".join(sys.argv[2:]) + "'\\n")
-try:
- if sys.argv[3]:
- f.write("act.py: '" + os.environ[sys.argv[3]] + "'\\n")
-except:
- pass
-f.close()
+
+with open(sys.argv[1], 'w') as f:
+ f.write("act.py: '" + "' '".join(sys.argv[2:]) + "'\\n")
+ try:
+ if sys.argv[3]:
+ f.write("act.py: '" + os.environ[sys.argv[3]] + "'\\n")
+ except:
+ pass
+
if 'ACTPY_PIPE' in os.environ:
if 'PIPE_STDOUT_FILE' in os.environ:
- stdout_msg = open(os.environ['PIPE_STDOUT_FILE'], 'r').read()
+ with open(os.environ['PIPE_STDOUT_FILE'], 'r') as f:
+ stdout_msg = f.read()
else:
stdout_msg = "act.py: stdout: executed act.py %s\\n" % ' '.join(sys.argv[1:])
sys.stdout.write( stdout_msg )
if 'PIPE_STDERR_FILE' in os.environ:
- stderr_msg = open(os.environ['PIPE_STDERR_FILE'], 'r').read()
+ with open(os.environ['PIPE_STDERR_FILE'], 'r') as f:
+ stderr_msg = f.read()
else:
stderr_msg = "act.py: stderr: executed act.py %s\\n" % ' '.join(sys.argv[1:])
- sys.stderr.write( stderr_msg )
+ sys.stderr.write(stderr_msg)
sys.exit(0)
""")