diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/Batch/generated.py | 10 | ||||
-rw-r--r-- | test/CacheDir/NoCache.py | 3 | ||||
-rw-r--r-- | test/Deprecated/TargetSignatures/build-content.py | 3 | ||||
-rw-r--r-- | test/Fortran/link-with-cxx.py | 6 | ||||
-rw-r--r-- | test/MSVC/generate-rc.py | 8 | ||||
-rw-r--r-- | test/NodeOps.py | 3 | ||||
-rw-r--r-- | test/Repository/Local.py | 6 | ||||
-rw-r--r-- | test/Repository/option-c.py | 3 | ||||
-rw-r--r-- | test/Requires/eval-order.py | 10 | ||||
-rw-r--r-- | test/Value.py | 10 | ||||
-rw-r--r-- | test/VariantDir/File-create.py | 6 | ||||
-rw-r--r-- | test/Win32/msvc_mingw_env.py | 102 | ||||
-rw-r--r-- | test/chained-build.py | 6 | ||||
-rw-r--r-- | test/implicit-cache/basic.py | 3 | ||||
-rw-r--r-- | test/sconsign/nonwritable.py | 12 |
15 files changed, 159 insertions, 32 deletions
diff --git a/test/Batch/generated.py b/test/Batch/generated.py index 21b8250..65ce8a8 100644 --- a/test/Batch/generated.py +++ b/test/Batch/generated.py @@ -36,10 +36,12 @@ test = TestSCons.TestSCons() test.write('SConstruct', """ def batch_build(target, source, env): for t, s in zip(target, source): - fp = open(str(t), 'wb') - if str(t) == 'f3.out': - fp.write(open('f3.include', 'rb').read()) - fp.write(open(str(s), 'rb').read()) + with open(str(t), 'wb') as fp: + if str(t) == 'f3.out': + with open('f3.include', 'rb') as f: + fp.write(f.read()) + with open(str(s), 'rb') as f: + fp.write(f.read()) env = Environment() bb = Action(batch_build, batch_key=True) env['BUILDERS']['Batch'] = Builder(action=bb) diff --git a/test/CacheDir/NoCache.py b/test/CacheDir/NoCache.py index f0929aa..8ecfeb3 100644 --- a/test/CacheDir/NoCache.py +++ b/test/CacheDir/NoCache.py @@ -46,7 +46,8 @@ CacheDir(r'%s') g = '%s' def ActionWithUndeclaredInputs(target,source,env): - open(target[0].get_abspath(),'w').write(g) + with open(target[0].get_abspath(),'w') as f: + f.write(g) Command('foo_cached', [], ActionWithUndeclaredInputs) NoCache(Command('foo_notcached', [], ActionWithUndeclaredInputs)) diff --git a/test/Deprecated/TargetSignatures/build-content.py b/test/Deprecated/TargetSignatures/build-content.py index 6a5a8c4..efdaaee 100644 --- a/test/Deprecated/TargetSignatures/build-content.py +++ b/test/Deprecated/TargetSignatures/build-content.py @@ -47,7 +47,8 @@ SetOption('warn', 'deprecated-target-signatures') env = Environment() def copy1(env, source, target): - open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read()) + with open(str(target[0]), 'wb') as fo, open(str(source[0]), 'rb') as fi: + fo.write(fi.read()) def copy2(env, source, target): %s diff --git a/test/Fortran/link-with-cxx.py b/test/Fortran/link-with-cxx.py index a29558e..bf10fc8 100644 --- a/test/Fortran/link-with-cxx.py +++ b/test/Fortran/link-with-cxx.py @@ -48,7 +48,8 @@ elif sys.argv[1][:5] == '/OUT:': outfile = open(sys.argv[1][5:], 'wb') infiles = sys.argv[2:] for infile in infiles: - outfile.write(open(infile, 'rb').read()) + with open(infile, 'rb') as f: + outfile.write(f.read()) outfile.close() sys.exit(0) """) @@ -69,7 +70,8 @@ import SCons.Tool.link def copier(target, source, env): s = str(source[0]) t = str(target[0]) - open(t, 'wb').write(open(s, 'rb').read()) + with open(t, 'wb') as fo, open(s, 'rb') as fi: + fo.write(fi.read()) env = Environment(CXX = r'%(_python_)s test_linker.py', CXXCOM = Action(copier), SMARTLINK = SCons.Tool.link.smart_link, diff --git a/test/MSVC/generate-rc.py b/test/MSVC/generate-rc.py index 00e9090..3dd4331 100644 --- a/test/MSVC/generate-rc.py +++ b/test/MSVC/generate-rc.py @@ -39,16 +39,16 @@ fake_rc = test.workpath('fake_rc.py') test.write(fake_rc, """\ import sys -contents = open(sys.argv[2], 'r').read() -open(sys.argv[1], 'w').write("fake_rc.py\\n" + contents) +with open(sys.argv[1], 'w') as fo, open(sys.argv[2], 'r') as fi: + fo.write("fake_rc.py\\n" + fi.read()) """) test.write('SConstruct', """ def generate_rc(target, source, env): t = str(target[0]) s = str(source[0]) - tfp = open(t, 'w') - tfp.write('generate_rc\\n' + open(s, 'r').read()) + with open(t, 'w') as fo, open(s, 'r') as fi: + fo.write('generate_rc\\n' + fi.read()) env = Environment(tools=['msvc'], RCCOM=r'%(_python_)s %(fake_rc)s $TARGET $SOURCE') diff --git a/test/NodeOps.py b/test/NodeOps.py index 1f856c3..99a3f6a 100644 --- a/test/NodeOps.py +++ b/test/NodeOps.py @@ -122,7 +122,8 @@ import os Import('*') def mycopy(env, source, target): - open(str(target[0]),'w').write(open(str(source[0]),'r').read()) + with open(str(target[0]), 'wt') as fo, open(str(source[0]), 'rt') as fi: + fo.write(fi.read()) def exists_test(node): before = os.path.exists(str(node)) # doesn't exist yet in VariantDir diff --git a/test/Repository/Local.py b/test/Repository/Local.py index 95fd898..7062075 100644 --- a/test/Repository/Local.py +++ b/test/Repository/Local.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 fo, open(source, 'r') as fi: + fo.write(fi.read()) Build = Builder(action=copy) env = Environment(BUILDERS={'Build':Build}, BBB='bbb') @@ -66,7 +67,8 @@ test.write(['repository', 'src', 'SConscript'], r""" def bbb_copy(env, source, target): target = str(target[0]) print('bbb_copy()') - open(target, "w").write(open('build/bbb.1', "r").read()) + with open(target, 'w') as fo, open('build/bbb.1', 'r') as fi: + fo.write(fi.read()) Import("env") env.Build('bbb.1', 'bbb.0') diff --git a/test/Repository/option-c.py b/test/Repository/option-c.py index b0d8533..58c4876 100644 --- a/test/Repository/option-c.py +++ b/test/Repository/option-c.py @@ -66,7 +66,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 fo, open(source, 'r') as fi: + fo.write(fi.read()) Build = Builder(action=copy) env = Environment(BUILDERS={'Build':Build}) diff --git a/test/Requires/eval-order.py b/test/Requires/eval-order.py index 696b5e9..77fbc98 100644 --- a/test/Requires/eval-order.py +++ b/test/Requires/eval-order.py @@ -34,11 +34,13 @@ test = TestSCons.TestSCons() test.write('SConstruct', """ def copy_and_create_func(target, source, env): - fp = open(str(target[0]), 'w') - for s in source: - fp.write(open(str(s), 'r').read()) - fp.close() + with open(str(target[0]), 'w') as fp: + for s in source: + with open(str(s), 'r') as f: + fp.write(f.read()) open('file.in', 'w').write("file.in 1\\n") + with open('file.in', 'w') as f: + f.write("file.in 1\\n") return None copy_and_create = Action(copy_and_create_func) env = Environment() diff --git a/test/Value.py b/test/Value.py index 34b036b..5a6a48e 100644 --- a/test/Value.py +++ b/test/Value.py @@ -48,7 +48,8 @@ L = len(P) C = Custom(P) def create(target, source, env): - open(str(target[0]), 'wb').write(source[0].get_contents()) + with open(str(target[0]), 'wb') as f: + f.write(source[0].get_contents()) env = Environment() env['BUILDERS']['B'] = Builder(action = create) @@ -62,7 +63,9 @@ def create_value (target, source, env): target[0].write(source[0].get_contents()) def create_value_file (target, source, env): - open(str(target[0]), 'wb').write(source[0].read()) + #open(str(target[0]), 'wb').write(source[0].read()) + with open(str(target[0]), 'wb') as f: + f.write(source[0].read()) env['BUILDERS']['B2'] = Builder(action = create_value) env['BUILDERS']['B3'] = Builder(action = create_value_file) @@ -75,7 +78,8 @@ env.B3('f5.out', V) test.write('put.py', """\ import os import sys -open(sys.argv[-1],'w').write(" ".join(sys.argv[1:-2])) +with open(sys.argv[-1],'w') as f: + f.write(" ".join(sys.argv[1:-2])) """) # Run all of the tests with both types of source signature diff --git a/test/VariantDir/File-create.py b/test/VariantDir/File-create.py index 25e6c09..ad9234b 100644 --- a/test/VariantDir/File-create.py +++ b/test/VariantDir/File-create.py @@ -49,12 +49,14 @@ SConscript('src/SConscript', variant_dir='build1', chdir=1, duplicate=1) test.write(['src', 'SConscript'], """\ #f1_in = File('f1.in') #Command('f1.out', f1_in, Copy('$TARGET', '$SOURCE')) -#open('f1.in', 'w').write("f1.in\\n") +#with open('f1.in', 'w') as f: +# f.write("f1.in\\n") f2_in = File('f2.in') str(f2_in) Command('f2.out', f2_in, Copy('$TARGET', '$SOURCE')) -open('f2.in', 'w').write("f2.in\\n") +with open('f2.in', 'w') as f: + f.write("f2.in\\n") """) test.run(arguments = '--tree=all .') diff --git a/test/Win32/msvc_mingw_env.py b/test/Win32/msvc_mingw_env.py new file mode 100644 index 0000000..107cd1e --- /dev/null +++ b/test/Win32/msvc_mingw_env.py @@ -0,0 +1,102 @@ +""" +This tests the MinGW with MSVC tool. +""" + +#!/usr/bin/env python +# +# __COPYRIGHT__ +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY +# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE +# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" + +import sys + +import TestSCons + +test = TestSCons.TestSCons() + +# MinGW is Windows only: +if sys.platform != 'win32': + msg = "Skipping mingw test on non-Windows platform '%s'\n" % sys.platform + test.skip_test(msg) + +test.skip_if_not_msvc() + +# control test: check for nologo and cl in env +test.write('SConstruct',""" +env=Environment(tools=['default']) +print('CCFLAGS=' + str(env['CCFLAGS']).strip()) +print('CC=' + str(env['CC']).strip()) +""") +test.run(arguments='-Q -s') +if('CCFLAGS=/nologo' not in test.stdout() + or 'CC=cl' not in test.stdout()): + test.fail_test() + +# make sure windows msvc doesnt add bad mingw flags +# and that gcc is selected +test.write('SConstruct',""" +env=Environment(tools=['default', 'mingw']) +print('CCFLAGS="' + str(env['CCFLAGS']).strip() + '"') +print('CC=' + str(env['CC']).strip()) +""") +test.run(arguments='-Q -s') +if('CCFLAGS=""' not in test.stdout() + or 'CC=gcc' not in test.stdout()): + test.fail_test() + +# msvc should overwrite the flags and use cl +test.write('SConstruct',""" +env=Environment(tools=['mingw', 'default']) +print('CCFLAGS=' + str(env['CCFLAGS']).strip()) +print('CC=' + str(env['CC']).strip()) +""") +test.run(arguments='-Q -s') +if('CCFLAGS=/nologo' not in test.stdout() + or 'CC=cl' not in test.stdout()): + test.fail_test() + +# test that CCFLAGS are preserved +test.write('SConstruct',""" +env=Environment(tools=['mingw'], CCFLAGS='-myflag') +print(env['CCFLAGS']) +""") +test.run(arguments='-Q -s') +if '-myflag' not in test.stdout(): + test.fail_test() + +# test that it handles a list +test.write('SConstruct',""" +env=Environment(tools=['mingw'], CCFLAGS=['-myflag', '-myflag2']) +print(str(env['CCFLAGS'])) +""") +test.run(arguments='-Q -s') +if "['-myflag', '-myflag2']" not in test.stdout(): + test.fail_test() + +test.pass_test() + +# Local Variables: +# tab-width:4 +# indent-tabs-mode:nil +# End: +# vim: set expandtab tabstop=4 shiftwidth=4: diff --git a/test/chained-build.py b/test/chained-build.py index c3351e1..871a593 100644 --- a/test/chained-build.py +++ b/test/chained-build.py @@ -38,7 +38,8 @@ test.subdir('w1') SConstruct1_contents = """\ def build(env, target, source): - open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read()) + with open(str(target[0]), 'wt') as fo, open(str(source[0]), 'rt') as fi: + fo.write(fi.read()) env=Environment(BUILDERS={'B' : Builder(action=build)}) env.B('foo.mid', 'foo.in') @@ -46,7 +47,8 @@ env.B('foo.mid', 'foo.in') SConstruct2_contents = """\ def build(env, target, source): - open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read()) + with open(str(target[0]), 'wt') as fo, open(str(source[0]), 'rt') as fi: + fo.write(fi.read()) env=Environment(BUILDERS={'B' : Builder(action=build)}) env.B('foo.out', 'foo.mid') diff --git a/test/implicit-cache/basic.py b/test/implicit-cache/basic.py index b7cd984..c03a320 100644 --- a/test/implicit-cache/basic.py +++ b/test/implicit-cache/basic.py @@ -65,7 +65,8 @@ env = Environment(CPPPATH=['inc2', include]) SConscript('variant/SConscript', "env") def copy(target, source, env): - open(str(target[0]), 'wt').write(open(str(source[0]), 'rt').read()) + with open(str(target[0]), 'wt') as fo, open(str(source[0]), 'rt') as fi: + fo.write(fi.read()) nodep = env.Command('nodeps.c', 'nodeps.in', action=copy) env.Program('nodeps', 'nodeps.c') diff --git a/test/sconsign/nonwritable.py b/test/sconsign/nonwritable.py index 6f12f18..812a476 100644 --- a/test/sconsign/nonwritable.py +++ b/test/sconsign/nonwritable.py @@ -51,13 +51,15 @@ work2_sub3__sconsign = test.workpath('work2', 'sub3', '.sconsign') SConstruct_contents = """\ def build1(target, source, env): - open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read()) + with open(str(target[0]), 'wb') as fo, open(str(source[0]), 'rb') as fi: + fo.write(fi.read()) return None def build2(target, source, env): import os import os.path - open(str(target[0]), 'wb').write(open(str(source[0]), 'rb').read()) + with open(str(target[0]), 'wb') as fo, open(str(source[0]), 'rb') as fi: + fo.write(fi.read()) dir, file = os.path.split(str(target[0])) os.chmod(dir, 0o555) return None @@ -92,8 +94,10 @@ test.write(['work2', 'SConstruct'], SConstruct_contents) test.write(['work2', 'foo.in'], "work2/foo.in\n") -pickle.dump({}, open(work2_sub1__sconsign, 'wb'), 1) -pickle.dump({}, open(work2_sub2__sconsign, 'wb'), 1) +with open(work2_sub1__sconsign, 'wb') as p: + pickle.dump({}, p, 1) +with open(work2_sub2__sconsign, 'wb') as p: + pickle.dump({}, p, 1) os.chmod(work2_sub1__sconsign, 0o444) |