Skip to content

🐍 Geometric Computer Vision Library for Spatial AI

add coverage CI (#2551)

João Gustavo A. Amorim204aba05dff3
diff --git a/.codecov.yml b/.codecov.yml
index 7b1a7928e..e14f5709b 100644
--- a/.codecov.yml
+++ b/.codecov.yml
@@ -13,7 +13,7 @@ codecov:
wait_for_ci: yes
coverage:
- precision: 0 # 2 = xx.xx%, 0 = xx%
+ precision: 2 # 2 = xx.xx%, 0 = xx%
round: nearest # how coverage is rounded: down/up/nearest
range: 70...100 # custom range of coverage colors from red -> yellow -> green
status:
@@ -21,16 +21,16 @@ coverage:
project:
default:
against: auto
- target: 99% # specify the target coverage for each commit status
- threshold: 30% # allow this little decrease on project
+ target: 87% # The target should be the same of the pyproject `fail_under`
+ # threshold: 30% # allow this little decrease on project
# https://github.com/codecov/support/wiki/Filtering-Branches
# branches: master
if_ci_failed: error
# https://github.com/codecov/support/wiki/Patch-Status
- patch:
+ patch: # is the coverage percentage of the number of lines touched in your patch (the git diff)
default:
against: auto
- target: 50% # specify the target "X%" coverage to hit
+ target: 87% # The target should be the same of the pyproject `fail_under`
# threshold: 50% # allow this much decrease on patch
changes: false
diff --git a/.github/workflows/pr_test_cpu.yml b/.github/workflows/pr_test_cpu.yml
index a17e24bf1..c140752f0 100644
--- a/.github/workflows/pr_test_cpu.yml
+++ b/.github/workflows/pr_test_cpu.yml
@@ -34,6 +34,15 @@ jobs:
pytorch-version: '["1.9.1", "2.0.1"]'
pytorch-dtype: 'float64'
+ tests-coverage:
+ uses: ./.github/workflows/tests.yml
+ with:
+ python-version: '["3.10"]'
+ pytorch-version: '["2.0.1"]'
+ pytorch-dtype: 'float32,float64'
+ coverage: true
+ continue-on-error: true
+
test-typing:
uses: ./.github/workflows/test_typing.yml
@@ -41,7 +50,7 @@ jobs:
uses: ./.github/workflows/test_tutorials.yml
collector:
- needs: [tests-cpu, tests-cpu-fp64, test-tutorials, test-typing]
+ needs: [tests-cpu, tests-cpu-fp64, test-tutorials, test-typing, tests-coverage]
if: always()
runs-on: ubuntu-latest
steps:
diff --git a/.github/workflows/scheduled_test_cpu.yml b/.github/workflows/scheduled_test_cpu.yml
index 5fed9ad60..85015f818 100644
--- a/.github/workflows/scheduled_test_cpu.yml
+++ b/.github/workflows/scheduled_test_cpu.yml
@@ -54,3 +54,12 @@ jobs:
test-typing:
uses: ./.github/workflows/test_typing.yml
+
+ tests-coverage:
+ uses: ./.github/workflows/tests.yml
+ with:
+ python-version: '["3.10"]'
+ pytorch-version: '["2.0.1"]'
+ pytorch-dtype: 'float32,float64'
+ coverage: true
+ continue-on-error: true
diff --git a/.github/workflows/test_typing.yml b/.github/workflows/test_typing.yml
index fb9c3f305..c450fab94 100644
--- a/.github/workflows/test_typing.yml
+++ b/.github/workflows/test_typing.yml
@@ -47,11 +47,11 @@ jobs:
shell: bash -l {0}
run: mypy --cobertura-xml-report ./
- - if: always()
- name: Upload typing coverage
- uses: codecov/codecov-action@v3
- with:
- file: cobertura.xml
- token: ${{ secrets.CODECOV_TOKEN }} # to not depend on build via GH API
- flags: typing,${{ inputs.os }}_py-${{ matrix.python-version }}_pt-${{ matrix.pytorch-version }}_${{ inputs.pytorch-dtype }}
- name: cpu-coverage-types
+ # - if: always()
+ # name: Upload typing coverage
+ # uses: codecov/codecov-action@v3
+ # with:
+ # file: cobertura.xml
+ # token: ${{ secrets.CODECOV_TOKEN }} # to not depend on build via GH API
+ # flags: typing,${{ inputs.os }}_py-${{ matrix.python-version }}_pt-${{ matrix.pytorch-version }}_${{ inputs.pytorch-dtype }}
+ # name: cpu-coverage-types
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index a39c8f269..ebbec227e 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -29,6 +29,10 @@ on:
required: false
type: boolean
default: false
+ coverage:
+ required: false
+ type: boolean
+ default: false
jobs:
tests:
@@ -55,12 +59,28 @@ jobs:
python-version: ${{ matrix.python-version }}
pytorch-version: ${{ matrix.pytorch-version }}
- - name: Run CPU tests ${{ inputs.pytorch-dtype }}
+ - if: ${{ inputs.coverage == false}}
+ name: Run CPU tests ${{ inputs.pytorch-dtype }}
+ continue-on-error: ${{ inputs.continue-on-error }}
+ shell: bash -l {0}
+ run: pytest -v --device cpu --dtype ${{ inputs.pytorch-dtype }} ${{ inputs.pytest-extra }} ./test
+
+ - if: ${{ inputs.coverage }}
+ name: Run CPU tests coverage ${{ inputs.pytorch-dtype }}
continue-on-error: ${{ inputs.continue-on-error }}
shell: bash -l {0}
- run: pytest -v --device cpu --dtype ${{ inputs.pytorch-dtype }} ${{ inputs.pytest-extra }} --cov=kornia --cov-report xml ./test
+ run: |
+ coverage erase
+ coverage run -m pytest -v --device cpu --dtype ${{ inputs.pytorch-dtype }} ${{ inputs.pytest-extra }} ./test
+
+ - if: ${{ inputs.coverage }}
+ name: Coverage report
+ shell: bash -l {0}
+ run: |
+ coverage xml -o coverage.xml # Generate the xml for the codecov
+ coverage report # Print the report
- - if: always()
+ - if: ${{ inputs.coverage }}
name: Upload coverage
uses: codecov/codecov-action@v3
with:
diff --git a/Makefile b/Makefile
index a7bbe494c..220311b37 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,9 @@ test-quick: FORCE
test-slow: FORCE
pytest -v --device all --dtype all -m "(jit or grad or nn)"
+test-coverage: FORCE
+ coverage erase && coverage run --source kornia/ -m pytest --device=all --dtype float32,float64 test/ && coverage report
+
lint: FORCE
pre-commit run ruff --all-files
diff --git a/pyproject.toml b/pyproject.toml
index 62be8eca5..da06efbc5 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -170,14 +170,46 @@ requires = [
"nn: mark a test as module test"
]
+[tool.coverage.run]
+branch = true
+source = [
+ 'kornia/',
+]
+omit = [
+ '*/__main__.py',
+ '*/setup.py',
+]
+
[tool.coverage.report]
-exclude_lines = [
- "def __repr__",
- "if __name__ == .__main__.:",
- "if 0:",
- "if self.debug:",
- "pragma: no cover",
- "raise",
+show_missing = true
+skip_covered = true
+fail_under = 87
+exclude_lines =[
+ # Based into the covdefaults plugin config
+ # a more strict default pragma
+ '\# pragma: no cover\b',
+
+ # allow defensive code
+ '^\s*raise AssertionError\b',
+ '^\s*raise NotImplementedError\b',
+ '^\s*return NotImplemented\b',
+ '^\s*raise$',
+
+ # typing-related code
+ '^\s*if (False|TYPE_CHECKING):',
+ ': \.\.\.(\s*#.*)?$',
+ '^ +\.\.\.$',
+
+ # ----------------------------
+ "def __repr__",
+ "if __name__ == .__main__.:",
+ "if 0:",
+ "if self.debug:",
+]
+
+partial_branches = [
+ # a more strict default pragma
+ '\# pragma: no cover\b',
]
[tool.mypy]
diff --git a/requirements/requirements-dev.txt b/requirements/requirements-dev.txt
index 1bf85f643..4b02eabcf 100644
--- a/requirements/requirements-dev.txt
+++ b/requirements/requirements-dev.txt
@@ -1,3 +1,4 @@
+coverage
kornia-rs==0.0.8
mypy[reports]
numpy
@@ -6,5 +7,4 @@ opencv-python
pre-commit>=2
pydocstyle
pytest==7.4.2
-pytest-cov==4.1.0
scipy