Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Commit

Permalink
fix: use coverage:paths to rewrite paths in coverage files (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Chianelli authored May 31, 2024
1 parent 518c371 commit deb60d1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 237 deletions.
16 changes: 0 additions & 16 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,11 @@ jobs:
working-directory: ./timefold-solver-python
run: mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:get -Dartifact=org.jacoco:org.jacoco.agent:0.8.11:jar:runtime -Ddest=target/jacocoagent.jar
- name: Run tox to measure timefold solver python code coverage from Python tests
continue-on-error: true # Sometimes the JVM segfaults on SUCCESSFUL tests with Java 17 (and always with Java 11)
working-directory: ./timefold-solver-python
run: python -m tox -- --cov=timefold --cov-report=xml:target/coverage.xml --cov-config=tox.ini --cov-branch --cov-append --jacoco-agent=./target/jacocoagent.jar
- name: Run tox to measure jpyinterpreter code coverage from Python tests
continue-on-error: true # Sometimes the JVM segfaults on SUCCESSFUL tests with Java 17 (and always with Java 11)
working-directory: ./timefold-solver-python/jpyinterpreter
run: python -m tox -- --cov=jpyinterpreter --cov-report=xml:target/coverage.xml --cov-config=tox.ini --cov-branch --cov-append --jacoco-agent=../target/jacocoagent.jar --jacoco-output=../target/jacoco.exec
# Because we are using JPype, and JPype add it own import hook, we need to use --import-mode=importlib in pytest
# This seems to create an issue in test coverage, where it reports coverage inside the tox virtual environment,
# instead of coverage inside sources. For instance, for a package, it will report:
# package name=".tox.py39.lib.python3.9.site-packages.jpyinterpreter"
# and for a file it will report:
# class name="jvm_setup.py" filename=".tox/py39/lib/python3.9/site-packages/jpyinterpreter/jvm_setup.py"
# We need to convert the package and file names into their true names; i.e. for the example above:
# package name="jpyinterpreter"
# class name="jvm_setup.py" filename="jpyinterpreter/src/main/python/jvm_setup.py"
# fix-coverage-paths.py is a Python script that does the above transformation for us and merge the two
# separate coverage files into one.
- name: Fix Python test coverage paths
working-directory: ./timefold-solver-python
run: python fix-coverage-paths.py
- name: Run SonarCloud analysis
working-directory: ./timefold-solver-python
env:
Expand Down
220 changes: 0 additions & 220 deletions fix-coverage-paths.py

This file was deleted.

5 changes: 5 additions & 0 deletions jpyinterpreter/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ deps =
JPype1>=1.5.0
commands =
pytest --import-mode=importlib {posargs}

[coverage:paths]
source =
src/main/python
**/jpyinterpreter
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<sonar.sources>src/main/java,src/main/python</sonar.sources>
<sonar.tests>src/test/java,tests</sonar.tests>
<sonar.python.version>3.9,3.10,3.11</sonar.python.version>
<sonar.python.coverage.reportPaths>target/coverage.xml</sonar.python.coverage.reportPaths>
<sonar.python.coverage.reportPaths>target/coverage.xml,jpyinterpreter/target/coverage.xml</sonar.python.coverage.reportPaths>
</properties>

<dependencyManagement>
Expand Down
5 changes: 5 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ deps =
JPype1>=1.5.0
commands =
pytest --import-mode=importlib {posargs} tests

[coverage:paths]
source =
timefold-solver-python-core/src/main/python
**/timefold/solver

0 comments on commit deb60d1

Please sign in to comment.