diff options
author | Mats Wichmann <mats@linux.com> | 2019-03-31 13:01:00 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2019-04-25 15:37:04 (GMT) |
commit | f61d3bcd112285644c1a6ce253b267ef690a7e06 (patch) | |
tree | 2e489e238c11697f602cb9a7cbeb43afed088734 /test/Fortran | |
parent | b0c3385604ebc1d7d552472f1cc6d0910aafa32a (diff) | |
download | SCons-f61d3bcd112285644c1a6ce253b267ef690a7e06.zip SCons-f61d3bcd112285644c1a6ce253b267ef690a7e06.tar.gz SCons-f61d3bcd112285644c1a6ce253b267ef690a7e06.tar.bz2 |
[PY 3.8] test fixes for file closings, rawstrings
On a linux host (missing some things that may be on the Travis CI
setup), Py3.8a3 now shows 19 fails, 1048 pass, with 84 Warning: messages.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'test/Fortran')
-rw-r--r-- | test/Fortran/FORTRANMODDIR.py | 6 | ||||
-rw-r--r-- | test/Fortran/FORTRANSUFFIXES.py | 17 | ||||
-rw-r--r-- | test/Fortran/USE-MODULE.py | 6 | ||||
-rw-r--r-- | test/Fortran/link-with-cxx.py | 23 | ||||
-rw-r--r-- | test/Fortran/module-subdir.py | 24 |
5 files changed, 41 insertions, 35 deletions
diff --git a/test/Fortran/FORTRANMODDIR.py b/test/Fortran/FORTRANMODDIR.py index 61dcc45..a0e03af 100644 --- a/test/Fortran/FORTRANMODDIR.py +++ b/test/Fortran/FORTRANMODDIR.py @@ -47,14 +47,16 @@ import re import sys # case insensitive matching, because Fortran is case insensitive mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)" -contents = open(sys.argv[2]).read() +with open(sys.argv[2]) as f: + contents = f.read() modules = re.findall(mod_regex, contents) (prefix, moddir) = sys.argv[1].split('=') if prefix != 'moduledir': sys.exit(1) modules = [os.path.join(moddir, m.lower()+'.mod') for m in modules] for t in sys.argv[3:] + modules: - open(t, 'wb').write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode()) + with open(t, 'wb') as f: + f.write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode()) """) test.write('SConstruct', """ diff --git a/test/Fortran/FORTRANSUFFIXES.py b/test/Fortran/FORTRANSUFFIXES.py index c1b3455..b703c60 100644 --- a/test/Fortran/FORTRANSUFFIXES.py +++ b/test/Fortran/FORTRANSUFFIXES.py @@ -37,14 +37,15 @@ test = TestSCons.TestSCons() test.write('myfc.py', r""" import sys def do_file(outf, inf): - for line in open(inf, 'rb').readlines(): - if line[:15] == b" INCLUDE '": - do_file(outf, line[15:-2]) - else: - outf.write(line) -outf = open(sys.argv[1], 'wb') -for f in sys.argv[2:]: - do_file(outf, f) + with open(inf, 'rb') as inf: + for line in inf.readlines(): + if line[:15] == b" INCLUDE '": + do_file(outf, line[15:-2]) + else: + outf.write(line) +with open(sys.argv[1], 'wb') as outf: + for f in sys.argv[2:]: + do_file(outf, f) sys.exit(0) """) diff --git a/test/Fortran/USE-MODULE.py b/test/Fortran/USE-MODULE.py index 0d78e7a..ab76f3d 100644 --- a/test/Fortran/USE-MODULE.py +++ b/test/Fortran/USE-MODULE.py @@ -38,11 +38,13 @@ import os.path import re import sys mod_regex = "(?im)^\\s*MODULE\\s+(?!PROCEDURE)(\\w+)" -contents = open(sys.argv[1]).read() +with open(sys.argv[1]) as f: + contents = f.read() modules = re.findall(mod_regex, contents) modules = [m.lower()+'.mod' for m in modules] for t in sys.argv[2:] + modules: - open(t, 'wb').write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode()) + with open(t, 'wb') as f: + f.write(('myfortran.py wrote %s\n' % os.path.split(t)[1]).encode()) sys.exit(0) """) diff --git a/test/Fortran/link-with-cxx.py b/test/Fortran/link-with-cxx.py index bf10fc8..f559b0a 100644 --- a/test/Fortran/link-with-cxx.py +++ b/test/Fortran/link-with-cxx.py @@ -42,25 +42,25 @@ test = TestSCons.TestSCons(match = TestSCons.match_re) test.write('test_linker.py', r""" import sys if sys.argv[1] == '-o': - outfile = open(sys.argv[2], 'wb') + ofp = open(sys.argv[2], 'wb') infiles = sys.argv[3:] elif sys.argv[1][:5] == '/OUT:': - outfile = open(sys.argv[1][5:], 'wb') + ofp = open(sys.argv[1][5:], 'wb') infiles = sys.argv[2:] for infile in infiles: - with open(infile, 'rb') as f: - outfile.write(f.read()) -outfile.close() + with open(infile, 'rb') as ifp: + ofp.write(ifp.read()) +ofp.close() sys.exit(0) """) test.write('test_fortran.py', r""" import sys -outfile = open(sys.argv[2], 'wb') -for infile in sys.argv[4:]: - outfile.write(open(infile, 'rb').read()) -outfile.close() +with open(sys.argv[2], 'wb') as ofp: + for infile in sys.argv[4:]: + with open(infile, 'rb') as ifp: + ofp.write(ifp.read()) sys.exit(0) """) @@ -70,8 +70,9 @@ import SCons.Tool.link def copier(target, source, env): s = str(source[0]) t = str(target[0]) - with open(t, 'wb') as fo, open(s, 'rb') as fi: - fo.write(fi.read()) + with open(t, 'wb') as ofp, open(s, 'rb') as ifp: + ofp.write(ifp.read()) + env = Environment(CXX = r'%(_python_)s test_linker.py', CXXCOM = Action(copier), SMARTLINK = SCons.Tool.link.smart_link, diff --git a/test/Fortran/module-subdir.py b/test/Fortran/module-subdir.py index 6224d44..0b87aa2 100644 --- a/test/Fortran/module-subdir.py +++ b/test/Fortran/module-subdir.py @@ -52,23 +52,23 @@ for opt, arg in opts: if opt == '-o': out = arg elif opt == '-M': modsubdir = arg import os -infile = open(args[0], 'rb') -outfile = open(out, 'wb') -for l in infile.readlines(): - if l[:7] == b'module ': - module = modsubdir + os.sep + l[7:-1].decode() + '.mod' - open(module, 'wb').write(('myfortran.py wrote %s\n' % module).encode()) - if l[:length] != comment: - outfile.write(l) +with open(out, 'wb') as ofp, open(args[0], 'rb') as ifp: + for l in ifp.readlines(): + if l[:7] == b'module ': + module = modsubdir + os.sep + l[7:-1].decode() + '.mod' + with open(module, 'wb') as f: + f.write(('myfortran.py wrote %s\n' % module).encode()) + if l[:length] != comment: + ofp.write(l) sys.exit(0) """) test.write('myar.py', """\ import sys -t = open(sys.argv[1], 'wb') -for s in sys.argv[2:]: - t.write(open(s, 'rb').read()) -t.close +with open(sys.argv[1], 'wb') as ofp: + for s in sys.argv[2:]: + with open(s, 'rb') as ifp: + ofp.write(ifp.read()) sys.exit(0) """) |