Skip to content

Increase test coverage to 98%: add comprehensive unit tests for client/device, retries, and export paths#5

Merged
devinslick merged 1 commit intomainfrom
increase-code-test-coverage
Nov 6, 2025
Merged

Increase test coverage to 98%: add comprehensive unit tests for client/device, retries, and export paths#5
devinslick merged 1 commit intomainfrom
increase-code-test-coverage

Conversation

@devinslick
Copy link
Copy Markdown
Owner

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)

# 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

  • All unit tests pass locally
  • Coverage ≥ 95% (actual: 98%)
  • No production code changes
  • coverage.xml updated for CI/Codecov

Copilot AI review requested due to automatic review settings November 6, 2025 16:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR updates the version number of the fmd_api package from 2.0.1 to 2.0.2, indicating a patch release.

  • Version bump from 2.0.1 to 2.0.2 in the project metadata

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@devinslick devinslick merged commit 2ba88a2 into main Nov 6, 2025
29 of 31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants