tests: add type annotations to IoT tests#1685
Open
ZeliardM wants to merge 2 commits intopython-kasa:masterfrom
Open
tests: add type annotations to IoT tests#1685ZeliardM wants to merge 2 commits intopython-kasa:masterfrom
ZeliardM wants to merge 2 commits intopython-kasa:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves static type checking for the IoT test suite by adding explicit -> None return annotations to test functions (sync + async), which enables mypy to type-check their bodies more thoroughly under --check-untyped-defs.
Changes:
- Added
-> Nonereturn annotations to 71 test functions acrosstests/iot/(8 files). - Addressed a handful of newly-exposed mypy issues via targeted variable annotations and more appropriate test doubles (e.g., using
Mock()instead ofNone). - Added a concrete type annotation for
test_dataintest_usage_convert_stat_datato satisfy mypy’svar-annotatedrequirement.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/iot/test_wallswitch.py | Adds -> None to the wallswitch motion test function. |
| tests/iot/test_iottimezone.py | Adds -> None to async/sync timezone-related unit tests. |
| tests/iot/test_iotstrip.py | Adds -> None to async strip behavior tests. |
| tests/iot/test_iotlightstrip.py | Adds -> None to async lightstrip tests and one sync device type test. |
| tests/iot/test_iotdimmer.py | Adds -> None to async dimmer tests and one sync device type test. |
| tests/iot/test_iotdevice.py | Adds -> None broadly to device tests; annotates dict vars to avoid mypy narrowing issues. |
| tests/iot/modules/test_usage.py | Adds -> None; replaces None with Mock() for Usage constructor; adds variable annotations for mypy. |
| tests/iot/modules/test_emeter.py | Adds -> None; annotates inline emeter_data dict to avoid mypy union/narrowing issues. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1685 +/- ##
=======================================
Coverage 93.22% 93.22%
=======================================
Files 157 157
Lines 9815 9815
Branches 1003 1003
=======================================
Hits 9150 9150
Misses 472 472
Partials 193 193 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add `-> None` return types and parameter type annotations to all test functions across 8 files in `tests/iot/`. Parameter annotations added: - `dev` typed to match fixture (IotDevice, IotDimmer, IotLightStrip, IotStrip, IotWallSwitch) - `mocker: MockerFixture` throughout - `turn_on: bool` for turn_on fixture - `brightness: int`, `transition: int` for parametrized values Fix mypy errors exposed by the new annotations: - Annotate reassigned `dest`/`source` dicts in `test_merge_dict` - Annotate `emeter_data` dicts to allow nested list access - Replace `None` with `Mock()` in `Usage()` constructor call - Add `list[dict[str, int]]` annotation to `test_data` variable - Add `isinstance(child, IotStripPlug)` narrowing for strip children - Suppress intentional attr-defined/arg-type errors with type: ignore
afb61d8 to
37b2b00
Compare
This was referenced Apr 7, 2026
This was referenced Apr 7, 2026
Add -> None return types and parameter type annotations to 7 previously uncovered test files in tests/iot/ and tests/iot/modules/: - tests/iot/test_iotbulb.py (17 functions) - tests/iot/modules/test_ambientlight.py (3 functions) - tests/iot/modules/test_cloud.py (1 function) - tests/iot/modules/test_dimmer.py (6 functions + fix missing setup vars) - tests/iot/modules/test_homekit.py (3 functions) - tests/iot/modules/test_motion.py (7 functions) - tests/iot/modules/test_schedule.py (1 function) Also fixes pre-existing bugs in test_dimmer.py where 4 test functions referenced undefined variables (dimmer, query_helper, test_threshold).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add
-> Nonereturn type annotations and parameter type annotations to all test functions across 8 files intests/iot/, improving type safety and enabling mypy to check function bodies.Changes
Annotations added (71 functions across 8 files):
tests/iot/test_iotdevice.py— 23 functionstests/iot/test_iotdimmer.py— 11 functionstests/iot/test_iotlightstrip.py— 7 functionstests/iot/test_iotstrip.py— 3 functionstests/iot/test_iottimezone.py— 13 functionstests/iot/test_wallswitch.py— 1 functiontests/iot/modules/test_emeter.py— 10 functionstests/iot/modules/test_usage.py— 3 functionsParameter type annotations added to all test functions:
dev: IotDevice,dev: IotDimmer,dev: IotLightStrip,dev: IotStrip,dev: IotWallSwitch)mocker: MockerFixture,turn_on: bool,brightness: int,transition: int)MockerFixture,IotStrip,IotWallSwitch,IotStripPlug,IotDeviceMypy fixes (exposed by the new annotations):
dest/sourcedicts intest_merge_dictasdictto prevent narrowed-type conflicts on reassignmentemeter_datadicts intest_emeter_daily,test_usage_today, andtest_usage_this_monthasdictto allow.append()/.extend()on nested lists (union withintfromerr_code)NonewithMock()inUsage()constructor call (arg-type)list[dict[str, int]]annotation totest_datavariable (var-annotated)isinstancenarrowing forIotStripPlugchildren accessFiles changed (8)
tests/iot/test_iotdevice.py,tests/iot/test_iotdimmer.py,tests/iot/test_iotlightstrip.py,tests/iot/test_iotstrip.py,tests/iot/test_iottimezone.py,tests/iot/test_wallswitch.py,tests/iot/modules/test_emeter.py,tests/iot/modules/test_usage.pyMerge order
This is PR 6 of 9 in the test modernization series. No file overlaps with other PRs.
Verification
mypy tests/iot/→ 0 errors