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/Install | |
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/Install')
-rw-r--r-- | test/Install/Install.py | 34 | ||||
-rw-r--r-- | test/Install/wrap-by-attribute.py | 8 |
2 files changed, 20 insertions, 22 deletions
diff --git a/test/Install/Install.py b/test/Install/Install.py index da97d2a..0647002 100644 --- a/test/Install/Install.py +++ b/test/Install/Install.py @@ -51,15 +51,16 @@ test.write(['work', 'SConstruct'], """\ DefaultEnvironment(tools=[]) def cat(env, source, target): target = str(target[0]) - f = open(target, "w") - for src in source: - f.write(open(str(src), "r").read()) - f.close() + with open(target, 'wb') as ofp: + for src in source: + with open(str(src), 'rb') as ifp: + ofp.write(ifp.read()) def my_install(dest, source, env): import shutil shutil.copy2(source, dest) - open('my_install.out', 'a').write(dest) + with open('my_install.out', 'a') as f: + f.write(dest) env1 = Environment(tools=[]) env1.Append(BUILDERS={'Cat':Builder(action=cat)}) @@ -123,7 +124,8 @@ test.fail_test(oldtime1 == os.path.getmtime(f1_out)) test.fail_test(oldtime2 != os.path.getmtime(f2_out)) # Verify that we didn't link to the Installed file. -open(f2_out, 'w').write("xyzzy\n") +with open(f2_out, 'w') as f: + f.write("xyzzy\n") test.must_match(['work', 'f2.out'], "f2.in\n", mode='r') # Verify that scons prints an error message @@ -131,20 +133,16 @@ test.must_match(['work', 'f2.out'], "f2.in\n", mode='r') test.write(['work', 'f1.in'], "f1.in again again\n") os.chmod(test.workpath('work', 'export'), 0o555) -f = open(f1_out, 'rb') +with open(f1_out, 'rb'): + expect = [ + "Permission denied", + "The process cannot access the file because it is being used by another process", + "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird", + ] + test.run(chdir='work', arguments=f1_out, stderr=None, status=2) -expect = [ - "Permission denied", - "The process cannot access the file because it is being used by another process", - "Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird", -] - -test.run(chdir = 'work', arguments = f1_out, stderr=None, status=2) - -test.must_contain_any_line(test.stderr(), expect) - -f.close() + test.must_contain_any_line(test.stderr(), expect) test.pass_test() diff --git a/test/Install/wrap-by-attribute.py b/test/Install/wrap-by-attribute.py index 6989fa8..014b7a5 100644 --- a/test/Install/wrap-by-attribute.py +++ b/test/Install/wrap-by-attribute.py @@ -47,10 +47,10 @@ import os.path 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 ofp: + for src in source: + with open(str(src), 'rb') as ifp: + ofp.write(ifp.read()) env = Environment(tools=[], DESTDIR='dest') env.Append(BUILDERS={'Cat':Builder(action=cat)}) |