Skip to content

Commit

Permalink
Add comprehensive coverage reporting and thresholds
Browse files Browse the repository at this point in the history
  • Loading branch information
kvz committed Nov 27, 2024
1 parent b6118db commit df96ca4
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 4 deletions.
66 changes: 63 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ['3.9', '3.10', '3.11', '3.12']

steps:
- uses: actions/checkout@v3
Expand All @@ -18,7 +18,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: "pip"
cache: 'pip'

- name: Install Poetry manager
run: pip install --upgrade poetry
Expand All @@ -28,4 +28,64 @@ jobs:

- name: Test with pytest
run: |
poetry run pytest --cov=transloadit tests
poetry run pytest --cov=transloadit \
--cov-report=xml \
--cov-report=term-missing \
--cov-fail-under=65 \
tests
- name: Upload coverage reports
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
flags: unittests
name: python-sdk
fail_ci_if_error: true

coverage:
needs: python
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
architecture: x64
cache: 'pip'

- name: Install Poetry manager
run: pip install --upgrade poetry

- name: Install Dependencies
run: poetry install

- name: Generate coverage report
run: |
poetry run pytest --cov=transloadit \
--cov-report=json \
--cov-report=html \
tests
- name: Check coverage thresholds
run: |
COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//')
THRESHOLD=65
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)"
exit 1
else
echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)"
fi
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: coverage-reports
path: |
coverage.json
htmlcov/
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![Build status](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml)
[![Coverage](https://codecov.io/gh/transloadit/python-sdk/branch/main/graph/badge.svg)](https://codecov.io/gh/transloadit/python-sdk)

# Transloadit python-sdk

Expand Down Expand Up @@ -42,3 +43,31 @@ For fully working examples, take a look at [`examples/`](https://github.com/tran
## Documentation

See [readthedocs](https://transloadit.readthedocs.io) for full API documentation.

## Development

### Testing

Run tests with:

```bash
poetry run pytest
```

### Code Coverage

We maintain code coverage to ensure reliability. The current minimum coverage threshold is 65%.

Coverage reports are:

- Generated locally in the `htmlcov` directory
- Uploaded to Codecov for tracking
- Enforced in CI (builds will fail if coverage drops below threshold)

View the coverage report locally by opening `htmlcov/index.html` in your browser.

Generate a coverage report with:

```bash
poetry run pytest --cov=transloadit --cov-report=html tests
```
23 changes: 22 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "pytransloadit"
version = "1.0.0"
description = "A Python Integration for Transloadits file uploading and encoding service."
description = "A Python Integration for Transloadit's file uploading and encoding service."
authors = ["Ifedapo Olarewaju"]
maintainers = ["Florian Kuenzig", "Arnaud Limbourg"]
license = "MIT"
Expand Down Expand Up @@ -44,3 +44,24 @@ sphinx-autobuild = "^2021.3.14"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
addopts = "--cov=transloadit --cov-report=term-missing"
testpaths = ["tests"]

[tool.coverage.run]
source = ["transloadit"]
branch = true

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"raise NotImplementedError",
"if __name__ == .__main__.:",
"pass",
"raise ImportError",
]
ignore_errors = true
fail_under = 65

0 comments on commit df96ca4

Please sign in to comment.