Skip to content

Commit

Permalink
[SCons] Refactor to eliminate runCythonTests.py
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and bryanwweber committed Aug 11, 2022
1 parent 72734b1 commit c039a0d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 127 deletions.
64 changes: 33 additions & 31 deletions test/SConscript
Expand Up @@ -118,14 +118,14 @@ def addTestProgram(subdir, progName, env_vars={}):
[], [Delete(passedFile.abspath)]))


def addPythonTest(testname, subdir, script, interpreter,
args="", dependencies=(), env_vars={}, optional=False):
def addPythonTest(testname, subset):
"""
Create targets for running and resetting a test script.
"""

def scriptRunner(target, source, env):
"""Scons Action to run a set of tests using pytest """
pytest_outfile = File("#test/work/pytest.xml").abspath
"""Scons Action to run a test script using the specified interpreter"""
workDir = Dir('#test/work').abspath
passedFile = target[0]
test_results.tests.pop(passedFile.name, None)
Expand All @@ -135,25 +135,31 @@ def addPythonTest(testname, subdir, script, interpreter,
os.remove(pytest_outfile)

environ = dict(env['ENV'])
for k,v in env_vars.items():
environ[k] = v
if env["skip_slow_tests"]:
environ["CT_SKIP_SLOW"] = "1"

cmdargs = args.split()
cmd = [env.subst("$python_cmd"), "-m", "pytest", "-raP",
"--junitxml=test/work/pytest.xml"]
if env["fast_fail_tests"]:
cmdargs.insert(0, "fast_fail")
cmd.append("-x")
if env["show_long_tests"]:
cmdargs.insert(0, "show_long")
cmd.append("--durations=50")

if env["verbose_tests"]:
cmdargs.insert(0, "verbose")
cmd.append("-v")
else:
cmd.append("--log-level=ERROR")

if env["coverage"]:
cmdargs.insert(0, "coverage")
if env["skip_slow_tests"]:
environ["CT_SKIP_SLOW"] = "1"
cmd.extend([
"--cov=cantera",
"--cov-config=test/python/coverage.ini",
"--cov-report=xml:build/pycov.xml",
"--cov-report=html:build/python-coverage"
])

code = subprocess.call(cmd + [str(s) for s in source], env=environ)

code = subprocess.call(
[env.subst(interpreter), source[0].abspath] + cmdargs,
env=environ
)
if not code:
# Test was successful
with open(target[0].path, 'w') as passed_file:
Expand Down Expand Up @@ -182,19 +188,21 @@ def addPythonTest(testname, subdir, script, interpreter,
' ***no results for entire test suite***'] = 100

testenv = localenv.Clone()
passedFile = File(pjoin(subdir, '%s.passed' % testname))
passedFile = File(f'python/{name}.passed')
PASSED_FILES[testname] = str(passedFile)

run_program = testenv.Command(passedFile, pjoin('#test', subdir, script), scriptRunner)
for dep in dependencies:
if isinstance(dep, str):
dep = File(pjoin(subdir, dep))
testenv.Depends(run_program, dep)
if not optional:
if subset:
test_files = [f"python/test_{subset}.py"]
else:
test_files = multi_glob(localenv, "python", "^test_*.py")
run_program = testenv.Command(passedFile, test_files, scriptRunner)
testenv.Depends(run_program, localenv["python_module"])
testenv.Depends(run_program, localenv["python_extension"])
if not subset:
testenv.Depends(env['test_results'], run_program)
test_results.tests[passedFile.name] = True
if os.path.exists(passedFile.abspath):
Alias('test-reset', testenv.Command('reset-%s%s' % (subdir, testname),
Alias("test-reset", testenv.Command(f"reset-python{testname}",
[], [Delete(passedFile.abspath)]))

return run_program
Expand Down Expand Up @@ -298,13 +306,7 @@ if localenv['python_package'] == 'full':
# tests (test-python) for the main suite.
for subset in python_subtests:
name = 'python-' + subset if subset else 'python'
pyTest = addPythonTest(
name, 'python', 'runCythonTests.py',
args=subset,
interpreter='$python_cmd',
dependencies=(localenv['python_module'] + localenv['python_extension'] +
multi_glob(localenv, test_root, 'py')),
optional=bool(subset))
pyTest = addPythonTest(name, subset=subset)
localenv.Alias('test-' + name, pyTest)
env['testNames'].append(name)

Expand Down
96 changes: 0 additions & 96 deletions test/python/runCythonTests.py

This file was deleted.

0 comments on commit c039a0d

Please sign in to comment.