Skip to content

Add pytest test suite with 96% coverage and GitHub Actions CI - #4

Open
geofffranks wants to merge 4 commits into
LF2b2w:mainfrom
geofffranks:test-coverage-90
Open

Add pytest test suite with 96% coverage and GitHub Actions CI#4
geofffranks wants to merge 4 commits into
LF2b2w:mainfrom
geofffranks:test-coverage-90

Conversation

@geofffranks

@geofffranks geofffranks commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replaces the broken tests/test_utec.py (wrong imports, references to non-existent methods like _api_call/_discover and UtecOAuth2 which lives in the HA integration, not this library) with a working pytest suite across 10 new test files covering API transport, device classes, auth, exceptions, and constants.
  • Adds pytest-asyncio + coverage configuration in pyproject.toml with a fail_under = 90 gate, plus a pinned requirements-test.txt and a rewritten tests/conftest.py providing shared fixtures (mock_api, discovery_dict, state_payload, _FakeAuth).
  • Adds a GitHub Actions workflow (.github/workflows/test.yml) that runs the suite with coverage on push to main and on all pull requests, across a Python 3.11 / 3.12 matrix.
  • Current result: 126 tests passing in ~0.8s, 96% total line coverage. Per-module: api.py/auth.py/const.py/exceptions.py 100%, light.py 99%, lock.py 98%, device.py 96%, switch.py 94%, device_const.py 87%.

Test Plan

  • pip install -e . -r requirements-test.txt
  • pytest tests/ — expect 126 passed, 0 failed
  • pytest tests/ --cov=utec_py --cov-report=term-missing — expect ≥90% overall, all required modules ≥90%
  • Confirm the new CI workflow triggers and goes green on this PR
  • Spot-check a few tests for structure (e.g. tests/test_api.py for HTTP transport via aioresponses, tests/test_lock.py for device state assertions)

Notes for Maintainers

  • Zero src/ changes. Several tests adapt to observed source behavior rather than "correcting" it — for example LockState/DoorState enum values are title case, BaseDevice.update wraps errors as DeviceError, battery_level maps integer keys {1→10, 2→30, 3→50, 4→70, 5→100}, and DeviceError inherits directly from Exception rather than UHomeError. These are documented inline where relevant.
  • docs/superpowers/plans/ contains the implementation plan and source audit used to produce this branch. They are process artifacts — feel free to squash them out of the merge if you prefer a cleaner history.
  • Known non-blocking simplification: tests/test_api.py defines its own _FakeAuth subclass that duplicates the one in tests/conftest.py. Both work; consolidation can be done in a follow-up if desired.

@geofffranks

Copy link
Copy Markdown
Collaborator Author

Sorry for the terseness in the PR notes, and plethora of commits, Claude got a bit much there.

Essentially - Adds a ton of test coverage to bring the overall coverage up to 96%. This also adds a github action for auto-running the tests for PRs and for commits to the main branch. As such didn't want to push/merge directly without checking with you first on this one @LF2b2w.

@geofffranks

Copy link
Copy Markdown
Collaborator Author

Ah, also it looks like branch protection + reviewer requirements effectively prevent me from merging/pushing on my own anyway. If that was intended and i misinterpreted, no worried, just mentioning in case.

@geofffranks
geofffranks force-pushed the test-coverage-90 branch 2 times, most recently from 090375c to 2570e30 Compare July 8, 2026 15:16
@geofffranks

Copy link
Copy Markdown
Collaborator Author

@LF2b2w bumping this PR as well

LF2b2w and others added 4 commits August 20, 2026 22:57
Squash of the geofffranks/utec-py fork divergence: simplified Auth,
device class restructuring, corrected switch/light/lock command payloads
and state reading, HA lock state wording, plus a full unit-test suite
(transport, Lock, Light, Switch, BaseDevice) and CI running pytest with
coverage on push to main and all PRs.

Tracked by tk up-jgns.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants