test: implement unit testing suite with pytest and add pre-push verification hook
This commit is contained in:
@@ -230,21 +230,45 @@ docker buildx build --platform linux/amd64,linux/arm64 -t strava-mcp-server:test
|
||||
|
||||
### 5. Git Hooks
|
||||
|
||||
A `pre-commit` hook is provided to automatically run `ruff check` on staged Python files before every commit, catching linting errors before they enter the history.
|
||||
Two hooks are provided in `scripts/hooks/` — install them both after cloning:
|
||||
|
||||
The hook is stored in the repository under `scripts/hooks/` for easy installation.
|
||||
|
||||
**Install the hook:**
|
||||
```bash
|
||||
cp scripts/hooks/pre-commit .git/hooks/pre-commit
|
||||
chmod +x .git/hooks/pre-commit
|
||||
cp scripts/hooks/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
|
||||
cp scripts/hooks/pre-push .git/hooks/pre-push && chmod +x .git/hooks/pre-push
|
||||
```
|
||||
|
||||
**Behaviour:**
|
||||
- ✅ Commit proceeds if `ruff check` passes on all staged `.py` files.
|
||||
- ❌ Commit is aborted if any linting errors are found.
|
||||
- 🔧 Auto-fix lint issues with `uv run ruff check --fix`.
|
||||
- ⚡ Bypass for emergencies: `git commit --no-verify`.
|
||||
#### `pre-commit` — Lint & Format check
|
||||
Runs on staged `.py` files before every commit.
|
||||
- 🔍 `ruff check` — linting
|
||||
- 🎨 `ruff format --check` — formatting
|
||||
- 🔧 Fix: `uv run ruff check --fix` + `uv run ruff format`
|
||||
- ⚡ Bypass: `git commit --no-verify`
|
||||
|
||||
#### `pre-push` — Unit tests
|
||||
Runs the full unit test suite before every push.
|
||||
- 🧪 `pytest tests/unit/ -q`
|
||||
- ⚡ Bypass: `git push --no-verify`
|
||||
|
||||
### 6. Unit Tests
|
||||
|
||||
Fast, offline unit tests for pure functions and MCP helpers (no Strava API required).
|
||||
|
||||
```bash
|
||||
# Run all unit tests
|
||||
uv run pytest tests/unit/ -v
|
||||
|
||||
# Run with coverage (if pytest-cov is installed)
|
||||
uv run pytest tests/unit/ --cov=strava_mcp_server
|
||||
```
|
||||
|
||||
**Test coverage:**
|
||||
| Module | Tests |
|
||||
|--------|-------|
|
||||
| `utils.py` — `parse_iso_to_unix` | `None`, empty, invalid, UTC, offset, date-only |
|
||||
| `utils.py` — `format_date_iso` | Normalization, `None`, datetime object, invalid |
|
||||
| `utils.py` — `format_date_human` | German format, `None`, datetime object, regex pattern |
|
||||
| `tools/*` — `_resource()` | Type, mimeType, URI, JSON validity, audience |
|
||||
| `tools/*` — `_user_text()` | Type, text value, audience |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user