mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-07-08 14:52:03 +00:00
tests: add type annotations to Smart tests (#1686)
Some checks are pending
CI / Perform Lint Checks (3.14) (push) Waiting to run
CI / Python 3.11 on macos-latest (push) Blocked by required conditions
CI / Python 3.12 on macos-latest (push) Blocked by required conditions
CI / Python 3.13 on macos-latest (push) Blocked by required conditions
CI / Python 3.14 on macos-latest (push) Blocked by required conditions
CI / Python 3.11 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.12 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.13 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.14 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.11 on windows-latest (push) Blocked by required conditions
CI / Python 3.12 on windows-latest (push) Blocked by required conditions
CI / Python 3.13 on windows-latest (push) Blocked by required conditions
CI / Python 3.14 on windows-latest (push) Blocked by required conditions
CodeQL Checks / Analyze (python) (push) Waiting to run
Some checks are pending
CI / Perform Lint Checks (3.14) (push) Waiting to run
CI / Python 3.11 on macos-latest (push) Blocked by required conditions
CI / Python 3.12 on macos-latest (push) Blocked by required conditions
CI / Python 3.13 on macos-latest (push) Blocked by required conditions
CI / Python 3.14 on macos-latest (push) Blocked by required conditions
CI / Python 3.11 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.12 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.13 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.14 on ubuntu-latest (push) Blocked by required conditions
CI / Python 3.11 on windows-latest (push) Blocked by required conditions
CI / Python 3.12 on windows-latest (push) Blocked by required conditions
CI / Python 3.13 on windows-latest (push) Blocked by required conditions
CI / Python 3.14 on windows-latest (push) Blocked by required conditions
CodeQL Checks / Analyze (python) (push) Waiting to run
Add type annotations across all 'smart' tests, enabling mypy to check test function bodies, catching type errors that were previously hidden.
This commit is contained in:
@@ -1,17 +1,32 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TypedDict
|
||||
|
||||
import pytest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from kasa import Module
|
||||
from kasa.smart import SmartDevice
|
||||
from kasa.smart.modules import Alarm
|
||||
from kasa.smart.modules.alarm import AlarmVolume
|
||||
|
||||
from ...device_fixtures import get_parent_and_child_modules, parametrize
|
||||
|
||||
alarm = parametrize("has alarm", component_filter="alarm", protocol_filter={"SMART"})
|
||||
|
||||
|
||||
class PlayAlarmKwargs(TypedDict, total=False):
|
||||
duration: int
|
||||
volume: AlarmVolume | int
|
||||
sound: str
|
||||
|
||||
|
||||
class PlayAlarmRequestParams(TypedDict, total=False):
|
||||
alarm_duration: int
|
||||
alarm_volume: AlarmVolume
|
||||
alarm_type: str
|
||||
|
||||
|
||||
@alarm
|
||||
@pytest.mark.parametrize(
|
||||
("feature", "prop_name", "type"),
|
||||
@@ -23,7 +38,9 @@ alarm = parametrize("has alarm", component_filter="alarm", protocol_filter={"SMA
|
||||
("alarm_volume_level", "alarm_volume", int),
|
||||
],
|
||||
)
|
||||
async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: type):
|
||||
async def test_features(
|
||||
dev: SmartDevice, feature: str, prop_name: str, type: type
|
||||
) -> None:
|
||||
"""Test that features are registered and work as expected."""
|
||||
alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
|
||||
assert alarm is not None
|
||||
@@ -37,7 +54,7 @@ async def test_features(dev: SmartDevice, feature: str, prop_name: str, type: ty
|
||||
|
||||
|
||||
@alarm
|
||||
async def test_volume_feature(dev: SmartDevice):
|
||||
async def test_volume_feature(dev: SmartDevice) -> None:
|
||||
"""Test that volume features have correct choices and range."""
|
||||
alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
|
||||
assert alarm is not None
|
||||
@@ -64,7 +81,12 @@ async def test_volume_feature(dev: SmartDevice):
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_play(dev: SmartDevice, kwargs, request_params, mocker: MockerFixture):
|
||||
async def test_play(
|
||||
dev: SmartDevice,
|
||||
kwargs: PlayAlarmKwargs,
|
||||
request_params: PlayAlarmRequestParams,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
"""Test that play parameters are handled correctly."""
|
||||
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
|
||||
call_spy = mocker.spy(alarm, "call")
|
||||
@@ -86,7 +108,7 @@ async def test_play(dev: SmartDevice, kwargs, request_params, mocker: MockerFixt
|
||||
|
||||
|
||||
@alarm
|
||||
async def test_stop(dev: SmartDevice, mocker: MockerFixture):
|
||||
async def test_stop(dev: SmartDevice, mocker: MockerFixture) -> None:
|
||||
"""Test that stop creates the correct call."""
|
||||
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
|
||||
call_spy = mocker.spy(alarm, "call")
|
||||
@@ -112,7 +134,7 @@ async def test_set_alarm_configure(
|
||||
method: str,
|
||||
value: str | int,
|
||||
target_key: str,
|
||||
):
|
||||
) -> None:
|
||||
"""Test that set_alarm_sound creates the correct call."""
|
||||
alarm: Alarm = next(get_parent_and_child_modules(dev, Module.Alarm))
|
||||
call_spy = mocker.spy(alarm, "call")
|
||||
|
||||
Reference in New Issue
Block a user