mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-06 21:03:50 +00:00
tests: add type annotations to top-level test files (#1688)
Add type annotations (parameter types and `-> None` return types) to all top-level test functions across 22 test files. This enables mypy to check test function bodies, catching type errors that were previously hidden.
This commit is contained in:
@@ -215,7 +215,7 @@ def parametrize_subtract(params: pytest.MarkDecorator, subtract: pytest.MarkDeco
|
||||
|
||||
|
||||
def parametrize(
|
||||
desc,
|
||||
desc: str,
|
||||
*,
|
||||
model_filter=None,
|
||||
protocol_filter=None,
|
||||
@@ -395,7 +395,7 @@ chime_smart = parametrize(
|
||||
vacuum = parametrize("vacuums", device_type_filter=[DeviceType.Vacuum])
|
||||
|
||||
|
||||
def check_categories():
|
||||
def check_categories() -> None:
|
||||
"""Check that every fixture file is categorized."""
|
||||
categorized_fixtures = set(
|
||||
dimmer_iot.args[1]
|
||||
@@ -428,7 +428,7 @@ def check_categories():
|
||||
check_categories()
|
||||
|
||||
|
||||
def device_for_fixture_name(model, protocol):
|
||||
def device_for_fixture_name(model: str, protocol: str):
|
||||
if protocol in {"SMART", "SMART.CHILD"}:
|
||||
return SmartDevice
|
||||
elif protocol in {"SMARTCAM", "SMARTCAM.CHILD"}:
|
||||
@@ -467,7 +467,9 @@ async def _update_and_close(d) -> Device:
|
||||
return d
|
||||
|
||||
|
||||
async def _discover_update_and_close(ip, username, password) -> Device:
|
||||
async def _discover_update_and_close(
|
||||
ip: str, username: str | None, password: str | None
|
||||
) -> Device:
|
||||
if username and password:
|
||||
credentials = Credentials(username=username, password=password)
|
||||
else:
|
||||
@@ -477,7 +479,7 @@ async def _discover_update_and_close(ip, username, password) -> Device:
|
||||
|
||||
|
||||
async def get_device_for_fixture(
|
||||
fixture_data: FixtureInfo, *, verbatim=False, update_after_init=True
|
||||
fixture_data: FixtureInfo, *, verbatim: bool = False, update_after_init: bool = True
|
||||
) -> Device:
|
||||
# if the wanted file is not an absolute path, prepend the fixtures directory
|
||||
|
||||
@@ -502,7 +504,9 @@ async def get_device_for_fixture(
|
||||
fixture_data.data, fixture_data.name, verbatim=verbatim
|
||||
)
|
||||
else:
|
||||
d.protocol = FakeIotProtocol(fixture_data.data, verbatim=verbatim)
|
||||
d.protocol = FakeIotProtocol(
|
||||
fixture_data.data, fixture_data.name, verbatim=verbatim
|
||||
)
|
||||
|
||||
discovery_data = None
|
||||
if "discovery_result" in fixture_data.data:
|
||||
@@ -520,21 +524,21 @@ async def get_device_for_fixture(
|
||||
return d
|
||||
|
||||
|
||||
async def get_device_for_fixture_protocol(fixture, protocol):
|
||||
async def get_device_for_fixture_protocol(fixture: str, protocol: str):
|
||||
finfo = FixtureInfo(name=fixture, protocol=protocol, data={})
|
||||
for fixture_info in FIXTURE_DATA:
|
||||
if finfo == fixture_info:
|
||||
return await get_device_for_fixture(fixture_info)
|
||||
|
||||
|
||||
def get_fixture_info(fixture, protocol):
|
||||
def get_fixture_info(fixture: str, protocol: str):
|
||||
finfo = FixtureInfo(name=fixture, protocol=protocol, data={})
|
||||
for fixture_info in FIXTURE_DATA:
|
||||
if finfo == fixture_info:
|
||||
return fixture_info
|
||||
|
||||
|
||||
def get_nearest_fixture_to_ip(dev):
|
||||
def get_nearest_fixture_to_ip(dev: Device):
|
||||
if isinstance(dev, SmartDevice):
|
||||
protocol_fixtures = filter_fixtures("", protocol_filter={"SMART"})
|
||||
elif isinstance(dev, SmartCamDevice):
|
||||
@@ -572,7 +576,7 @@ def get_nearest_fixture_to_ip(dev):
|
||||
|
||||
|
||||
@pytest.fixture(params=filter_fixtures("main devices"), ids=idgenerator)
|
||||
async def dev(request) -> AsyncGenerator[Device, None]:
|
||||
async def dev(request: pytest.FixtureRequest) -> AsyncGenerator[Device, None]:
|
||||
"""Device fixture.
|
||||
|
||||
Provides a device (given --ip) or parametrized fixture for the supported devices.
|
||||
|
||||
Reference in New Issue
Block a user