From 16dcbc795ee9550c7e2cccaf76a3a336bce307dc Mon Sep 17 00:00:00 2001 From: Aleksa Perovic Date: Mon, 10 Nov 2025 21:51:05 +0100 Subject: [PATCH 1/2] feat: add python coverage --- .github/workflows/javaTests.yml | 1 + .github/workflows/python.yml | 92 ++++++++++++++++++- README.md | 3 +- src/main/python/.coveragerc | 28 ++++++ src/main/python/tests/federated/runFedTest.sh | 2 +- 5 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 src/main/python/.coveragerc diff --git a/.github/workflows/javaTests.yml b/.github/workflows/javaTests.yml index d7797e5f4a3..afb765c1e64 100644 --- a/.github/workflows/javaTests.yml +++ b/.github/workflows/javaTests.yml @@ -156,6 +156,7 @@ jobs: with: fail_ci_if_error: false files: target/site/jacoco/jacoco.xml + flags: java token: ${{ secrets.CODECOV_TOKEN }} - name: Upload Jacoco Report Artifact PR diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index fcd8bf8c849..f622e07acce 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -112,6 +112,7 @@ jobs: requests \ pandas \ unittest-parallel \ + coverage - name: Build Python Package run: | @@ -126,14 +127,16 @@ jobs: export SYSDS_QUIET=1 export LOG4JPROP=$SYSTEMDS_ROOT/src/test/resources/log4j.properties cd src/main/python - unittest-parallel -t . -s tests -v + unittest-parallel -t . -s tests -v --coverage + mv .coverage .coverage.${{ matrix.test_mode }} - name: Run tests no env if: ${{ matrix.test_mode == 'noenv' }} run: | export LOG4JPROP=$(pwd)/src/test/resources/log4j.properties cd src/main/python - unittest-parallel -t . -s tests -v + unittest-parallel -t . -s tests -v --coverage + mv .coverage .coverage.${{ matrix.test_mode }} - name: Run Federated Python Tests if: ${{ matrix.test_mode == 'federated' }} @@ -142,6 +145,7 @@ jobs: export PATH=$SYSTEMDS_ROOT/bin:$PATH cd src/main/python ./tests/federated/runFedTest.sh + mv .coverage .coverage.${{ matrix.test_mode }} - name: Cache Torch Hub if: ${{ matrix.test_mode == 'scuro' }} @@ -175,4 +179,86 @@ jobs: fvcore kill $KA cd src/main/python - python -m unittest discover -s tests/scuro -p 'test_*.py' -v + coverage run -m unittest discover -s tests/scuro -p 'test_*.py' -v + mv .coverage .coverage.${{ matrix.test_mode }} + + - name: Save Python Test Coverage as Artifact + uses: actions/upload-artifact@v5 + with: + name: .coverage.${{ matrix.test_mode }} + include-hidden-files: true + path: ${{ github.workspace }}/src/main/python/.coverage.${{ matrix.test_mode }} + retention-days: 1 + + determine_test_coverage: + name: Determine Test Coverage + runs-on: ${{ matrix.os }} + needs: [ + test + ] + strategy: + fail-fast: false + matrix: + python-version: [3.8] + os: [ubuntu-24.04] + + steps: + - name: Checkout Repository + uses: actions/checkout@v5 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + architecture: 'x64' + + - name: Install coverage package + run: | + pip install --upgrade pip + pip install coverage + + - name: Download all Python Coverage Artifacts + uses: actions/download-artifact@v6 + with: + pattern: .coverage.* + path: ${{ github.workspace }}/src/main/python/ + + - name: Merge Python Coverage Reports + run: | + cd src/main/python + coverage combine .coverage.* + coverage xml -o coverage.xml + + - name: Upload merged coverage report to Codecov + uses: codecov/codecov-action@v5.5.1 + if: github.repository_owner == 'apache' + with: + fail_ci_if_error: false + files: src/main/python/coverage.xml + flags: python + name: coverage.xml + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Upload Coverage Report Artifact PR + if: (github.repository_owner == 'apache') && (github.ref_name != 'main') + uses: actions/upload-artifact@v5 + with: + name: coverage.xml + path: src/main/python/coverage.xml + retention-days: 7 + + - name: Upload Coverage Report Artifact Main + if: (github.repository_owner == 'apache') && (github.ref_name == 'main') + uses: actions/upload-artifact@v5 + with: + name: coverage.xml + path: src/main/python/coverage.xml + retention-days: 30 + + - name: Upload Coverage Report Artifact Fork + if: (github.repository_owner != 'apache') + uses: actions/upload-artifact@v5 + with: + name: coverage.xml + path: src/main/python/coverage.xml + retention-days: 3 diff --git a/README.md b/README.md index 0f948786165..1c72a98e5a0 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ To build from source visit [SystemDS Install from source](https://apache.github. [![Documentation](https://github.com/apache/systemds/actions/workflows/documentation.yml/badge.svg?branch=main)](https://github.com/apache/systemds/actions/workflows/documentation.yml) [![LicenseCheck](https://github.com/apache/systemds/actions/workflows/license.yml/badge.svg?branch=main)](https://github.com/apache/systemds/actions/workflows/license.yml) [![Java Tests](https://github.com/apache/systemds/actions/workflows/javaTests.yml/badge.svg?branch=main)](https://github.com/apache/systemds/actions/workflows/javaTests.yml) -[![codecov](https://codecov.io/gh/apache/systemds/graph/badge.svg?token=4YfvX8s6Dz)](https://codecov.io/gh/apache/systemds) +[![Java Coverage](https://codecov.io/gh/apache/systemds/graph/badge.svg?token=4YfvX8s6Dz&flag=java)](https://codecov.io/gh/apache/systemds) [![Python Test](https://github.com/apache/systemds/actions/workflows/python.yml/badge.svg?branch=main)](https://github.com/apache/systemds/actions/workflows/python.yml) +[![Python Coverage](https://codecov.io/gh/apache/systemds/graph/badge.svg?token=4YfvX8s6Dz&flag=python)](https://codecov.io/gh/apache/systemds) [![Total PyPI downloads](https://static.pepy.tech/personalized-badge/systemds?units=abbreviation&period=total&left_color=grey&right_color=blue&left_text=Total%20PyPI%20Downloads)](https://pepy.tech/project/systemds) [![Monthly PyPI downloads](https://static.pepy.tech/personalized-badge/systemds?units=abbreviation&left_color=grey&right_color=blue&left_text=Monthly%20PyPI%20Downloads)](https://pepy.tech/project/systemds) diff --git a/src/main/python/.coveragerc b/src/main/python/.coveragerc new file mode 100644 index 00000000000..b02765b80f9 --- /dev/null +++ b/src/main/python/.coveragerc @@ -0,0 +1,28 @@ +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + +[run] +omit = + ; omit files generated by opencv-python, see https://github.com/coveragepy/coveragepy/issues/1653 + config.py + config-3.py + ; omit pytorch-generated files in /tmp + /tmp/* diff --git a/src/main/python/tests/federated/runFedTest.sh b/src/main/python/tests/federated/runFedTest.sh index d37c044ed2b..2e58d5efd3e 100755 --- a/src/main/python/tests/federated/runFedTest.sh +++ b/src/main/python/tests/federated/runFedTest.sh @@ -48,7 +48,7 @@ Fed3=$! echo "Starting workers" && sleep 6 && echo "Starting tests" # Run test -python -m unittest discover -s tests/federated -p 'test_*.py' $1 >$log 2>&1 +coverage run -m unittest discover -s tests/federated -p 'test_*.py' $1 >$log 2>&1 pkill -P $Fed1 pkill -P $Fed2 pkill -P $Fed3 From f22338856391b9f94cff642a44765a381ed8f6cd Mon Sep 17 00:00:00 2001 From: Aleksa Perovic Date: Mon, 17 Nov 2025 16:38:31 +0100 Subject: [PATCH 2/2] fix: ignore .torch/ for coverage --- src/main/python/.coveragerc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/python/.coveragerc b/src/main/python/.coveragerc index b02765b80f9..d0afc346d7e 100644 --- a/src/main/python/.coveragerc +++ b/src/main/python/.coveragerc @@ -24,5 +24,6 @@ omit = ; omit files generated by opencv-python, see https://github.com/coveragepy/coveragepy/issues/1653 config.py config-3.py - ; omit pytorch-generated files in /tmp + ; omit pytorch-generated files /tmp/* + **/.torch/*