diff options
author | William Deegan <bill@baddogconsulting.com> | 2019-04-28 15:43:43 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-28 15:43:43 -0400 |
commit | 35e6bbe16a859b42efca4592b435695a530f0717 (patch) | |
tree | 5a298b113bb1899e91583866b41eb9c337c0857e /test/fixture | |
parent | 44c7b81e1a47ff5d4439740b1e929ea723ee1f18 (diff) | |
parent | 4ecdcf07580b1bfcd03f7886b6ab9256ee825175 (diff) | |
download | scons-git-35e6bbe16a859b42efca4592b435695a530f0717.tar.gz |
Merge pull request #3345 from mwichmann/py38warns4-tests
[wip] Py38warns4 tests
Diffstat (limited to 'test/fixture')
-rw-r--r-- | test/fixture/mycompile.py | 25 | ||||
-rw-r--r-- | test/fixture/mylink.py | 66 | ||||
-rw-r--r-- | test/fixture/myrewrite.py | 22 | ||||
-rw-r--r-- | test/fixture/wrapper.py | 10 | ||||
-rw-r--r-- | test/fixture/wrapper_with_args.py | 10 |
5 files changed, 84 insertions, 49 deletions
diff --git a/test/fixture/mycompile.py b/test/fixture/mycompile.py index 555c2c8fa..27bf840e9 100644 --- a/test/fixture/mycompile.py +++ b/test/fixture/mycompile.py @@ -1,8 +1,19 @@ +r""" +Phony "compiler" for testing SCons. + +Copies its source files to the target file, dropping lines +that match a pattern, so we can recognize the tool +has made a modification. +""" + import sys -line = ('/*' + sys.argv[1] + '*/\n').encode() -outfile = open(sys.argv[2], 'wb') -for f in sys.argv[3:]: - infile = open(f, 'rb') - for l in [l for l in infile.readlines() if l != line]: - outfile.write(l) -sys.exit(0) + +if __name__ == '__main__': + line = ('/*' + sys.argv[1] + '*/\n').encode() + with open(sys.argv[2], 'wb') as ofp: + for f in sys.argv[3:]: + with open(f, 'rb') as ifp: + lines = [ln for ln in ifp.readlines() if ln != line] + for ln in lines: + ofp.write(ln) + sys.exit(0) diff --git a/test/fixture/mylink.py b/test/fixture/mylink.py index 7c03f0078..b56711816 100644 --- a/test/fixture/mylink.py +++ b/test/fixture/mylink.py @@ -1,31 +1,39 @@ +r""" +Phony "linker" for testing SCons. + +Recognizes the option to specify an output file, ignoring +all others; copies input lines to the output file except +ones that contain a pattern, so we can recognize the tool +has made a modification. +""" + import sys -if sys.platform == 'win32': - args = sys.argv[1:] - while args: - a = args[0] - if a == '-o': - out = args[1] - args = args[2:] - continue - if not a[0] in '/-': - break - args = args[1:] - if a[:5].lower() == '/out:': out = a[5:] - infile = open(args[0], 'rb') - outfile = open(out, 'wb') - for l in infile.readlines(): - if l[:5] != b'#link': - outfile.write(l) - sys.exit(0) -else: - import getopt - opts, args = getopt.getopt(sys.argv[1:], 'o:') - for opt, arg in opts: - if opt == '-o': out = arg - infile = open(args[0], 'rb') - outfile = open(out, 'wb') - for l in infile.readlines(): - if l[:5] != b'#link': - outfile.write(l) - sys.exit(0) +if __name__ == '__main__': + if sys.platform == 'win32': + args = sys.argv[1:] + while args: + a = args[0] + if a == '-o': + out = args[1] + args = args[2:] + continue + if not a[0] in '/-': + break + args = args[1:] + if a[:5].lower() == '/out:': out = a[5:] + with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: + for l in ifp.readlines(): + if not l.startswith(b'#link'): + ofp.write(l) + sys.exit(0) + else: + import getopt + opts, args = getopt.getopt(sys.argv[1:], 'o:') + for opt, arg in opts: + if opt == '-o': out = arg + with open(args[0], 'rb') as ifp, open(out, 'wb') as ofp: + for l in ifp.readlines(): + if not l.startswith(b'#link'): + ofp.write(l) + sys.exit(0) diff --git a/test/fixture/myrewrite.py b/test/fixture/myrewrite.py index 40bf830c8..ad4609197 100644 --- a/test/fixture/myrewrite.py +++ b/test/fixture/myrewrite.py @@ -1,7 +1,17 @@ +r""" +Phony tool to modify a file in place for testing SCons. + +Drops lines that match a pattern. Currently used to test +ranlib-related behavior without invoking ranlib. +""" + import sys -line = ('/*' + sys.argv[1] + '*/\n').encode() -lines = open(sys.argv[2], 'rb').readlines() -outfile = open(sys.argv[2], 'wb') -for l in [l for l in lines if l != line]: - outfile.write(l) -sys.exit(0) + +if __name__ == '__main__': + line = ('/*' + sys.argv[1] + '*/\n').encode() + with open(sys.argv[2], 'rb') as ifp: + lines = [ln for ln in ifp.readlines() if ln != line] + with open(sys.argv[2], 'wb') as ofp: + for ln in lines: + ofp.write(ln) + sys.exit(0) diff --git a/test/fixture/wrapper.py b/test/fixture/wrapper.py index f02ea03d3..a02368996 100644 --- a/test/fixture/wrapper.py +++ b/test/fixture/wrapper.py @@ -1,6 +1,10 @@ import os import sys -if '--version' not in sys.argv and '-dumpversion' not in sys.argv: +import subprocess + +if __name__ == '__main__': path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out') - open(path, 'wb').write(b"wrapper.py\n") -os.system(" ".join(sys.argv[1:])) + if '--version' not in sys.argv and '-dumpversion' not in sys.argv: + with open(path, 'wb') as f: + f.write(b"wrapper.py\n") + subprocess.call(sys.argv[1:]) diff --git a/test/fixture/wrapper_with_args.py b/test/fixture/wrapper_with_args.py index fccab729c..f9e4d2210 100644 --- a/test/fixture/wrapper_with_args.py +++ b/test/fixture/wrapper_with_args.py @@ -1,7 +1,9 @@ import os import sys +import subprocess -path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out') - -open(path, 'a').write("wrapper_with_args.py %s\n" % " ".join(sys.argv[1:])) -os.system(" ".join(sys.argv[1:])) +if __name__ == '__main__': + path = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'wrapper.out') + with open(path, 'a') as f: + f.write("wrapper_with_args.py %s\n" % " ".join(sys.argv[1:])) + subprocess.call(sys.argv[1:]) |