Commit 2ba88a2
authored
Increase test coverage to 98%: add comprehensive unit tests for client/device, retries, and export paths
## Summary
- Raises repository test coverage from ~81% to 98%
- Adds 45+ targeted unit tests across `fmd_api.client` and `fmd_api.device`
- Focuses on previously untested error paths, retry/backoff logic, and export edge cases
- No production code changes; tests only
## What changed
- New tests in `tests/unit/test_coverage_improvements.py`:
- Authentication flow: salt retrieval, password hashing, access token, private key decryption
- Retry/backoff: 429 with Retry-After, 500/502/503/504, connection errors, jitter/no-jitter backoff
- JSON parsing fallbacks: non-JSON responses, empty body, missing keys
- Export ZIP: PNG/JPEG detection, default jpg fallback for unknown formats, decrypt errors
- Device edge cases: photo download decode errors, internal guards
- Utilities: token masking, Retry-After parsing, streaming responses
- Coverage artifacts: `coverage.xml` generated for Codecov
## Why
- Address Codecov alerts and improve confidence in critical paths (auth, I/O, error handling)
- Reduce regressions by covering negative and edge scenarios
## Metrics
- Before: ~81% total coverage (`client.py` ~77%, `device.py` ~94%)
- After: 98% total coverage (`client.py` ~97%, `device.py` 100%)
- Tests: 104 tests passing locally
## Compatibility
- Breaking changes: None
- Public API changes: None
- Dependencies: No new runtime dependencies
## How to validate locally (optional)
```powershell
# From repo root (Windows PowerShell)
python -m pytest tests/unit --cov=fmd_api --cov-report=term-missing --cov-branch
```
## Notes and follow-ups
- Remaining uncovered lines are hard-to-trigger branches in `client.py` (e.g., specific fallback/log-only segments): `353–358`, `368`, `392–393`, `477–478`, `563`, `717–718`
- Reaching 100% would likely require deeper `aiohttp` response mocking or small refactors to expose those branches for deterministic testing; can be tackled in a follow-up if desired
## Checklist
- [x] All unit tests pass locally
- [x] Coverage ≥ 95% (actual: 98%)
- [x] No production code changes
- [x] `coverage.xml` updated for CI/Codecov1 file changed
+1
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
0 commit comments