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/Alias | |
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/Alias')
-rw-r--r-- | test/Alias/Alias.py | 3 | ||||
-rw-r--r-- | test/Alias/Depends.py | 3 | ||||
-rw-r--r-- | test/Alias/action.py | 14 | ||||
-rw-r--r-- | test/Alias/scanner.py | 8 | ||||
-rw-r--r-- | test/Alias/srcdir.py | 26 |
5 files changed, 30 insertions, 24 deletions
diff --git a/test/Alias/Alias.py b/test/Alias/Alias.py index a5dd903..c371625 100644 --- a/test/Alias/Alias.py +++ b/test/Alias/Alias.py @@ -37,7 +37,8 @@ test.subdir('sub1', 'sub2') test.write('build.py', r""" import sys -open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read()) +with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp: + f.write(ifp.read()) sys.exit(0) """) diff --git a/test/Alias/Depends.py b/test/Alias/Depends.py index a1129e4..715374c 100644 --- a/test/Alias/Depends.py +++ b/test/Alias/Depends.py @@ -37,7 +37,8 @@ test.subdir('sub1', 'sub2') test.write('build.py', r""" import sys -open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read()) +with open(sys.argv[1], 'wb') as f, open(sys.argv[2], 'rb') as ifp: + f.write(ifp.read()) sys.exit(0) """) diff --git a/test/Alias/action.py b/test/Alias/action.py index 2a10dbc..def27a7 100644 --- a/test/Alias/action.py +++ b/test/Alias/action.py @@ -35,20 +35,22 @@ test = TestSCons.TestSCons() test.write('SConstruct', """ def cat(target, source, env): target = str(target[0]) - f = open(target, "wb") - for src in source: - f.write(open(str(src), "rb").read()) - f.close() + with open(target, "wb") as f: + for src in source: + with open(str(src), "rb") as ifp: + f.write(ifp.read()) def foo(target, source, env): target = list(map(str, target)) source = list(map(str, source)) - open('foo', 'wb').write(bytearray("foo(%s, %s)\\n" % (target, source),'utf-8')) + with open('foo', 'wb') as f: + f.write(bytearray("foo(%s, %s)\\n" % (target, source),'utf-8')) def bar(target, source, env): target = list(map(str, target)) source = list(map(str, source)) - open('bar', 'wb').write(bytearray("bar(%s, %s)\\n" % (target, source),'utf-8')) + with open('bar', 'wb') as f: + f.write(bytearray("bar(%s, %s)\\n" % (target, source),'utf-8')) env = Environment(BUILDERS = {'Cat':Builder(action=cat)}) env.Alias(target = ['build-f1'], source = 'f1.out', action = foo) diff --git a/test/Alias/scanner.py b/test/Alias/scanner.py index d20a729..a6ded81 100644 --- a/test/Alias/scanner.py +++ b/test/Alias/scanner.py @@ -35,10 +35,10 @@ test = TestSCons.TestSCons() test.write('SConstruct', """ def cat(env, source, target): target = str(target[0]) - f = open(target, "wb") - for src in source: - f.write(open(str(src), "rb").read()) - f.close() + with open(target, "wb") as f: + for src in source: + with open(str(src), "rb") as ifp: + f.write(ifp.read()) XBuilder = Builder(action = cat, src_suffix = '.x', suffix = '.c') env = Environment() diff --git a/test/Alias/srcdir.py b/test/Alias/srcdir.py index 4a0de43..977d114 100644 --- a/test/Alias/srcdir.py +++ b/test/Alias/srcdir.py @@ -63,21 +63,23 @@ test.subdir('python') test.write('SConstruct', """\ import os.path -env = Environment () +env = Environment() -def at_copy_ext (target, source, env): - n = str (source[0]) - s = open (n, 'rb').read () - e = os.path.splitext (n)[1] - t = str (target[0]) + e - open (t, 'wb').write (s) +def at_copy_ext(target, source, env): + n = str(source[0]) + with open(n, 'rb') as f: + s = f.read() + e = os.path.splitext(n)[1] + t = str(target[0]) + e + with open(t, 'wb') as f: + f.write(s) -AT_COPY_EXT = Builder (action = at_copy_ext, src_suffix=['.py', '.sh',]) -env.Append (BUILDERS = {'AT_COPY_EXT': AT_COPY_EXT}) +AT_COPY_EXT = Builder(action=at_copy_ext, src_suffix=['.py', '.sh',]) +env.Append(BUILDERS={'AT_COPY_EXT': AT_COPY_EXT}) -env.Alias ('minimal', ['python']) +env.Alias('minimal', ['python']) -Export ('env') +Export('env') b = 'python/out-scons' @@ -87,7 +89,7 @@ SConscript(b + '/SConscript') """) test.write(['python', 'SConscript'], """\ -Import ('env') +Import('env') env.AT_COPY_EXT('foo.py') """) |