Skip to content

Commit 1ebe765

Browse files
committed
Add code coverage tooling
1 parent 74780f0 commit 1ebe765

File tree

7 files changed

+303
-13
lines changed

7 files changed

+303
-13
lines changed

.coveragerc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[run]
2+
branch = True
3+
source = src/stac_auth_proxy
4+
omit =
5+
*/tests/*
6+
*/test_*
7+
*/__pycache__/*
8+
*/venv/*
9+
*/build/*
10+
*/dist/*
11+
*/htmlcov/*
12+
*/lambda.py
13+
*/__main__.py
14+
15+
[report]
16+
exclude_lines =
17+
pragma: no cover
18+
def __repr__
19+
if self.debug:
20+
if settings.DEBUG
21+
raise AssertionError
22+
raise NotImplementedError
23+
if 0:
24+
if __name__ == .__main__.:
25+
class .*\bProtocol\):
26+
@(abc\.)?abstractmethod
27+
# Have to re-enable the standard pragma
28+
pragma: no cover
29+
30+
[html]
31+
directory = htmlcov
32+
33+
[xml]
34+
output = coverage.xml

.github/workflows/cicd.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,21 @@ jobs:
2929
- uses: astral-sh/setup-uv@v4
3030
with:
3131
enable-cache: true
32-
- run: uv run pytest -n auto
32+
- name: Run tests with coverage
33+
run: |
34+
uv run pytest -n auto --cov=src/stac_auth_proxy --cov-report=xml --cov-report=html --cov-report=term-missing --cov-fail-under=85
35+
- name: Upload coverage reports to Codecov
36+
uses: codecov/codecov-action@v4
37+
with:
38+
file: ./coverage.xml
39+
flags: unittests
40+
name: codecov-umbrella
41+
fail_ci_if_error: false
42+
- name: Archive coverage reports
43+
uses: actions/upload-artifact@v4
44+
if: always()
45+
with:
46+
name: coverage-reports
47+
path: |
48+
htmlcov/
49+
coverage.xml

.pre-commit-config.yaml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,24 @@
11
repos:
22
- repo: https://github.com/abravalheri/validate-pyproject
3-
rev: v0.23
3+
rev: v0.24.1
44
hooks:
55
- id: validate-pyproject
66

7-
- repo: https://github.com/psf/black
8-
rev: 22.12.0
9-
hooks:
10-
- id: black
11-
language_version: python
12-
137
- repo: https://github.com/PyCQA/isort
14-
rev: 5.12.0
8+
rev: 6.0.1
159
hooks:
1610
- id: isort
1711
language_version: python
1812

1913
- repo: https://github.com/charliermarsh/ruff-pre-commit
20-
rev: v0.0.238
14+
rev: v0.12.11
2115
hooks:
22-
- id: ruff
16+
- id: ruff-check
2317
args: ["--fix"]
18+
- id: ruff-format
2419

2520
- repo: https://github.com/pre-commit/mirrors-mypy
26-
rev: v1.3.0
21+
rev: v1.17.1
2722
hooks:
2823
- id: mypy
2924
language_version: python

Makefile

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
.PHONY: help test test-coverage test-fast lint format clean install dev-install
2+
3+
help: ## Show this help message
4+
@echo "Available commands:"
5+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
6+
7+
install: ## Install the package
8+
uv sync
9+
10+
dev-install: ## Install development dependencies
11+
uv sync --group dev
12+
13+
test: ## Run tests
14+
uv run pytest
15+
16+
test-fast: ## Run tests in parallel
17+
uv run pytest -n auto
18+
19+
test-coverage: ## Run tests with coverage
20+
@echo "🧪 Running tests with coverage..."
21+
uv run pytest \
22+
--cov=src/stac_auth_proxy \
23+
--cov-report=term-missing \
24+
--cov-report=html \
25+
--cov-report=xml \
26+
--cov-fail-under=85 \
27+
-v
28+
@echo "✅ Coverage report generated!"
29+
@echo "📊 HTML report available at: htmlcov/index.html"
30+
@echo "📄 XML report available at: coverage.xml"
31+
@if [ "$(CI)" = "true" ]; then \
32+
echo "🚀 Running in CI environment"; \
33+
else \
34+
echo "💻 Running locally - opening HTML report..."; \
35+
if command -v open >/dev/null 2>&1; then \
36+
open htmlcov/index.html; \
37+
elif command -v xdg-open >/dev/null 2>&1; then \
38+
xdg-open htmlcov/index.html; \
39+
else \
40+
echo "Please open htmlcov/index.html in your browser to view the coverage report"; \
41+
fi; \
42+
fi
43+
44+
lint: ## Run linting
45+
uv run pre-commit run ruff-check --all-files
46+
uv run pre-commit run mypy --all-files
47+
48+
format: ## Format code
49+
uv run pre-commit run ruff-format --all-files
50+
51+
clean: ## Clean up generated files
52+
rm -rf htmlcov/
53+
rm -rf .coverage
54+
rm -rf coverage.xml
55+
rm -rf .pytest_cache/
56+
rm -rf build/
57+
rm -rf dist/
58+
rm -rf *.egg-info/
59+
find . -type d -name __pycache__ -delete
60+
find . -type f -name "*.pyc" -delete
61+
62+
ci: ## Run CI checks locally
63+
uv run pre-commit run --all-files
64+
@echo "🧪 Running tests with coverage..."
65+
uv run pytest \
66+
--cov=src/stac_auth_proxy \
67+
--cov-report=term-missing \
68+
--cov-report=html \
69+
--cov-report=xml \
70+
--cov-fail-under=85 \
71+
-v
72+
@echo "✅ CI checks completed!"

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
[![PyPI - Version][pypi-version-badge]][pypi-link]
99
[![GHCR - Version][ghcr-version-badge]][ghcr-link]
1010
[![GHCR - Size][ghcr-size-badge]][ghcr-link]
11+
[![codecov][codecov-badge]][codecov-link]
12+
[![Tests][tests-badge]][tests-link]
1113

