Use context manager in test cases.

pull/716/head
Elliott Sales de Andrade 9 years ago
parent 181d9a891d
commit aec1e88c21
  1. 12
      run_tests.py
  2. 15
      test cases/common/103 manygen/subdir/manygen.py
  3. 9
      test cases/common/107 postconf/postconf.py
  4. 9
      test cases/common/108 postconf with args/postconf.py
  5. 3
      test cases/common/113 generatorcustom/catter.py
  6. 6
      test cases/common/113 generatorcustom/gen.py
  7. 3
      test cases/common/117 custom target capture/my_compiler.py
  8. 8
      test cases/common/16 configure file/generator.py
  9. 5
      test cases/common/48 test args/tester.py
  10. 6
      test cases/common/56 custom target/depfile/dep.py
  11. 7
      test cases/common/56 custom target/my_compiler.py
  12. 7
      test cases/common/57 custom target chain/my_compiler.py
  13. 7
      test cases/common/57 custom target chain/my_compiler2.py
  14. 4
      test cases/common/57 custom target chain/usetarget/subcomp.py
  15. 3
      test cases/common/58 run target/converter.py
  16. 3
      test cases/common/58 run target/fakeburner.py
  17. 6
      test cases/common/61 custom target source output/generator.py
  18. 6
      test cases/common/64 custom header generator/makeheader.py
  19. 9
      test cases/common/65 multiple generators/mygen.py
  20. 9
      test cases/common/72 build always/version_gen.py
  21. 9
      test cases/common/76 configure file in custom target/src/mycompiler.py
  22. 6
      test cases/common/78 ctarget dependency/gen1.py
  23. 3
      test cases/common/78 ctarget dependency/gen2.py
  24. 6
      test cases/common/93 private include/stlib/compiler.py
  25. 6
      test cases/common/98 gen extra/srcgen.py

