diff options
author | Mats Wichmann <mats@linux.com> | 2022-03-22 20:11:13 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2022-03-30 13:16:29 (GMT) |
commit | 2b673e30e81f83304746e7fec9aa4ddb0fd66f88 (patch) | |
tree | 8d91682d9d80e05d66dab0c3d7e396479c24433b | |
parent | 2976ed620bfd86804927a9bc3760924f4a3205e2 (diff) | |
download | SCons-2b673e30e81f83304746e7fec9aa4ddb0fd66f88.zip SCons-2b673e30e81f83304746e7fec9aa4ddb0fd66f88.tar.gz SCons-2b673e30e81f83304746e7fec9aa4ddb0fd66f88.tar.bz2 |
Fix some more tests to use context-mgr open
Fiddled formatting a bit.
Signed-off-by: Mats Wichmann <mats@linux.com>
-rw-r--r-- | test/Actions/append.py | 16 | ||||
-rw-r--r-- | test/Actions/function.py | 64 | ||||
-rw-r--r-- | test/Actions/pre-post.py | 31 | ||||
-rw-r--r-- | test/option/option--.py | 24 | ||||
-rw-r--r-- | test/option/option--Q.py | 27 | ||||
-rw-r--r-- | test/option/option-i.py | 51 | ||||
-rw-r--r-- | test/option/option-k.py | 152 | ||||
-rw-r--r-- | test/option/option-s.py | 23 |
8 files changed, 197 insertions, 191 deletions
diff --git a/test/Actions/append.py b/test/Actions/append.py index b5d4c3a..42a414b 100644 --- a/test/Actions/append.py +++ b/test/Actions/append.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,13 +22,13 @@ # 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. -# -# This test exercises the addition operator of Action objects. -# Using Environment.Prepend() and Environment.Append(), you should be -# able to add new actions to existing ones, effectively adding steps -# to a build process. -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +""" +This test exercises the addition operator of Action objects. +Using Environment.Prepend() and Environment.Append(), you should be +able to add new actions to existing ones, effectively adding steps +to a build process. +""" import os import stat diff --git a/test/Actions/function.py b/test/Actions/function.py index 7f292cf..699cd17 100644 --- a/test/Actions/function.py +++ b/test/Actions/function.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 @@ -59,6 +58,7 @@ options.AddVariables( ('literal_in_listcomp', 'Literal inside list comprehension', '2'), ) +DefaultEnvironment(tools=[]) optEnv = Environment(options=options, tools=[]) r = re.compile(optEnv['regexp']) @@ -67,25 +67,24 @@ withClosure = \ r''' def toto(header='%(header)s', trailer='%(trailer)s'): xxx = %(closure_cell_value)s - def writeDeps(target, source, env, b=%(b)s, r=r %(extraarg)s , - header=header, trailer=trailer): + def writeDeps(target, source, env, b=%(b)s, r=r %(extraarg)s , header=header, trailer=trailer): """+'"""%(docstring)s"""'+""" def foo(b=b): return %(nestedfuncexp)s - f = open(str(target[0]),'wb') - f.write(bytearray(header,'utf-8')) - for d in env['ENVDEPS']: - f.write(bytearray(d+'%(separator)s','utf-8')) - f.write(bytearray(trailer+'\\n','utf-8')) - f.write(bytearray(str(foo())+'\\n','utf-8')) - f.write(bytearray(r.match('aaaa').group(1)+'\\n','utf-8')) - f.write(bytearray(str(sum([x*%(literal_in_listcomp)s for x in [1,2]]))+'\\n', 'utf-8')) - %(extracode)s - try: - f.write(bytearray(str(xarg),'utf-8')+b'\\n') - except NameError: - pass - f.close() + + with open(str(target[0]), 'wb') as f: + f.write(bytearray(header, 'utf-8')) + for d in env['ENVDEPS']: + f.write(bytearray(d+'%(separator)s', 'utf-8')) + f.write(bytearray(trailer+'\\n', 'utf-8')) + f.write(bytearray(str(foo())+'\\n', 'utf-8')) + f.write(bytearray(r.match('aaaa').group(1)+'\\n', 'utf-8')) + f.write(bytearray(str(sum([x*%(literal_in_listcomp)s for x in [1, 2]]))+'\\n', 'utf-8')) + %(extracode)s + try: + f.write(bytearray(str(xarg), 'utf-8')+b'\\n') + except NameError: + pass return writeDeps ''' @@ -93,13 +92,9 @@ def toto(header='%(header)s', trailer='%(trailer)s'): exec(withClosure % optEnv) genHeaderBld = SCons.Builder.Builder( - action = SCons.Action.Action( - toto(), - 'Generating $TARGET', - varlist=['ENVDEPS'] - ), - suffix = '.gen.h' - ) + action=SCons.Action.Action(toto(), 'Generating $TARGET', varlist=['ENVDEPS']), + suffix='.gen.h', +) DefaultEnvironment(tools=[]) env = Environment(tools=[]) @@ -128,23 +123,22 @@ scons: done building targets. """ def runtest(arguments, expectedOutFile, expectedRebuild=True, stderr=""): - test.run(arguments=arguments, - stdout=expectedRebuild and rebuildstr or nobuildstr, - stderr="") + test.run( + arguments=arguments, + stdout=expectedRebuild and rebuildstr or nobuildstr, + stderr="", + ) sys.stdout.write('First Build.\n') test.must_match('Out.gen.h', expectedOutFile, message="First Build") - # Should not be rebuild when run a second time with the same - # arguments. - + # Should not be rebuild when run a second time with the same arguments. sys.stdout.write('Rebuild.\n') - test.run(arguments = arguments, stdout=nobuildstr, stderr="") + test.run(arguments=arguments, stdout=nobuildstr, stderr="") test.must_match('Out.gen.h', expectedOutFile, message="Should not rebuild") - # We're making this script chatty to prevent timeouts on really really # slow buildbot slaves (*cough* Solaris *cough*). diff --git a/test/Actions/pre-post.py b/test/Actions/pre-post.py index 358aa43..ce8cbdc 100644 --- a/test/Actions/pre-post.py +++ b/test/Actions/pre-post.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,12 +22,11 @@ # 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. -# -# This test exercises the AddPreAction() and AddPostAction() API -# functions, which add pre-build and post-build actions to nodes. -# -__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +""" +This test exercises the AddPreAction() and AddPostAction() API +functions, which add pre-build and post-build actions to nodes. +""" import os @@ -56,11 +57,8 @@ def before(env, target, source): def after(env, target, source): t = str(target[0]) a = "after_" + t - fin = open(t, "rb") - fout = open(a, "wb") - fout.write(fin.read()) - fout.close() - fin.close() + with open(t, "rb") as fin, open(a, "wb") as fout: + fout.write(fin.read()) os.chmod(a, os.stat(a)[stat.ST_MODE] | stat.S_IXUSR) foo = env.Program(source='foo.c', target='foo') @@ -103,19 +101,22 @@ test.must_match(['work3', 'dir', 'file'], "build()\n") # work4 start test.write(['work4', 'SConstruct'], """\ - DefaultEnvironment(tools=[]) def pre_action(target, source, env): with open(str(target[0]), 'ab') as f: f.write(('pre %%s\\n' %% source[0]).encode()) + def post_action(target, source, env): with open(str(target[0]), 'ab') as f: f.write(('post %%s\\n' %% source[0]).encode()) + env = Environment(tools=[]) -o = env.Command(['pre-post', 'file.out'], - 'file.in', - r'%(_python_)s build.py ${TARGETS[1]} $SOURCE') +o = env.Command( + ['pre-post', 'file.out'], + 'file.in', + r'%(_python_)s build.py ${TARGETS[1]} $SOURCE' +) env.AddPreAction(o, pre_action) env.AddPostAction(o, post_action) """ % locals()) diff --git a/test/option/option--.py b/test/option/option--.py index 8e06260..dbfb3c9 100644 --- a/test/option/option--.py +++ b/test/option/option--.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 os.path @@ -34,16 +33,17 @@ test = TestSCons.TestSCons() test.write('build.py', r""" import sys -file = open(sys.argv[1], 'w') -file.write("build.py: %s\n" % sys.argv[1]) -file.close() + +with open(sys.argv[1], 'w') as file: + file.write("build.py: %s\n" % sys.argv[1]) +sys.exit(0) """) test.write('SConstruct', """ -MyBuild = Builder(action = r'%(_python_)s build.py $TARGETS') -env = Environment(BUILDERS = { 'MyBuild' : MyBuild }) -env.MyBuild(target = '-f1.out', source = 'f1.in') -env.MyBuild(target = '-f2.out', source = 'f2.in') +MyBuild = Builder(action=r'%(_python_)s build.py $TARGETS') +env = Environment(BUILDERS={'MyBuild': MyBuild}) +env.MyBuild(target='-f1.out', source='f1.in') +env.MyBuild(target='-f2.out', source='f2.in') """ % locals()) test.write('f1.in', "f1.in\n") @@ -51,7 +51,7 @@ test.write('f2.in', "f2.in\n") expect = test.wrap_stdout('%(_python_)s build.py -f1.out\n%(_python_)s build.py -f2.out\n' % locals()) -test.run(arguments = '-- -f1.out -f2.out', stdout = expect) +test.run(arguments='-- -f1.out -f2.out', stdout=expect) test.fail_test(not os.path.exists(test.workpath('-f1.out'))) test.fail_test(not os.path.exists(test.workpath('-f2.out'))) diff --git a/test/option/option--Q.py b/test/option/option--Q.py index f3b82f9..ac56d34 100644 --- a/test/option/option--Q.py +++ b/test/option/option--Q.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 os.path @@ -35,24 +34,24 @@ test = TestSCons.TestSCons() test.write('build.py', r""" import sys -file = open(sys.argv[1], 'w') -file.write("build.py: %s\n" % sys.argv[1]) -file.close() + +with open(sys.argv[1], 'w') as file: + file.write("build.py: %s\n" % sys.argv[1]) +sys.exit(0) """) test.write('SConstruct', """ - AddOption('--use_SetOption', action='store_true', dest='setoption', default=False) -use_setoption=GetOption('setoption') +use_setoption = GetOption('setoption') if use_setoption: SetOption('no_progress', True) - -MyBuild = Builder(action = r'%(_python_)s build.py $TARGET') -env = Environment(BUILDERS = { 'MyBuild' : MyBuild }) -env.MyBuild(target = 'f1.out', source = 'f1.in') -env.MyBuild(target = 'f2.out', source = 'f2.in') + +MyBuild = Builder(action=r'%(_python_)s build.py $TARGET') +env = Environment(BUILDERS={'MyBuild': MyBuild}) +env.MyBuild(target='f1.out', source='f1.in') +env.MyBuild(target='f2.out', source='f2.in') """ % locals()) test.write('f1.in', "f1.in\n") diff --git a/test/option/option-i.py b/test/option/option-i.py index 9b5212d..e426e1f 100644 --- a/test/option/option-i.py +++ b/test/option/option-i.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 os.path @@ -34,43 +33,46 @@ test = TestSCons.TestSCons() test.write('succeed.py', r""" import sys -file = open(sys.argv[1], 'w') -file.write("succeed.py: %s\n" % sys.argv[1]) -file.close() + +with open(sys.argv[1], 'w') as file: + file.write("succeed.py: %s\n" % sys.argv[1]) sys.exit(0) """) test.write('fail.py', r""" import sys + sys.exit(1) """) test.write('SConstruct', """ -Succeed = Builder(action = r'%(_python_)s succeed.py $TARGETS') -Fail = Builder(action = r'%(_python_)s fail.py $TARGETS') -env = Environment(BUILDERS = { 'Succeed' : Succeed, 'Fail' : Fail }) -env.Fail(target = 'aaa.1', source = 'aaa.in') -env.Succeed(target = 'aaa.out', source = 'aaa.1') -env.Fail(target = 'bbb.1', source = 'bbb.in') -env.Succeed(target = 'bbb.out', source = 'bbb.1') +Succeed = Builder(action=r'%(_python_)s succeed.py $TARGETS') +Fail = Builder(action=r'%(_python_)s fail.py $TARGETS') +env = Environment(BUILDERS={'Succeed': Succeed, 'Fail': Fail}) +env.Fail(target='aaa.1', source='aaa.in') +env.Succeed(target='aaa.out', source='aaa.1') +env.Fail(target='bbb.1', source='bbb.in') +env.Succeed(target='bbb.out', source='bbb.1') """ % locals()) test.write('aaa.in', "aaa.in\n") test.write('bbb.in', "bbb.in\n") -test.run(arguments = 'aaa.1 aaa.out bbb.1 bbb.out', - stderr = 'scons: *** [aaa.1] Error 1\n', - status = 2) +test.run( + arguments='aaa.1 aaa.out bbb.1 bbb.out', + stderr='scons: *** [aaa.1] Error 1\n', + status=2, +) test.fail_test(os.path.exists(test.workpath('aaa.1'))) test.fail_test(os.path.exists(test.workpath('aaa.out'))) test.fail_test(os.path.exists(test.workpath('bbb.1'))) test.fail_test(os.path.exists(test.workpath('bbb.out'))) -test.run(arguments = '-i aaa.1 aaa.out bbb.1 bbb.out', - stderr = - 'scons: *** [aaa.1] Error 1\n' - 'scons: *** [bbb.1] Error 1\n') +test.run( + arguments='-i aaa.1 aaa.out bbb.1 bbb.out', + stderr='scons: *** [aaa.1] Error 1\nscons: *** [bbb.1] Error 1\n', +) test.fail_test(os.path.exists(test.workpath('aaa.1'))) test.fail_test(test.read('aaa.out',mode='r') != "succeed.py: aaa.out\n") @@ -80,9 +82,10 @@ test.fail_test(test.read('bbb.out',mode='r') != "succeed.py: bbb.out\n") test.unlink("aaa.out") test.unlink("bbb.out") -test.run(arguments='--ignore-errors aaa.1 aaa.out bbb.1 bbb.out', - stderr='scons: *** [aaa.1] Error 1\n' - 'scons: *** [bbb.1] Error 1\n') +test.run( + arguments='--ignore-errors aaa.1 aaa.out bbb.1 bbb.out', + stderr='scons: *** [aaa.1] Error 1\nscons: *** [bbb.1] Error 1\n', +) test.fail_test(os.path.exists(test.workpath('aaa.1'))) test.fail_test(test.read('aaa.out', mode='r') != "succeed.py: aaa.out\n") diff --git a/test/option/option-k.py b/test/option/option-k.py index d6c81ea..6a7cfcb 100644 --- a/test/option/option-k.py +++ b/test/option/option-k.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 TestSCons @@ -33,18 +32,17 @@ test = TestSCons.TestSCons() test.subdir('work1', 'work2', 'work3') - - test.write('succeed.py', r""" import sys -file = open(sys.argv[1], 'w') -file.write("succeed.py: %s\n" % sys.argv[1]) -file.close() + +with open(sys.argv[1], 'w') as file: + file.write("succeed.py: %s\n" % sys.argv[1]) sys.exit(0) """) test.write('fail.py', r""" import sys + sys.exit(1) """) @@ -66,19 +64,23 @@ env.Succeed(target='bbb.out', source='bbb.in') test.write(['work1', 'aaa.in'], "aaa.in\n") test.write(['work1', 'bbb.in'], "bbb.in\n") -test.run(chdir='work1', - arguments='aaa.out bbb.out', - stderr='scons: *** [aaa.1] Error 1\n', - status=2) +test.run( + chdir='work1', + arguments='aaa.out bbb.out', + stderr='scons: *** [aaa.1] Error 1\n', + status=2, +) test.must_not_exist(test.workpath('work1', 'aaa.1')) test.must_not_exist(test.workpath('work1', 'aaa.out')) test.must_not_exist(test.workpath('work1', 'bbb.out')) -test.run(chdir='work1', - arguments='-k aaa.out bbb.out', - stderr='scons: *** [aaa.1] Error 1\n', - status=2) +test.run( + chdir='work1', + arguments='-k aaa.out bbb.out', + stderr='scons: *** [aaa.1] Error 1\n', + status=2, +) test.must_not_exist(test.workpath('work1', 'aaa.1')) test.must_not_exist(test.workpath('work1', 'aaa.out')) @@ -86,10 +88,12 @@ test.must_match(['work1', 'bbb.out'], "succeed.py: bbb.out\n", mode='r') test.unlink(['work1', 'bbb.out']) -test.run(chdir = 'work1', - arguments='--keep-going aaa.out bbb.out', - stderr='scons: *** [aaa.1] Error 1\n', - status=2) +test.run( + chdir='work1', + arguments='--keep-going aaa.out bbb.out', + stderr='scons: *** [aaa.1] Error 1\n', + status=2, +) test.must_not_exist(test.workpath('work1', 'aaa.1')) test.must_not_exist(test.workpath('work1', 'aaa.out')) @@ -131,11 +135,12 @@ env.Succeed('ddd.out', 'ccc.in') test.write(['work2', 'aaa.in'], "aaa.in\n") test.write(['work2', 'ccc.in'], "ccc.in\n") -test.run(chdir='work2', - arguments='-k .', - status=2, - stderr=None, - stdout="""\ +test.run( + chdir='work2', + arguments='-k .', + status=2, + stderr=None, + stdout="""\ scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... @@ -143,7 +148,9 @@ scons: Building targets ... %(_python_)s ../succeed.py ccc.out %(_python_)s ../succeed.py ddd.out scons: done building targets (errors occurred during build). -""" % locals()) +""" + % locals(), +) test.must_not_exist(['work2', 'aaa.out']) test.must_not_exist(['work2', 'bbb.out']) @@ -175,19 +182,19 @@ test.must_match(['work2', 'ddd.out'], "succeed.py: ddd.out\n", mode='r') test.write(['work3', 'SConstruct'], """\ DefaultEnvironment(tools=[]) -Succeed = Builder(action = r'%(_python_)s ../succeed.py $TARGETS') -Fail = Builder(action = r'%(_python_)s ../fail.py $TARGETS') -env = Environment(BUILDERS = {'Succeed': Succeed, 'Fail': Fail}, tools=[]) +Succeed = Builder(action=r'%(_python_)s ../succeed.py $TARGETS') +Fail = Builder(action=r'%(_python_)s ../fail.py $TARGETS') +env = Environment(BUILDERS={'Succeed': Succeed, 'Fail': Fail}, tools=[]) a = env.Fail('aaa.out', 'aaa.in') b = env.Succeed('bbb.out', 'bbb.in') c = env.Succeed('ccc.out', 'ccc.in') -a1 = Alias( 'a1', a ) -a2 = Alias( 'a2', a+b) -a4 = Alias( 'a4', c) -a3 = Alias( 'a3', a4+c) +a1 = Alias('a1', a) +a2 = Alias('a2', a + b) +a4 = Alias('a4', c) +a3 = Alias('a3', a4 + c) -Alias('all', a1+a2+a3) +Alias('all', a1 + a2 + a3) """ % locals()) test.write(['work3', 'aaa.in'], "aaa.in\n") @@ -196,36 +203,37 @@ test.write(['work3', 'ccc.in'], "ccc.in\n") # Test tegular build (i.e. without -k) -test.run(chdir = 'work3', - arguments = '.', - status = 2, - stderr = None, - stdout = """\ +test.run( + chdir='work3', + arguments='.', + status=2, + stderr=None, + stdout="""\ scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... %(_python_)s ../fail.py aaa.out scons: building terminated because of errors. -""" % locals()) +""" + % locals(), +) test.must_not_exist(['work3', 'aaa.out']) test.must_not_exist(['work3', 'bbb.out']) test.must_not_exist(['work3', 'ccc.out']) - -test.run(chdir = 'work3', - arguments = '-c .') +test.run(chdir='work3', arguments='-c .') test.must_not_exist(['work3', 'aaa.out']) test.must_not_exist(['work3', 'bbb.out']) test.must_not_exist(['work3', 'ccc.out']) - # Current directory -test.run(chdir = 'work3', - arguments = '-k .', - status = 2, - stderr = None, - stdout = """\ +test.run( + chdir='work3', + arguments='-k .', + status=2, + stderr=None, + stdout="""\ scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... @@ -233,26 +241,27 @@ scons: Building targets ... %(_python_)s ../succeed.py bbb.out %(_python_)s ../succeed.py ccc.out scons: done building targets (errors occurred during build). -""" % locals()) +""" + % locals(), +) test.must_not_exist(['work3', 'aaa.out']) test.must_exist(['work3', 'bbb.out']) test.must_exist(['work3', 'ccc.out']) - -test.run(chdir = 'work3', - arguments = '-c .') +test.run(chdir='work3', arguments='-c .') test.must_not_exist(['work3', 'aaa.out']) test.must_not_exist(['work3', 'bbb.out']) test.must_not_exist(['work3', 'ccc.out']) # Single target -test.run(chdir = 'work3', - arguments = '--keep-going all', - status = 2, - stderr = None, - stdout = """\ +test.run( + chdir='work3', + arguments='--keep-going all', + status=2, + stderr=None, + stdout="""\ scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... @@ -260,26 +269,26 @@ scons: Building targets ... %(_python_)s ../succeed.py bbb.out %(_python_)s ../succeed.py ccc.out scons: done building targets (errors occurred during build). -""" % locals()) +""" + % locals(), +) test.must_not_exist(['work3', 'aaa.out']) test.must_exist(['work3', 'bbb.out']) test.must_exist(['work3', 'ccc.out']) - -test.run(chdir = 'work3', - arguments = '-c .') +test.run(chdir='work3', arguments='-c .') test.must_not_exist(['work3', 'aaa.out']) test.must_not_exist(['work3', 'bbb.out']) test.must_not_exist(['work3', 'ccc.out']) - # Separate top-level targets -test.run(chdir = 'work3', - arguments = '-k a1 a2 a3', - status = 2, - stderr = None, - stdout = """\ +test.run( + chdir='work3', + arguments='-k a1 a2 a3', + status=2, + stderr=None, + stdout="""\ scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... @@ -287,13 +296,14 @@ scons: Building targets ... %(_python_)s ../succeed.py bbb.out %(_python_)s ../succeed.py ccc.out scons: done building targets (errors occurred during build). -""" % locals()) +""" + % locals(), +) test.must_not_exist(['work3', 'aaa.out']) test.must_exist(['work3', 'bbb.out']) test.must_exist(['work3', 'ccc.out']) - test.pass_test() # Local Variables: diff --git a/test/option/option-s.py b/test/option/option-s.py index 89a0c62..359c295 100644 --- a/test/option/option-s.py +++ b/test/option/option-s.py @@ -1,6 +1,8 @@ #!/usr/bin/env python # -# __COPYRIGHT__ +# MIT License +# +# Copyright The SCons Foundation # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the @@ -20,9 +22,6 @@ # 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 os.path @@ -34,18 +33,19 @@ test = TestSCons.TestSCons() test.write('build.py', r""" import sys -file = open(sys.argv[1], 'w') -file.write("build.py: %s\n" % sys.argv[1]) -file.close() + +with open(sys.argv[1], 'w') as file: + file.write("build.py: %s\n" % sys.argv[1]) +sys.exit(0) """) test.write('SConstruct', """ DefaultEnvironment(tools=[]) -MyBuild = Builder(action = r'%(_python_)s build.py $TARGET') +MyBuild = Builder(action=r'%(_python_)s build.py $TARGET') -silent = ARGUMENTS.get('QUIET',0) +silent = ARGUMENTS.get('QUIET', 0) if silent: - SetOption('silent',True) + SetOption('silent', True) env = Environment(BUILDERS={'MyBuild': MyBuild}, tools=[]) env.MyBuild(target='f1.out', source='f1.in') @@ -86,10 +86,7 @@ test.run(arguments='QUIET=1 f1.out f2.out', test.fail_test(not os.path.exists(test.workpath('f1.out'))) test.fail_test(not os.path.exists(test.workpath('f2.out'))) - - test.pass_test() - # Local Variables: # tab-width:4 |