1214
STAC Auth Proxy is a proxy API that mediates between the client and your internally accessible STAC API to provide flexible authentication, authorization, and content-filtering mechanisms.
1315

@@ -37,3 +39,7 @@ Head to [Getting Started](https://developmentseed.org/stac-auth-proxy/user-guide
3739
[ghcr-version-badge]: https://ghcr-badge.egpl.dev/developmentseed/stac-auth-proxy/latest_tag?color=%2344cc11&ignore=latest&label=image+version&trim=
3840
[ghcr-size-badge]: https://ghcr-badge.egpl.dev/developmentseed/stac-auth-proxy/size?color=%2344cc11&tag=latest&label=image+size&trim=
3941
[ghcr-link]: https://github.com/developmentseed/stac-auth-proxy/pkgs/container/stac-auth-proxy
42+
[codecov-badge]: https://codecov.io/gh/developmentseed/stac-auth-proxy/branch/main/graph/badge.svg
43+
[codecov-link]: https://codecov.io/gh/developmentseed/stac-auth-proxy
44+
[tests-badge]: https://github.com/developmentseed/stac-auth-proxy/actions/workflows/cicd.yaml/badge.svg
45+
[tests-link]: https://github.com/developmentseed/stac-auth-proxy/actions/workflows/cicd.yaml

pyproject.toml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,43 @@ lambda = [
4242

4343
[tool.coverage.run]
4444
branch = true
45+
source = ["src/stac_auth_proxy"]
46+
omit = [
47+
"*/tests/*",
48+
"*/test_*",
49+
"*/__pycache__/*",
50+
"*/venv/*",
51+
"*/build/*",
52+
"*/dist/*",
53+
"*/htmlcov/*",
54+
"*/lambda.py", # Lambda entry point not tested in unit tests
55+
]
56+
57+
[tool.coverage.report]
58+
exclude_lines = [
59+
"pragma: no cover",
60+
"def __repr__",
61+
"if self.debug:",
62+
"if settings.DEBUG",
63+
"raise AssertionError",
64+
"raise NotImplementedError",
65+
"if 0:",
66+
"if __name__ == .__main__.:",
67+
"class .*\\bProtocol\\):",
68+
"@(abc\\.)?abstractmethod",
69+
]
70+
71+
[tool.coverage.html]
72+
directory = "htmlcov"
73+
74+
[tool.coverage.xml]
75+
output = "coverage.xml"
4576

4677
[tool.isort]
4778
known_first_party = ["stac_auth_proxy"]
4879
profile = "black"
4980

50-
[tool.ruff]
81+
[tool.ruff.lint]
5182
ignore = ["E501", "D203", "D205", "D212"]
5283
select = ["D", "E", "F"]
5384

@@ -58,14 +89,38 @@ requires = ["hatchling>=1.12.0"]
5889
[dependency-groups]
5990
dev = [
6091
"jwcrypto>=1.5.6",
92+
"mypy>=1.3.0",
6193
"pre-commit>=3.5.0",
6294
"pytest-asyncio>=0.25.1",
6395
"pytest-cov>=5.0.0",
6496
"pytest-xdist>=3.6.1",
6597
"pytest>=8.3.3",
98+
"ruff>=0.0.238",
6699
"starlette-cramjam>=0.4.0",
100+
"types-simplejson",
101+
"types-attrs",
67102
]
68103

69104
[tool.pytest.ini_options]
70105
asyncio_default_fixture_loop_scope = "function"
71106
asyncio_mode = "auto"
107+
testpaths = ["tests"]
108+
python_files = ["test_*.py", "*_test.py"]
109+
python_classes = ["Test*"]
110+
python_functions = ["test_*"]
111+
addopts = [
112+
"--strict-markers",
113+
"--strict-config",
114+
"--verbose",
115+
"--tb=short",
116+
"--cov=src/stac_auth_proxy",
117+
"--cov-report=term-missing",
118+
"--cov-report=html",
119+
"--cov-report=xml",
120+
"--cov-fail-under=85",
121+
]
122+
markers = [
123+
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
124+
"integration: marks tests as integration tests",
125+
"unit: marks tests as unit tests",
126+
]

0 commit comments

Comments
 (0)