@ -156,8 +156,9 @@ def validate_install(srcdir, installdir):
if os.path.exists(os.path.join(installdir, noinst_file)):
expected[noinst_file] = False
elif os.path.exists(info_file):
for line in open(info_file):
expected[platform_fix_exe_name(line.strip())] = False
with open(info_file) as f:
for line in f:
expected[platform_fix_exe_name(line.strip())] = False
# Check if expected files were found
for fname in expected:
if os.path.exists(os.path.join(installdir, fname)):
@ -249,7 +250,8 @@ def _run_test(testdir, test_build_dir, install_dir, extra_args, flags, compile_c
(returncode, stdo, stde) = run_configure_inprocess(gen_command)
try:
logfile = os.path.join(test_build_dir, 'meson-logs/meson-log.txt')
mesonlog = open(logfile, errors='ignore').read()
with open(logfile, errors='ignore') as f:
mesonlog = f.read()
except Exception:
mesonlog = 'No meson-log.txt found.'
gen_time = time.time() - gen_start
@ -401,7 +403,9 @@ def run_tests(extra_args):
def check_file(fname):
linenum = 1
for line in open(fname, 'rb').readlines():
with open(fname, 'rb') as f:
lines = f.readlines()
for line in lines:
if b'\t' in line:
print("File %s contains a literal tab on line %d. Only spaces are permitted." % (fname, linenum))
sys.exit(1)

@ -6,7 +6,8 @@
import sys, os
import shutil, subprocess
funcname = open(sys.argv[1]).readline().strip()
with open(sys.argv[1]) as f:
funcname = f.readline().strip()
outdir = sys.argv[2]
if not os.path.isdir(outdir):
@ -44,19 +45,22 @@ outc = os.path.join(outdir, funcname + '.c')
tmpc = 'diibadaaba.c'
tmpo = 'diibadaaba' + objsuffix
open(outc, 'w').write('''#include"%s.h"
with open(outc, 'w') as f:
f.write('''#include"%s.h"
int %s_in_src() {
return 0;
}
''' % (funcname, funcname))
open(outh, 'w').write('''#pragma once
with open(outh, 'w') as f:
f.write('''#pragma once
int %s_in_lib();
int %s_in_obj();
int %s_in_src();
''' % (funcname, funcname, funcname))
open(tmpc, 'w').write('''int %s_in_obj() {
with open(tmpc, 'w') as f:
f.write('''int %s_in_obj() {
return 0;
}
''' % funcname)
@ -66,7 +70,8 @@ if is_vs:
else:
subprocess.check_call([compiler, '-c', '-o', outo, tmpc])
open(tmpc, 'w').write('''int %s_in_lib() {
with open(tmpc, 'w') as f:
f.write('''int %s_in_lib() {
return 0;
}
''' % funcname)

@ -7,5 +7,10 @@ template = '''#pragma once
#define THE_NUMBER {}
'''
data = open(os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')).readline().strip()
open(os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h'), 'w').write(template.format(data))
input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
f.write(template.format(data))

@ -9,5 +9,10 @@ template = '''#pragma once
#define THE_ARG2 {}
'''
data = open(os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')).readline().strip()
open(os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h'), 'w').write(template.format(data, sys.argv[1], sys.argv[2]))
input_file = os.path.join(os.environ['MESON_SOURCE_ROOT'], 'raw.dat')
output_file = os.path.join(os.environ['MESON_BUILD_ROOT'], 'generated.h')
with open(input_file) as f:
data = f.readline().strip()
with open(output_file, 'w') as f:
f.write(template.format(data, sys.argv[1], sys.argv[2]))

@ -8,6 +8,7 @@ inputs = sys.argv[1:-1]
with open(output, 'w') as ofile:
ofile.write('#pragma once\n')
for i in inputs:
content = open(i, 'r').read()
with open(i, 'r') as ifile:
content = ifile.read()
ofile.write(content)
ofile.write('\n')

@ -5,7 +5,9 @@ import sys, os
ifile = sys.argv[1]
ofile = sys.argv[2]
resname = open(ifile, 'r').readline().strip()
with open(ifile, 'r') as f:
resname = f.readline().strip()
templ = 'const char %s[] = "%s";\n'
open(ofile, 'w').write(templ % (resname, resname))
with open(ofile, 'w') as f:
f.write(templ % (resname, resname))

@ -6,7 +6,8 @@ if __name__ == '__main__':
if len(sys.argv) != 2:
print(sys.argv[0], 'input_file')
sys.exit(1)
ifile = open(sys.argv[1]).read()
with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n':
print('Malformed input')
sys.exit(1)

@ -6,8 +6,8 @@ if len(sys.argv) != 3:
print("Wrong amount of parameters.")
# Just test that it exists.
ifile = open(sys.argv[1], 'r')
with open(sys.argv[1], 'r') as ifile:
pass
ofile = open(sys.argv[2], 'w')
ofile.write("#define ZERO_RESULT 0\n")
ofile.close()
with open(sys.argv[2], 'w') as ofile:
ofile.write("#define ZERO_RESULT 0\n")

@ -2,5 +2,6 @@
import sys
if open(sys.argv[1]).read() != 'contents\n':
sys.exit(1)
with open(sys.argv[1]) as f:
if f.read() != 'contents\n':
sys.exit(1)

@ -9,5 +9,7 @@ depfiles = glob(os.path.join(srcdir, '*'))
quoted_depfiles = [x.replace(' ', '\ ') for x in depfiles]
open(output, 'w').write('I am the result of globbing.')
open(depfile, 'w').write('%s: %s\n' % (output, ' '.join(quoted_depfiles)))
with open(output, 'w') as f:
f.write('I am the result of globbing.')
with open(depfile, 'w') as f:
f.write('%s: %s\n' % (output, ' '.join(quoted_depfiles)))

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file')
sys.exit(1)
ifile = open(sys.argv[1]).read()
with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n':
print('Malformed input')
sys.exit(1)
ofile = open(sys.argv[2], 'w')
ofile.write('This is a binary output file.\n')
with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a binary output file.\n')

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file')
sys.exit(1)
ifile = open(sys.argv[1]).read()
with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a text only input file.\n':
print('Malformed input')
sys.exit(1)
ofile = open(sys.argv[2], 'w')
ofile.write('This is a binary output file.\n')
with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a binary output file.\n')

@ -6,9 +6,10 @@ if __name__ == '__main__':
if len(sys.argv) != 3:
print(sys.argv[0], 'input_file output_file')
sys.exit(1)
ifile = open(sys.argv[1]).read()
with open(sys.argv[1]) as f:
ifile = f.read()
if ifile != 'This is a binary output file.\n':
print('Malformed input')
sys.exit(1)
ofile = open(sys.argv[2], 'w')
ofile.write('This is a different binary output file.\n')
with open(sys.argv[2], 'w') as ofile:
ofile.write('This is a different binary output file.\n')

@ -3,5 +3,5 @@
import sys, os
with open(sys.argv[1], 'rb') as ifile:
open(sys.argv[2], 'w').write('Everything ok.\n')
with open(sys.argv[2], 'w') as ofile:
ofile.write('Everything ok.\n')

@ -2,4 +2,5 @@
import sys
open(sys.argv[2], 'wb').write(open(sys.argv[1], 'rb').read())
with open(sys.argv[1], 'rb') as ifile, open(sys.argv[2], 'wb') as ofile:
ofile.write(ifile.read())

@ -5,7 +5,8 @@ import sys
plain_arg = sys.argv[1]
_, filename, _ = plain_arg.split(':')
try:
content = open(filename, 'rb').read()
with open(filename, 'rb') as f:
content = f.read()
except FileNotFoundError:
print('Could not open file. Missing dependency?')
sys.exit(1)

@ -7,8 +7,10 @@ if len(sys.argv) != 2:
odir = sys.argv[1]
open(os.path.join(odir, 'mylib.h'), 'w').write('int func();\n')
open(os.path.join(odir, 'mylib.c'), 'w').write('''int func() {
with open(os.path.join(odir, 'mylib.h'), 'w') as f:
f.write('int func();\n')
with open(os.path.join(odir, 'mylib.c'), 'w') as f:
f.write('''int func() {
return 0;
}
''')

@ -6,5 +6,7 @@
import sys
template = '#define RET_VAL %s\n'
output = template % (open(sys.argv[1]).readline().strip())
open(sys.argv[2], 'w').write(output)
with open(sys.argv[1]) as f:
output = template % (f.readline().strip(), )
with open(sys.argv[2], 'w') as f:
f.write(output)

@ -6,14 +6,17 @@ if len(sys.argv) != 3:
print("You is fail.")
sys.exit(1)
val = open(sys.argv[1]).read().strip()
with open(sys.argv[1]) as f:
val = f.read().strip()
outdir = sys.argv[2]
outhdr = os.path.join(outdir, 'source%s.h' % val)
outsrc = os.path.join(outdir, 'source%s.cpp' % val)
open(outhdr, 'w').write('int func%s();\n' % val)
open(outsrc, 'w').write('''int func%s() {
with open(outhdr, 'w') as f:
f.write('int func%s();\n' % val)
with open(outsrc, 'w') as f:
f.write('''int func%s() {
return 0;
}
''' % val)

@ -14,14 +14,17 @@ def generate(infile, outfile, fallback):
version = stdo.decode().strip()
except:
pass
newdata = open(infile).read().replace('@VERSION@', version)
with open(infile) as f:
newdata = f.read().replace('@VERSION@', version)
try:
olddata = open(outfile).read()
with open(outfile) as f:
olddata = f.read()
if olddata == newdata:
return
except:
pass
open(outfile, 'w').write(newdata)
with open(outfile, 'w') as f:
f.write(newdata)
if __name__ == '__main__':
infile = sys.argv[1]

@ -2,7 +2,8 @@
import sys
ifile = open(sys.argv[1])
if ifile.readline().strip() != '42':
print('Incorrect input')
open(sys.argv[2], 'w').write('Success\n')
with open(sys.argv[1]) as ifile:
if ifile.readline().strip() != '42':
print('Incorrect input')
with open(sys.argv[2], 'w') as ofile:
ofile.write('Success\n')

@ -6,5 +6,7 @@ import time, sys
# is missing.
time.sleep(0.5)
contents = open(sys.argv[1], 'r').read()
open(sys.argv[2], 'w').write(contents)
with open(sys.argv[1], 'r') as f:
contents = f.read()
with open(sys.argv[2], 'w') as f:
f.write(contents)

@ -6,4 +6,5 @@ from glob import glob
files = glob(os.path.join(sys.argv[1], '*.tmp'))
assert(len(files) == 1)
open(sys.argv[2], 'w').write(open(files[0], 'r').read())
with open(files[0], 'r') as ifile, open(sys.argv[2], 'w') as ofile:
ofile.write(ifile.read())

@ -26,5 +26,7 @@ hfile = os.path.join(outdir, base + '.h')
c_code = c_templ % (base, base)
h_code = h_templ % base
open(cfile, 'w').write(c_code)
open(hfile, 'w').write(h_code)
with open(cfile, 'w') as f:
f.write(c_code)
with open(hfile, 'w') as f:
f.write(h_code)

@ -19,8 +19,10 @@ c_templ = '''int %s() {
options = parser.parse_args(sys.argv[1:])
funcname = open(options.input).readline().strip()
with open(options.input) as f:
funcname = f.readline().strip()
if options.upper:
funcname = funcname.upper()
open(options.output, 'w').write(c_templ % funcname)
with open(options.output, 'w') as f:
f.write(c_templ % funcname)

Loading…
Cancel
Save