Skip to content

Commit df96ca4

Browse files
committed
Add comprehensive coverage reporting and thresholds
1 parent b6118db commit df96ca4

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
strategy:
99
matrix:
1010
os: [ubuntu-latest, windows-latest]
11-
python-version: ["3.9", "3.10", "3.11", "3.12"]
11+
python-version: ['3.9', '3.10', '3.11', '3.12']
1212

1313
steps:
1414
- uses: actions/checkout@v3
@@ -18,7 +18,7 @@ jobs:
1818
with:
1919
python-version: ${{ matrix.python-version }}
2020
architecture: x64
21-
cache: "pip"
21+
cache: 'pip'
2222

2323
- name: Install Poetry manager
2424
run: pip install --upgrade poetry
@@ -28,4 +28,64 @@ jobs:
2828

2929
- name: Test with pytest
3030
run: |
31-
poetry run pytest --cov=transloadit tests
31+
poetry run pytest --cov=transloadit \
32+
--cov-report=xml \
33+
--cov-report=term-missing \
34+
--cov-fail-under=65 \
35+
tests
36+
37+
- name: Upload coverage reports
38+
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
39+
uses: codecov/codecov-action@v4
40+
with:
41+
token: ${{ secrets.CODECOV_TOKEN }}
42+
files: ./coverage.xml
43+
flags: unittests
44+
name: python-sdk
45+
fail_ci_if_error: true
46+
47+
coverage:
48+
needs: python
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v3
52+
53+
- name: Set up Python
54+
uses: actions/setup-python@v4
55+
with:
56+
python-version: '3.12'
57+
architecture: x64
58+
cache: 'pip'
59+
60+
- name: Install Poetry manager
61+
run: pip install --upgrade poetry
62+
63+
- name: Install Dependencies
64+
run: poetry install
65+
66+
- name: Generate coverage report
67+
run: |
68+
poetry run pytest --cov=transloadit \
69+
--cov-report=json \
70+
--cov-report=html \
71+
tests
72+
73+
- name: Check coverage thresholds
74+
run: |
75+
COVERAGE=$(poetry run coverage report | grep TOTAL | awk '{print $4}' | sed 's/%//')
76+
THRESHOLD=65
77+
78+
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
79+
echo "Coverage ($COVERAGE%) is below threshold ($THRESHOLD%)"
80+
exit 1
81+
else
82+
echo "Coverage ($COVERAGE%) meets threshold ($THRESHOLD%)"
83+
fi
84+
85+
- name: Upload coverage artifacts
86+
uses: actions/upload-artifact@v4
87+
with:
88+
name: coverage-reports
89+
path: |
90+
coverage.json
91+
htmlcov/

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![Build status](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml/badge.svg)](https://github.com/transloadit/python-sdk/actions/workflows/ci.yml)
2+
[![Coverage](https://codecov.io/gh/transloadit/python-sdk/branch/main/graph/badge.svg)](https://codecov.io/gh/transloadit/python-sdk)
23

34
# Transloadit python-sdk
45

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

4445
See [readthedocs](https://transloadit.readthedocs.io) for full API documentation.
46+
47+
## Development
48+
49+
### Testing
50+
51+
Run tests with:
52+
53+
```bash
54+
poetry run pytest
55+
```
56+
57+
### Code Coverage
58+
59+
We maintain code coverage to ensure reliability. The current minimum coverage threshold is 65%.
60+
61+
Coverage reports are:
62+
63+
- Generated locally in the `htmlcov` directory
64+
- Uploaded to Codecov for tracking
65+
- Enforced in CI (builds will fail if coverage drops below threshold)
66+
67+
View the coverage report locally by opening `htmlcov/index.html` in your browser.
68+
69+
Generate a coverage report with:
70+
71+
```bash
72+
poetry run pytest --cov=transloadit --cov-report=html tests
73+
```

pyproject.toml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[tool.poetry]
22
name = "pytransloadit"
33
version = "1.0.0"
4-
description = "A Python Integration for Transloadits file uploading and encoding service."
4+
description = "A Python Integration for Transloadit's file uploading and encoding service."
55
authors = ["Ifedapo Olarewaju"]
66
maintainers = ["Florian Kuenzig", "Arnaud Limbourg"]
77
license = "MIT"
@@ -44,3 +44,24 @@ sphinx-autobuild = "^2021.3.14"
4444
[build-system]
4545
requires = ["poetry-core"]
4646
build-backend = "poetry.core.masonry.api"
47+
48+
[tool.pytest.ini_options]
49+
addopts = "--cov=transloadit --cov-report=term-missing"
50+
testpaths = ["tests"]
51+
52+
[tool.coverage.run]
53+
source = ["transloadit"]
54+
branch = true
55+
56+
[tool.coverage.report]
57+
exclude_lines = [
58+
"pragma: no cover",
59+
"def __repr__",
60+
"if self.debug:",
61+
"raise NotImplementedError",
62+
"if __name__ == .__main__.:",
63+
"pass",
64+
"raise ImportError",
65+
]
66+
ignore_errors = true
67+
fail_under = 65

0 commit comments

Comments
 (0)