add rye scripts for code coverage

This commit is contained in:
Cédric Deltheil 2024-01-27 18:32:40 +00:00 committed by Cédric Deltheil
parent 1efb7a0e10
commit cd64bb29e6
3 changed files with 29 additions and 0 deletions

5
.gitignore vendored
View file

@ -32,3 +32,8 @@ wandb/
# lock files
requirements-dev.lock
# coverage.py
htmlcov/
.coverage
.coverage.*

View file

@ -68,3 +68,15 @@ You can enforce running tests on CPU. Tests that require a GPU will be skipped.
```bash
REFINERS_TEST_DEVICE=cpu rye run pytest
```
You can collect [code coverage](https://github.com/nedbat/coveragepy) data while running tests with, e.g.:
```bash
rye run test-cov
```
Then, browse the corresponding HTML report with:
```bash
rye run serve-cov-report
```

View file

@ -69,6 +69,11 @@ allow-direct-references = true
[tool.rye.scripts]
lint = { chain = ["ruff format .", "ruff --fix ."] }
serve-docs = "mkdocs serve"
test-cov = "coverage run -m pytest"
# Work around for "Couldn't parse" errors due to e.g. opencv-python:
# https://github.com/nedbat/coveragepy/issues/1653
build-html-cov = { cmd = "coverage html", env = { PYTHONWARNINGS = "ignore:Couldn't parse::coverage.report_core" } }
serve-cov-report = { chain = ["build-html-cov", "python -m http.server 8080 -b 127.0.0.1 -d htmlcov"]}
[tool.black]
line-length = 120
@ -99,3 +104,10 @@ include = ["src/refiners", "tests", "scripts"]
strict = ["*"]
exclude = ["**/__pycache__", "tests/weights"]
reportMissingTypeStubs = "warning"
[tool.coverage.run]
branch = true
# Also apply to HTML output, where appropriate
[tool.coverage.report]
ignore_errors = true # see `build-html-cov` for details