Skip to content

tests: add type annotations to CLI, protocol, and smartcam tests#1687

Open
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM:tests/cli-protocols-smartcam-type-annotations
Open

tests: add type annotations to CLI, protocol, and smartcam tests#1687
ZeliardM wants to merge 1 commit intopython-kasa:masterfrom
ZeliardM:tests/cli-protocols-smartcam-type-annotations

Conversation

@ZeliardM
Copy link
Copy Markdown
Contributor

@ZeliardM ZeliardM commented Apr 7, 2026

Summary

Add type annotations (-> None return types and parameter types) to test files in the tests/cli/, tests/protocols/, and tests/smartcam/ directories. This enables mypy to check test function bodies, catching type errors that were previously hidden.

Changes

Return types:

  • Added -> None to all test functions across 11 files

Parameter types:

  • cli tests: dev: Device, runner: CliRunner, caplog: pytest.LogCaptureFixture, mocker: MockerFixture
  • test_iotprotocol.py: mocker: MockerFixture, transport_class: type[XorTransport] / type[BaseTransport], protocol_class: type[BaseProtocol] (where type-safe), caplog: pytest.LogCaptureFixture, log_level: int, retry_count: int
  • test_smartprotocol.py: dummy_protocol: SmartProtocol, mocker: MockerFixture, batch_size: int, error_code: SmartErrorCode / int, list_sum: int, request_size: int
  • smartcam tests: raw: str | None, expected: float | None, protocol_filter: set[str] | None, fixture_name: str

Mypy fixes:

  • Added # type: ignore[misc] for intentional __init__ introspection in signature tests
  • Added # type: ignore[attr-defined] for runtime-only deprecated TPLinkSmartHomeProtocol import
  • Annotated mock_response: dict to fix indexing error from heterogeneous dict literal
  • Left encryption_class/encrypt_class/decrypt_class and some protocol_class params untyped (duck-typed parametrized values with no common interface)

Files changed (11)

tests/cli/test_hub.py, tests/cli/test_vacuum.py, tests/protocols/test_iotprotocol.py, tests/protocols/test_smartprotocol.py, tests/smartcam/modules/test_alarm.py, tests/smartcam/modules/test_battery.py, tests/smartcam/modules/test_camera.py, tests/smartcam/modules/test_childsetup.py, tests/smartcam/modules/test_detections.py, tests/smartcam/modules/test_pantilt.py, tests/smartcam/test_smartcamdevice.py

Merge order

This is PR 8 of 9 in the test modernization series. No file overlaps with other PRs.

Order PR Scope
1 #1677 Tests: cleanup and fixes
2 #1681 CI: pin GitHub Actions to SHA
3 #1682 Docs: modernize docstrings
4 #1683 Tests: centralize session cleanup
5 #1684 Tests: transport type annotations
6 #1685 Tests: IoT type annotations
7 #1686 Tests: Smart type annotations
8 #1687 Tests: CLI/protocols/smartcam type annotations
9 #1688 Tests: top-level type annotations

Verification

  • mypy: 0 errors across all 11 files
  • All tests pass
  • Pre-commit (ruff, ruff-format, mypy) all pass
  • Full test suite passes after sequential merge of all 9 PRs (10,656 passed, 194 skipped)

@ZeliardM ZeliardM marked this pull request as ready for review April 7, 2026 02:26
Copilot AI review requested due to automatic review settings April 7, 2026 02:26
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.22%. Comparing base (76d9f68) to head (291626e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1687   +/-   ##
=======================================
  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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 improves static typing coverage in the test suite by adding explicit type annotations to tests under tests/cli/, tests/protocols/, and tests/smartcam/, aligning the tests with the repository’s broader type-checking practices (e.g., mypy in pre-commit).

Changes:

  • Added explicit -> None return annotations to async and sync test functions across the targeted test files.
  • Added parameter type annotations for common pytest fixtures and parametrized inputs (e.g., Device, CliRunner, MockerFixture, pytest.LogCaptureFixture, unions like str | None).
  • Introduced a small number of targeted # type: ignore[...] annotations in protocol tests where runtime behavior intentionally diverges from static typing.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/cli/test_hub.py Types dev, runner, caplog, and mocker in hub CLI tests; adds -> None.
tests/cli/test_vacuum.py Types dev, runner, and mocker in vacuum CLI tests; adds -> None.
tests/protocols/test_iotprotocol.py Adds from __future__ import annotations, fixture/input typing, and targeted type: ignore for known runtime-only behavior.
tests/protocols/test_smartprotocol.py Adds fixture/input typing (including parametrized ints/enums) and -> None across smart protocol tests.
tests/smartcam/modules/test_alarm.py Adds -> None return typing for alarm module tests.
tests/smartcam/modules/test_battery.py Types parametrized inputs with appropriate unions (e.g., `str
tests/smartcam/modules/test_camera.py Adds -> None return typing for camera module tests.
tests/smartcam/modules/test_childsetup.py Adds fixture parameter types (MockerFixture, LogCaptureFixture) and -> None.
tests/smartcam/modules/test_detections.py Adds typing to selected helper parameters and -> None to the async test function.
tests/smartcam/modules/test_pantilt.py Adds fixture parameter types and -> None across PanTilt module tests.
tests/smartcam/test_smartcamdevice.py Adds -> None and fixture parameter typing (including FrozenDateTimeFactory) for smartcam device tests.

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

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