diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-07-13 16:03:14 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-07-13 16:08:02 -0700 |
commit | 1cc8b854d6f32f44a2f60b3e090a805954e6377c (patch) | |
tree | 42d47cdf5314ceb521054379d5761b63347e1905 | |
parent | 9e2f21c9aa1993325b5a7043d206e2baf07e9180 (diff) | |
download | binaryen-1cc8b854d6f32f44a2f60b3e090a805954e6377c.tar.gz binaryen-1cc8b854d6f32f44a2f60b3e090a805954e6377c.tar.bz2 binaryen-1cc8b854d6f32f44a2f60b3e090a805954e6377c.zip |
use with-open
-rwxr-xr-x | auto_update_tests.py | 18 | ||||
-rwxr-xr-x | check.py | 10 |
2 files changed, 14 insertions, 14 deletions
diff --git a/auto_update_tests.py b/auto_update_tests.py index 3b6c9bf24..75396655e 100755 --- a/auto_update_tests.py +++ b/auto_update_tests.py @@ -21,7 +21,7 @@ for asm in sorted(os.listdir('test')): print '..', asm, wasm print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', wasm), 'w').write(actual) + with open(os.path.join('test', wasm), 'w') as o: o.write(actual) for dot_s_dir in ['dot_s', 'llvm_autogenerated']: for s in sorted(os.listdir(os.path.join('test', dot_s_dir))): @@ -37,7 +37,7 @@ for dot_s_dir in ['dot_s', 'llvm_autogenerated']: assert err == '', 'bad err:' + err expected_file = os.path.join('test', dot_s_dir, wasm) - open(expected_file, 'w').write(actual) + with open(expected_file, 'w') as o: o.write(actual) ''' for wasm in ['address.wast']:#os.listdir(os.path.join('test', 'spec')): @@ -59,11 +59,11 @@ for t in sorted(os.listdir(os.path.join('test', 'print'))): cmd = [os.path.join('bin', 'wasm-shell'), os.path.join('test', 'print', t), '--print'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', 'print', wasm + '.txt'), 'w').write(actual) + with open(os.path.join('test', 'print', wasm + '.txt'), 'w') as o: o.write(actual) cmd = [os.path.join('bin', 'wasm-shell'), os.path.join('test', 'print', t), '--print-minified'] print ' ', ' '.join(cmd) actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate() - open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w').write(actual) + with open(os.path.join('test', 'print', wasm + '.minified.txt'), 'w') as o: o.write(actual) for t in sorted(os.listdir(os.path.join('test', 'passes'))): if t.endswith('.wast'): @@ -74,10 +74,10 @@ for t in sorted(os.listdir(os.path.join('test', 'passes'))): actual = '' for module, asserts in split_wast(t): assert len(asserts) == 0 - open('split.wast', 'w').write(module) + with open('split.wast', 'w') as o: o.write(module) cmd = [os.path.join('bin', 'wasm-opt')] + opts + ['split.wast', '--print'] actual += run_command(cmd) - open(os.path.join('test', 'passes', passname + '.txt'), 'w').write(actual) + with open(os.path.join('test', 'passes', passname + '.txt'), 'w') as o: o.write(actual) print '\n[ checking binary format testcases... ]\n' @@ -95,7 +95,7 @@ for wast in sorted(os.listdir('test')): subprocess.check_call(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert os.path.exists('a.wast') actual = open('a.wast').read() - open(os.path.join('test', wast + '.fromBinary'), 'w').write(actual) + with open(os.path.join('test', wast + '.fromBinary'), 'w') as o: o.write(actual) print '\n[ checking example testcases... ]\n' @@ -110,7 +110,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): continue print ' (will check trace in ', t, ')' src = 'trace.cpp' - open(src, 'w').write(out) + with open(src, 'w') as o: o.write(out) expected = os.path.join('test', 'example', t + '.txt') else: src = os.path.join('test', 'example', t) @@ -138,7 +138,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): proc = subprocess.Popen([output_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) actual, err = proc.communicate() assert proc.returncode == 0, [proc.returncode, actual, err] - open(expected, 'w').write(actual) + with open(expected, 'w') as o: o.write(actual) finally: os.remove(output_file) if sys.platform == 'darwin': @@ -73,7 +73,7 @@ def fetch_waterfall(): os.mkdir(WATERFALL_BUILD_DIR) subprocess.check_call(['tar', '-xf', os.path.abspath(fullname)], cwd=WATERFALL_BUILD_DIR) print '(noting local revision)' - open(os.path.join('test', 'local-revision'), 'w').write(rev) + with open(os.path.join('test', 'local-revision'), 'w') as o: o.write(rev) has_vanilla_llvm = False @@ -269,7 +269,7 @@ for t in sorted(os.listdir(os.path.join('test', 'passes'))): actual = '' for module, asserts in split_wast(t): assert len(asserts) == 0 - open('split.wast', 'w').write(module) + with open('split.wast', 'w') as o: o.write(module) cmd = [os.path.join('bin', 'wasm-opt')] + opts + ['split.wast', '--print'] actual += run_command(cmd) fail_if_not_identical(actual, open(os.path.join('test', 'passes', passname + '.txt')).read()) @@ -412,7 +412,7 @@ for t in spec_tests: for module, asserts in split_wast(wast): print ' testing split module', split_num split_num += 1 - open('split.wast', 'w').write(module + '\n' + '\n'.join(asserts)) + with open('split.wast', 'w') as o: o.write(module + '\n' + '\n'.join(asserts)) run_spec_test('split.wast') # before binary stuff - just check it's still ok split out result_wast = binary_format_check('split.wast', verify_final_result=False) # add the asserts, and verify that the test still passes @@ -627,7 +627,7 @@ for t in sorted(os.listdir(os.path.join('test', 'example'))): continue print ' (will check trace in ', t, ')' src = 'trace.cpp' - open(src, 'w').write(out) + with open(src, 'w') as o: o.write(out) expected = os.path.join('test', 'example', t + '.txt') else: src = os.path.join('test', 'example', t) @@ -705,7 +705,7 @@ if has_emcc: asm = open('a.wasm.asm.js').read() asm = asm.replace('"almost asm"', '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') asm = asm.replace("'almost asm'", '"use asm"; var not_in_asm = [].length + (true || { x: 5 }.x);') - open('a.wasm.asm.js', 'w').write(asm) + with open('a.wasm.asm.js', 'w') as o: o.write(asm) if method == 'interpret-asm2wasm': os.unlink('a.wasm.wast') # we should not need the .wast if not success: |