Skip to content

Commit

Permalink
add rye scripts for code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
deltheil committed Jan 29, 2024
1 parent 1efb7a0 commit cd64bb2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ wandb/

# lock files
requirements-dev.lock

# coverage.py
htmlcov/
.coverage
.coverage.*
12 changes: 12 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit cd64bb2

Please sign in to comment.