summaryrefslogtreecommitdiffstats
path: root/testing
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2019-03-05 14:30:30 (GMT)
committerMats Wichmann <mats@linux.com>2019-03-05 14:41:09 (GMT)
commit674ebaca7eef1706549e2d3ddbe563cb2f3864c6 (patch)
tree5d0b067cfcd7e3aaad100f1cd0baa2dcb7f0b957 /testing
parent96380855bb73cd6b061d067b0059fbbb6573e020 (diff)
downloadSCons-674ebaca7eef1706549e2d3ddbe563cb2f3864c6.zip
SCons-674ebaca7eef1706549e2d3ddbe563cb2f3864c6.tar.gz
SCons-674ebaca7eef1706549e2d3ddbe563cb2f3864c6.tar.bz2
[PYPY] [PY 3.8] add context mgr use in scons-time
To fix some test problems for pypy, which seem more prone to problems of lost data if files are written and not explicitly closed, add context managers on file opens in scons-time. Also quiets warnings which are emitted by the much noisier Python 3.8. Changes are to the scons-time script and to the framework. After visual inspection of outputs while debugging, switched the framework's created tools in the scons-time area to use os.linesep instead of explicit '\\n' strings, tools should operate in a native way. Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'testing')
-rw-r--r--testing/framework/TestSCons_time.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/testing/framework/TestSCons_time.py b/testing/framework/TestSCons_time.py
index 8260bef..e37d269 100644
--- a/testing/framework/TestSCons_time.py
+++ b/testing/framework/TestSCons_time.py
@@ -38,18 +38,18 @@ import os
import sys
def write_args(fp, args):
- fp.write(args[0] + '\\n')
+ fp.write(args[0] + os.linesep)
for arg in args[1:]:
- fp.write(' ' + arg + '\\n')
+ fp.write(' ' + arg + os.linesep)
write_args(sys.stdout, sys.argv)
for arg in sys.argv[1:]:
if arg[:10] == '--profile=':
with open(arg[10:], 'w') as profile:
- profile.write('--profile\\n')
+ profile.write('--profile' + os.linesep)
write_args(profile, sys.argv)
break
-sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + '\\n')
+sys.stdout.write('SCONS_LIB_DIR = ' + os.environ['SCONS_LIB_DIR'] + os.linesep)
with open('SConstruct', 'r') as f:
script = f.read()
exec(script)
@@ -63,8 +63,8 @@ import sys
script_dir = 'src/script'
if not os.path.exists(script_dir):
os.makedirs(script_dir)
-open(script_dir + '/scons.py', 'w').write(
-r'''%s''')
+with open(script_dir + '/scons.py', 'w') as f:
+ f.write(r'''%s''')
""" % scons_py
@@ -76,8 +76,8 @@ import sys
dir = sys.argv[-1]
script_dir = dir + '/src/script'
os.makedirs(script_dir)
-open(script_dir + '/scons.py', 'w').write(
-r'''%s''')
+with open(script_dir + '/scons.py', 'w') as f:
+ f.write(r'''%s''')
""" % scons_py
@@ -89,8 +89,8 @@ import sys
dir = sys.argv[-1]
script_dir = dir + '/src/script'
os.makedirs(script_dir)
-open(script_dir + '/scons.py', 'w').write(
-r'''%s''')
+with open(script_dir + '/scons.py', 'w') as f:
+ f.write(r'''%s''')
""" % scons_py
@@ -297,13 +297,15 @@ class TestSCons_time(TestCommon):
tar = tarfile.open(archive, mode[suffix])
for name, content in files:
path = os.path.join(dir, name)
- open(path, 'wb').write(bytearray(content,'utf-8'))
+ with open(path, 'wb') as f:
+ f.write(bytearray(content,'utf-8'))
tarinfo = tar.gettarinfo(path, path)
tarinfo.uid = 111
tarinfo.gid = 111
tarinfo.uname = 'fake_user'
tarinfo.gname = 'fake_group'
- tar.addfile(tarinfo, open(path, 'rb'))
+ with open(path, 'rb') as f:
+ tar.addfile(tarinfo, f)
tar.close()
shutil.rmtree(dir)
return self.workpath(archive)
@@ -322,7 +324,8 @@ class TestSCons_time(TestCommon):
zip = zipfile.ZipFile(archive, 'w')
for name, content in files:
path = os.path.join(dir, name)
- open(path, 'w').write(content)
+ with open(path, 'w') as f:
+ f.write(content)
zip.write(path)
zip.close()
shutil.rmtree(dir)