Skip to content

Commit

Permalink
[SCons] Extend coverage option to Python module
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and bryanwweber committed Aug 11, 2022
1 parent 25c5174 commit 47b9d67
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -45,5 +45,6 @@ environment.y*
*.gch
coverage/
coverage.info
.coverage
doc/sphinx/matlab/*.rst
!doc/sphinx/matlab/index.rst
7 changes: 6 additions & 1 deletion interfaces/cython/SConscript
Expand Up @@ -88,12 +88,17 @@ license = localenv.Command("LICENSE.txt", "#build/ext/LICENSE.txt",
Copy("$TARGET", "$SOURCE"))
localenv.Depends(license, localenv["license_target"])

directives = {}
if env["coverage"]:
directives["linetrace"] = True
localenv.Append(CPPDEFINES={"CYTHON_TRACE": 1})

# Build the Python module
cython_obj = []
for pyxfile in multi_glob(localenv, "cantera", "pyx"):
cythonized = localenv.Command(
f"cantera/{pyxfile.name.replace('.pyx', '.cpp')}", pyxfile,
'''${python_cmd} -c "import Cython.Build; Cython.Build.cythonize(r'${SOURCE}')"'''
f'''${{python_cmd}} -c "import Cython.Build; Cython.Build.cythonize(r'${{SOURCE}}', compiler_directives={directives!r})"'''
)
for pxd in multi_glob(localenv, "cantera", "pxd"):
localenv.Depends(cythonized, pxd)
Expand Down
2 changes: 2 additions & 0 deletions test/SConscript
Expand Up @@ -145,6 +145,8 @@ def addPythonTest(testname, subdir, script, interpreter,
cmdargs.insert(0, "show_long")
if env["verbose_tests"]:
cmdargs.insert(0, "verbose")
if env["coverage"]:
cmdargs.insert(0, "coverage")
if env["skip_slow_tests"]:
environ["CT_SKIP_SLOW"] = "1"

Expand Down
6 changes: 6 additions & 0 deletions test/python/coverage.ini
@@ -0,0 +1,6 @@
[run]
plugins = Cython.Coverage
omit =
*.cti
stringsource
source = ../../build/python/cantera
7 changes: 6 additions & 1 deletion test/python/runCythonTests.py
Expand Up @@ -38,7 +38,6 @@
from pathlib import Path

CANTERA_ROOT = Path(__file__).parents[2]
os.chdir(str(CANTERA_ROOT / "test" / "work"))

try:
import pytest
Expand All @@ -62,6 +61,7 @@
fast_fail = False
show_long = False
verbose = False
coverage = False
if "fast_fail" in sys.argv:
fast_fail = True
subset_start += 1
Expand All @@ -71,6 +71,9 @@
if "verbose" in sys.argv:
verbose = True
subset_start += 1
if "coverage" in sys.argv:
coverage = True
subset_start += 1

base = CANTERA_ROOT / "test" / "python"
subsets = []
Expand All @@ -85,6 +88,8 @@
pytest_args += ["--durations=50"]
if fast_fail:
pytest_args.insert(0, "-x")
if coverage:
pytest_args.extend(["--cov=cantera", "--cov-config=test/python/coverage.ini"])
if verbose:
pytest_args.insert(0, "-v")
else:
Expand Down

0 comments on commit 47b9d67

Please sign in to comment.