summaryrefslogtreecommitdiffstats
path: root/test/Repository
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2019-03-31 13:01:00 (GMT)
committerMats Wichmann <mats@linux.com>2019-04-25 15:37:04 (GMT)
commitf61d3bcd112285644c1a6ce253b267ef690a7e06 (patch)
tree2e489e238c11697f602cb9a7cbeb43afed088734 /test/Repository
parentb0c3385604ebc1d7d552472f1cc6d0910aafa32a (diff)
downloadSCons-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/Repository')
-rw-r--r--test/Repository/Default.py3
-rw-r--r--test/Repository/LIBPATH.py15
-rw-r--r--test/Repository/Local.py4
-rw-r--r--test/Repository/SConscript.py18
-rw-r--r--test/Repository/VariantDir.py8
-rw-r--r--test/Repository/option-c.py4
-rw-r--r--test/Repository/option-f.py8
-rw-r--r--test/Repository/option-n.py3
-rw-r--r--test/Repository/targets.py8
9 files changed, 37 insertions, 34 deletions
diff --git a/test/Repository/Default.py b/test/Repository/Default.py
index bd9d5f8..e33a26e 100644
--- a/test/Repository/Default.py
+++ b/test/Repository/Default.py
@@ -47,7 +47,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- open(target, "w").write(open(source, "r").read())
+ with open(target, "w") as ofp, open(source, "r") as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/LIBPATH.py b/test/Repository/LIBPATH.py
index 8b396fa..646b5d7 100644
--- a/test/Repository/LIBPATH.py
+++ b/test/Repository/LIBPATH.py
@@ -46,14 +46,13 @@ bbb_exe = env_yyy.Program('bbb', 'bbb.c')
def write_LIBDIRFLAGS(env, target, source):
pre = env.subst('$LIBDIRPREFIX')
suf = env.subst('$LIBDIRSUFFIX')
- f = open(str(target[0]), 'w')
- for arg in env.subst('$_LIBDIRFLAGS', target=target).split():
- if arg[:len(pre)] == pre:
- arg = arg[len(pre):]
- if arg[-len(suf):] == suf:
- arg = arg[:-len(pre)]
- f.write(arg + '\n')
- f.close()
+ with open(str(target[0]), 'w') as f:
+ for arg in env.subst('$_LIBDIRFLAGS', target=target).split():
+ if arg[:len(pre)] == pre:
+ arg = arg[len(pre):]
+ if arg[-len(suf):] == suf:
+ arg = arg[:-len(pre)]
+ f.write(arg + '\n')
return 0
env_zzz.Command('zzz.out', aaa_exe, write_LIBDIRFLAGS)
env_yyy.Command('yyy.out', bbb_exe, write_LIBDIRFLAGS)
diff --git a/test/Repository/Local.py b/test/Repository/Local.py
index 7062075..a906245 100644
--- a/test/Repository/Local.py
+++ b/test/Repository/Local.py
@@ -49,8 +49,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- with open(target, 'w') as fo, open(source, 'r') as fi:
- fo.write(fi.read())
+ with open(target, 'w') as ofp, open(source, 'r') as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build}, BBB='bbb')
diff --git a/test/Repository/SConscript.py b/test/Repository/SConscript.py
index 1b67c07..1482800 100644
--- a/test/Repository/SConscript.py
+++ b/test/Repository/SConscript.py
@@ -61,10 +61,11 @@ SConscript('src/SConscript')
test.write(['rep1', 'src', 'SConscript'], """\
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, "w") as ofp:
+ for src in source:
+ with open(str(src), "r") as ifp:
+ ofp.write(ifp.read())
+
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
""")
@@ -97,10 +98,11 @@ SConscript('src/SConscript')
test.write(['rep2', 'src', 'SConscript'], """\
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, "w") as ofp:
+ for src in source:
+ with open(str(src), "r") as ifp:
+ ofp.write(ifp.read())
+
env = Environment(BUILDERS={'Cat':Builder(action=cat)})
env.Cat(target = 'foo', source = ['aaa.in', 'bbb.in', 'ccc.in'])
SConscript('sub/SConscript')
diff --git a/test/Repository/VariantDir.py b/test/Repository/VariantDir.py
index 8887f86..327e550 100644
--- a/test/Repository/VariantDir.py
+++ b/test/Repository/VariantDir.py
@@ -49,10 +49,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "w")
- for src in source:
- f.write(open(src, "r").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(src, "r") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.mid', 'aaa.in')
diff --git a/test/Repository/option-c.py b/test/Repository/option-c.py
index 58c4876..a73bcf7 100644
--- a/test/Repository/option-c.py
+++ b/test/Repository/option-c.py
@@ -66,8 +66,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- with open(target, 'w') as fo, open(source, 'r') as fi:
- fo.write(fi.read())
+ with open(target, 'w') as ofp, open(source, 'r') as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/option-f.py b/test/Repository/option-f.py
index c990f2f..f1b2cc6 100644
--- a/test/Repository/option-f.py
+++ b/test/Repository/option-f.py
@@ -43,10 +43,10 @@ test.write(['repository', 'SConstruct'], """\
Repository(r'%s')
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(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')
diff --git a/test/Repository/option-n.py b/test/Repository/option-n.py
index d23a200..d99e92a 100644
--- a/test/Repository/option-n.py
+++ b/test/Repository/option-n.py
@@ -49,7 +49,8 @@ def copy(env, source, target):
source = str(source[0])
target = str(target[0])
print('copy() < %s > %s' % (source, target))
- open(target, "w").write(open(source, "r").read())
+ with open(target, "w") as ofp, open(source, "r") as ifp:
+ ofp.write(ifp.read())
Build = Builder(action=copy)
env = Environment(BUILDERS={'Build':Build})
diff --git a/test/Repository/targets.py b/test/Repository/targets.py
index 0bc625a..5899c57 100644
--- a/test/Repository/targets.py
+++ b/test/Repository/targets.py
@@ -44,10 +44,10 @@ def cat(env, source, target):
target = str(target[0])
source = list(map(str, source))
print('cat(%s) > %s' % (source, target))
- f = open(target, "w")
- for src in source:
- f.write(open(src, "r").read())
- f.close()
+ with open(target, "w") as ofp:
+ for src in source:
+ with open(src, "r") as ifp:
+ ofp.write(ifp.read())
env = Environment(BUILDERS={'Build':Builder(action=cat)})
env.Build('aaa.out', 'aaa.in')