[SCons] Add options to run subsets of the Python test suite
New test targets are automatically generated from the test_foo.py scripts, with the new targets named like 'cython2-test-foo'.
This commit is contained in:
parent
a8e884d34e
commit
7e64056082
2 changed files with 57 additions and 22 deletions
|
|
@ -54,7 +54,8 @@ def addTestProgram(subdir, progName):
|
|||
[], [Delete(passedFile.abspath)]))
|
||||
|
||||
|
||||
def addTestScript(testname, subdir, script, interpreter, dependencies=(), env_vars={}):
|
||||
def addTestScript(testname, subdir, script, interpreter, args='',
|
||||
dependencies=(), env_vars={}, optional=False):
|
||||
"""
|
||||
Create targets for running and resetting a test script.
|
||||
"""
|
||||
|
|
@ -70,7 +71,7 @@ def addTestScript(testname, subdir, script, interpreter, dependencies=(), env_va
|
|||
for k,v in env_vars.iteritems():
|
||||
print k,v
|
||||
environ[k] = v
|
||||
code = subprocess.call([env.subst(interpreter), source[0].abspath],
|
||||
code = subprocess.call([env.subst(interpreter), source[0].abspath] + args.split(),
|
||||
env=environ,
|
||||
cwd=workDir)
|
||||
if not code:
|
||||
|
|
@ -90,7 +91,8 @@ def addTestScript(testname, subdir, script, interpreter, dependencies=(), env_va
|
|||
if isinstance(dep, str):
|
||||
dep = File(pjoin(subdir, dep))
|
||||
testenv.Depends(run_program, dep)
|
||||
Alias('test', run_program)
|
||||
if not optional:
|
||||
Alias('test', run_program)
|
||||
if os.path.exists(passedFile.abspath):
|
||||
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, testname),
|
||||
[], [Delete(passedFile.abspath)]))
|
||||
|
|
@ -153,26 +155,45 @@ def addMatlabTest(script, testName, dependencies=None, env_vars=()):
|
|||
addTestProgram('thermo', 'thermo')
|
||||
addTestProgram('kinetics', 'kinetics')
|
||||
|
||||
python_subtests = ['']
|
||||
test_root = '#interfaces/cython/cantera/test'
|
||||
for f in mglob(localenv, test_root, '^test_*.py'):
|
||||
python_subtests.append(f.name[5:-3])
|
||||
|
||||
if localenv['python_package'] == 'full':
|
||||
pyTest = addTestScript('cython2', 'python', 'runCythonTests.py',
|
||||
interpreter='$python_cmd',
|
||||
dependencies=(localenv['python2_module'] +
|
||||
localenv['python2_extension'] +
|
||||
mglob(localenv, '#interfaces/cython/cantera/test', 'py')),
|
||||
env_vars={'PYTHONPATH':Dir('#build/python2').abspath})
|
||||
localenv.Alias('test-cython2', pyTest)
|
||||
env['testNames'].append('cython2')
|
||||
# Create test aliases for individual test modules (e.g. test-cython2-thermo;
|
||||
# not run as part of the main suite) and a single test runner with all the
|
||||
# tests (test-cython2) for the main suite.
|
||||
for subset in python_subtests:
|
||||
name = 'cython2-' + subset if subset else 'cython2'
|
||||
pyTest = addTestScript(name, 'python', 'runCythonTests.py',
|
||||
args=subset,
|
||||
interpreter='$python_cmd',
|
||||
dependencies=(localenv['python2_module'] +
|
||||
localenv['python2_extension'] +
|
||||
mglob(localenv, test_root, 'py')),
|
||||
env_vars={'PYTHONPATH':Dir('#build/python2').abspath},
|
||||
optional=bool(subset))
|
||||
localenv.Alias('test-' + name, pyTest)
|
||||
env['testNames'].append(name)
|
||||
|
||||
if localenv['python3_package'] == 'y':
|
||||
pyTest = addTestScript('cython3', 'python', 'runCythonTests.py',
|
||||
interpreter='$python3_cmd',
|
||||
dependencies=(localenv['python3_module'] +
|
||||
localenv['python3_extension'] +
|
||||
mglob(localenv, '#interfaces/cython/cantera/test', 'py')),
|
||||
env_vars={'PYTHONPATH':Dir('#build/python3').abspath,
|
||||
'PYTHON_CMD': localenv.subst('$python3_cmd')})
|
||||
localenv.Alias('test-cython3', pyTest)
|
||||
env['testNames'].append('cython3')
|
||||
# Create test aliases for individual test modules (e.g. test-cython3-thermo;
|
||||
# not run as part of the main suite) and a single test runner with all the
|
||||
# tests (test-cython3) for the main suite.
|
||||
for subset in python_subtests:
|
||||
name = 'cython3-' + subset if subset else 'cython3'
|
||||
pyTest = addTestScript('cython3', 'python', 'runCythonTests.py',
|
||||
interpreter='$python3_cmd',
|
||||
args=subset,
|
||||
dependencies=(localenv['python3_module'] +
|
||||
localenv['python3_extension'] +
|
||||
mglob(localenv, test_root, 'py')),
|
||||
env_vars={'PYTHONPATH':Dir('#build/python3').abspath,
|
||||
'PYTHON_CMD': localenv.subst('$python3_cmd')},
|
||||
optional=bool(subset))
|
||||
localenv.Alias('test-' + name, pyTest)
|
||||
env['testNames'].append(name)
|
||||
|
||||
if localenv['matlab_toolbox'] == 'y':
|
||||
if localenv['python_package'] in ('full', 'minimal'):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@
|
|||
Unit tests for Cantera's Cython-based Python module.
|
||||
|
||||
This script gathers all the tests defined 'cantera.test' module, runs them,
|
||||
and prints a report.
|
||||
and prints a report. Extra command line arguments can be used to run subsets
|
||||
of the test suite, e.g.
|
||||
|
||||
python runCythonTests.py thermo kinetics
|
||||
python runCythonTests.py onedim reactor
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
|
|
@ -17,6 +21,7 @@ else:
|
|||
|
||||
from cantera.test.utilities import unittest
|
||||
import cantera
|
||||
import cantera.test
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('\n* INFO: using Cantera module found at this location:')
|
||||
|
|
@ -25,7 +30,16 @@ if __name__ == '__main__':
|
|||
|
||||
loader = unittest.TestLoader()
|
||||
runner = unittest.TextTestRunner(verbosity=2)
|
||||
suite = loader.loadTestsFromName('cantera.test')
|
||||
suite = unittest.TestSuite()
|
||||
subsets = []
|
||||
for name in dir(cantera.test):
|
||||
if name.startswith('test_') and name[5:] in sys.argv:
|
||||
subsets.append('cantera.test.' + name)
|
||||
|
||||
if not subsets:
|
||||
subsets.append('cantera.test')
|
||||
|
||||
suite = loader.loadTestsFromNames(subsets)
|
||||
|
||||
results = runner.run(suite)
|
||||
sys.exit(len(results.errors) + len(results.failures))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue