diff options
author | Mats Wichmann <mats@linux.com> | 2020-01-29 19:37:08 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2020-02-12 17:47:46 (GMT) |
commit | 4814146dc3f69729e22f89078a5783a82e9df039 (patch) | |
tree | 9981cdd637b16dc1eeeb0c16405061540b15be15 /test/SWIG/SWIG.py | |
parent | eebcc30c898269ddb2fcfff846544a077059d10b (diff) | |
download | SCons-4814146dc3f69729e22f89078a5783a82e9df039.zip SCons-4814146dc3f69729e22f89078a5783a82e9df039.tar.gz SCons-4814146dc3f69729e22f89078a5783a82e9df039.tar.bz2 |
test cleanups: use harness python
In a few places, a command line was built to execute a wrapper
script written in Python, but the Python used was not the one used
to invoke the test run (which is made available by TestSCons), but
the result of running test.where_is('python'). On a system which
still has the thing named 'python' resolve to Python 2, this fails,
through no fault of scons itself.
The two fixture wrapper scripts used occasionally by the tests
used subprocess.call; this is considered "old" though not marked
as deprecated at this time. Switched to subprocess.run. See:
https://docs.python.org/3/library/subprocess.html#older-high-level-api
One of these scripts was doing unnecessary bytes-twiddling.
Modernized the inline myswig.py script (in test/SWIG/SWIG.py).
This script was reformatted using Black along the way.
Signed-off-by: Mats Wichmann <mats@linux.com>
Diffstat (limited to 'test/SWIG/SWIG.py')
-rw-r--r-- | test/SWIG/SWIG.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/test/SWIG/SWIG.py b/test/SWIG/SWIG.py index 31bc7d7..625b5f1 100644 --- a/test/SWIG/SWIG.py +++ b/test/SWIG/SWIG.py @@ -35,19 +35,19 @@ _obj = TestSCons._obj test = TestSCons.TestSCons() -python = test.where_is('python') -if not python: - test.skip_test('Can not find installed "python", skipping test.\n') +_python_ = TestSCons._python_ - -test.write('myswig.py', r""" +test.write('myswig.py', """\ import getopt import sys -opts, args = getopt.getopt(sys.argv[1:], 'c:o:v:') + +opts, args = getopt.getopt(sys.argv[1:], "c:o:v:") for opt, arg in opts: - if opt == '-c': pass - elif opt == '-o': out = arg - elif opt == '-v' and arg == 'ersion': + if opt == "-c": + pass + elif opt == "-o": + out = arg + elif opt == "-v" and arg == "ersion": print("") print("SWIG Version 0.1.2") print("") @@ -55,23 +55,23 @@ for opt, arg in opts: print("") print("Configured options: +pcre") print("") - print("Please see http://www.swig.org for reporting bugs and further information") + print("Please see http://www.swig.org for reporting bugs " + "and further information") sys.exit(0) -infile = open(args[0], 'r') -outfile = open(out, 'w') -for l in infile.readlines(): - if l[:4] != 'swig': - outfile.write(l) + +with open(args[0], "r") as ifp, open(out, "w") as ofp: + for line in ifp: + if not line.startswith("swig"): + ofp.write(line) sys.exit(0) """) -test.write('SConstruct', """ -env = Environment(tools=['default', 'swig'], - SWIG = [r'%(python)s', 'myswig.py']) +test.write('SConstruct', """\ +env = Environment(tools=["default", "swig"], SWIG=[r"%(_python_)s", "myswig.py"]) print(env.subst("Using SWIG $SWIGVERSION")) -env.Program(target = 'test1', source = 'test1.i') -env.CFile(target = 'test2', source = 'test2.i') -env.Clone(SWIGFLAGS = '-c++').Program(target = 'test3', source = 'test3.i') +env.Program(target="test1", source="test1.i") +env.CFile(target="test2", source="test2.i") +env.Clone(SWIGFLAGS="-c++").Program(target="test3", source="test3.i") """ % locals()) test.write('test1.i', r""" |