diff options
author | Mats Wichmann <mats@linux.com> | 2019-02-14 19:42:00 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2019-02-14 22:13:16 (GMT) |
commit | 887f4a1b06ceed33ee6ba4c5589a32a607d6b001 (patch) | |
tree | 48de09819749eea0e8d134386892397809122769 /testing | |
parent | 334e11d04bb3be2f0ed93f929548e6cdc84c3158 (diff) | |
download | SCons-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 'testing')
-rw-r--r-- | testing/framework/TestSCons.py | 3 | ||||
-rw-r--r-- | testing/framework/TestSCons_time.py | 36 |
2 files changed, 32 insertions, 7 deletions
diff --git a/testing/framework/TestSCons.py b/testing/framework/TestSCons.py index 38ffd08..7fe48e8 100644 --- a/testing/framework/TestSCons.py +++ b/testing/framework/TestSCons.py @@ -920,7 +920,8 @@ for opt, arg in cmd_opts: else: opt_string = opt_string + ' ' + opt output.write("/* mymoc.py%s */\\n" % opt_string) for a in args: - contents = open(a, 'r').read() + with open(a, 'r') as f: + contents = f.read() a = a.replace('\\\\', '\\\\\\\\') subst = r'{ my_qt_symbol( "' + a + '\\\\n" ); }' if impl: diff --git a/testing/framework/TestSCons_time.py b/testing/framework/TestSCons_time.py index bc116ec..6299f51 100644 --- a/testing/framework/TestSCons_time.py +++ b/testing/framework/TestSCons_time.py @@ -24,8 +24,7 @@ from TestCommon import __all__ # some of the scons_time tests may need regex-based matching: from TestSCons import search_re, search_re_in_list -__all__.extend([ 'TestSCons_time', - ]) +__all__.extend(['TestSCons_time',]) SConstruct = """\ from __future__ import print_function @@ -37,25 +36,30 @@ scons_py = """\ #!/usr/bin/env python import os import sys + def write_args(fp, args): fp.write(args[0] + '\\n') for arg in args[1:]: fp.write(' ' + arg + '\\n') + write_args(sys.stdout, sys.argv) for arg in sys.argv[1:]: if arg[:10] == '--profile=': - profile = open(arg[10:], 'w') - profile.write('--profile\\n') - write_args(profile, sys.argv) + with open(arg[10:], 'w') as profile: + profile.write('--profile\\n') + write_args(profile, sys.argv) break sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + '\\n') -exec(open('SConstruct', 'r').read()) +with open('SConstruct', 'r') as f: + script = f.read() +exec(script) """ aegis_py = """\ #!/usr/bin/env python import os import sys + script_dir = 'src/script' if not os.path.exists(script_dir): os.makedirs(script_dir) @@ -68,6 +72,20 @@ svn_py = """\ #!/usr/bin/env python import os import sys + +dir = sys.argv[-1] +script_dir = dir + '/src/script' +os.makedirs(script_dir) +open(script_dir + '/scons.py', 'w').write( +r'''%s''') +""" % scons_py + + +git_py = """\ +#!/usr/bin/env python +import os +import sys + dir = sys.argv[-1] script_dir = dir + '/src/script' os.makedirs(script_dir) @@ -239,6 +257,12 @@ class TestSCons_time(TestCommon): os.chmod(name, 0o755) return name + def write_fake_git_py(self, name): + name = self.workpath(name) + self.write(name, git_py) + os.chmod(name, 0o755) + return name + def write_sample_directory(self, archive, dir, files): dir = self.workpath(dir) for name, content in files: |