Skip to content

Commit

Permalink
chore: enable code coverage (#143)
Browse files Browse the repository at this point in the history
## Reason for Change
enable code coverage to help maintain a high coding standard

# Changes
- enable code coverage to the python api and ontology-builder
- combine the coverage reports and submit to codecoverage.
- setup a GHA run to run codecoverge for prs and main
  • Loading branch information
Bento007 authored Mar 25, 2024
1 parent 162f323 commit c52c436
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 3 deletions.
48 changes: 46 additions & 2 deletions .github/workflows/push-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ jobs:
pip install -r requirements-dev.txt
- name: Ontology builder unit tests
run: |
cd tools/ontology-builder && make unit-tests
cd tools/ontology-builder
make coverage/run
- name: Upload coverage results as an artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: /home/runner/work/cellxgene-ontology-guide/cellxgene-ontology-guide/.coverage*
retention-days: 3

unit-test-python-api:
runs-on: ubuntu-latest
Expand All @@ -78,4 +85,41 @@ jobs:
- name: Python API unit tests
run: |
cd api/python
make unit-tests
make coverage/run
- name: Upload coverage results as an artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: /home/runner/work/cellxgene-ontology-guide/cellxgene-ontology-guide/.coverage*
retention-days: 3

submit-codecoverage:
needs:
- unit-test-ontology-builder
- unit-test-python-api
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.11
- name: install coverage
run: pip install coverage
- uses: actions/download-artifact@v3
with:
name: coverage
path: .
- name: coverage report
run: |
make coverage/report-xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
env_vars: OS,PYTHON
files: ./coverage.xml
flags: unittests
name: codecov-umbrella
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
/api/python/LICENSE
/api/python/src/cellxgene_ontology_guide/data/
/api/python/dist/
.coverage*
/htmlcov/
/api/python/docs/
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
include tools/coverage.mk

lint:
pre-commit run --all-files
2 changes: 2 additions & 0 deletions api/python/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include ../../tools/coverage.mk

install: package-data
pip install .

Expand Down
3 changes: 2 additions & 1 deletion api/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ requires-python = "~= 3.10"
dependencies = ["semantic_version>=2.10.0,<3"]

[project.optional-dependencies]
test = ["pytest"]
test = ["pytest", "coverage"]

[tool.setuptools.packages.find]
where = ["src"]
Expand All @@ -30,3 +30,4 @@ root = "../.." # relative to the location of the pyproject.toml file

[tool.pytest.ini_options]
pythonpath = ["src/cellxgene_ontology_guide"]

17 changes: 17 additions & 0 deletions tools/coverage.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# shared coverage targets
REPO_ROOT := $(shell git rev-parse --show-toplevel)
COVERAGE_DATA_FILE=.coverage.$(shell git rev-parse --short HEAD)
export COVERAGE_RUN_ARGS:=--data-file=$(REPO_ROOT)/$(COVERAGE_DATA_FILE) --branch --parallel-mode


coverage/run:
coverage run $(COVERAGE_RUN_ARGS) -m pytest ./tests;

coverage/combine:
coverage combine --data-file=$(COVERAGE_DATA_FILE)

coverage/report-xml: coverage/combine
coverage xml --data-file=$(COVERAGE_DATA_FILE) -i --skip-empty

coverage/report-html: coverage/combine
coverage html --data-file=$(COVERAGE_DATA_FILE) -i --skip-empty
2 changes: 2 additions & 0 deletions tools/ontology-builder/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include ../coverage.mk

unit-tests:
python -m pytest tests

Expand Down
1 change: 1 addition & 0 deletions tools/ontology-builder/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
coverage

0 comments on commit c52c436

Please sign in to comment.