mirror of
https://github.com/python-kasa/python-kasa.git
synced 2026-10-07 05:13:49 +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:
@@ -2,6 +2,7 @@ import asyncio
|
||||
|
||||
import pytest
|
||||
import xdoctest
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from .conftest import (
|
||||
get_device_for_fixture_protocol,
|
||||
@@ -10,7 +11,7 @@ from .conftest import (
|
||||
)
|
||||
|
||||
|
||||
def test_bulb_examples(mocker):
|
||||
def test_bulb_examples(mocker: MockerFixture) -> None:
|
||||
"""Use KL130 (bulb with all features) to test the doctests."""
|
||||
p = asyncio.run(get_device_for_fixture_protocol("KL130(US)_1.0_1.8.11.json", "IOT"))
|
||||
asyncio.run(p.set_alias("Bedroom Bulb"))
|
||||
@@ -22,7 +23,7 @@ def test_bulb_examples(mocker):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_iotdevice_examples(mocker):
|
||||
def test_iotdevice_examples(mocker: MockerFixture) -> None:
|
||||
"""Use HS110 for emeter examples."""
|
||||
p = asyncio.run(get_device_for_fixture_protocol("HS110(EU)_1.0_1.2.5.json", "IOT"))
|
||||
asyncio.run(p.set_alias("Bedroom Lamp Plug"))
|
||||
@@ -34,7 +35,7 @@ def test_iotdevice_examples(mocker):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_plug_examples(mocker):
|
||||
def test_plug_examples(mocker: MockerFixture) -> None:
|
||||
"""Test plug examples."""
|
||||
p = asyncio.run(get_device_for_fixture_protocol("HS110(EU)_1.0_1.2.5.json", "IOT"))
|
||||
asyncio.run(p.set_alias("Bedroom Lamp Plug"))
|
||||
@@ -45,13 +46,13 @@ def test_plug_examples(mocker):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_strip_examples(readmes_mock):
|
||||
def test_strip_examples(readmes_mock) -> None:
|
||||
"""Test strip examples."""
|
||||
res = xdoctest.doctest_module("kasa.iot.iotstrip", "all")
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_dimmer_examples(mocker):
|
||||
def test_dimmer_examples(mocker: MockerFixture) -> None:
|
||||
"""Test dimmer examples."""
|
||||
p = asyncio.run(get_device_for_fixture_protocol("HS220(US)_1.0_1.5.7.json", "IOT"))
|
||||
mocker.patch("kasa.iot.iotdimmer.IotDimmer", return_value=p)
|
||||
@@ -60,7 +61,7 @@ def test_dimmer_examples(mocker):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_lightstrip_examples(mocker):
|
||||
def test_lightstrip_examples(mocker: MockerFixture) -> None:
|
||||
"""Test lightstrip examples."""
|
||||
p = asyncio.run(get_device_for_fixture_protocol("KL430(US)_1.0_1.0.10.json", "IOT"))
|
||||
asyncio.run(p.set_alias("Bedroom Lightstrip"))
|
||||
@@ -71,7 +72,7 @@ def test_lightstrip_examples(mocker):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_discovery_examples(readmes_mock):
|
||||
def test_discovery_examples(readmes_mock) -> None:
|
||||
"""Test discovery examples."""
|
||||
res = xdoctest.doctest_module("kasa.discover", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -79,7 +80,7 @@ def test_discovery_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_deviceconfig_examples(readmes_mock):
|
||||
def test_deviceconfig_examples(readmes_mock) -> None:
|
||||
"""Test discovery examples."""
|
||||
res = xdoctest.doctest_module("kasa.deviceconfig", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -87,7 +88,7 @@ def test_deviceconfig_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_device_examples(readmes_mock):
|
||||
def test_device_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.device", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -95,7 +96,7 @@ def test_device_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_light_examples(readmes_mock):
|
||||
def test_light_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.interfaces.light", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -103,7 +104,7 @@ def test_light_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_light_preset_examples(readmes_mock):
|
||||
def test_light_preset_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.interfaces.lightpreset", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -111,7 +112,7 @@ def test_light_preset_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_light_effect_examples(readmes_mock):
|
||||
def test_light_effect_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.interfaces.lighteffect", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -119,7 +120,7 @@ def test_light_effect_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_child_examples(readmes_mock):
|
||||
def test_child_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.smart.modules.childdevice", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -127,7 +128,7 @@ def test_child_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_module_examples(readmes_mock):
|
||||
def test_module_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.module", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -135,7 +136,7 @@ def test_module_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_feature_examples(readmes_mock):
|
||||
def test_feature_examples(readmes_mock) -> None:
|
||||
"""Test device examples."""
|
||||
res = xdoctest.doctest_module("kasa.feature", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -143,7 +144,7 @@ def test_feature_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_tutorial_examples(readmes_mock):
|
||||
def test_tutorial_examples(readmes_mock) -> None:
|
||||
"""Test discovery examples."""
|
||||
res = xdoctest.doctest_module("docs/tutorial.py", "all")
|
||||
assert res["n_passed"] > 0
|
||||
@@ -151,7 +152,7 @@ def test_tutorial_examples(readmes_mock):
|
||||
assert not res["failed"]
|
||||
|
||||
|
||||
def test_childsetup_examples(readmes_mock, mocker):
|
||||
def test_childsetup_examples(readmes_mock, mocker: MockerFixture) -> None:
|
||||
"""Test device examples."""
|
||||
pair_resp = [
|
||||
{
|
||||
@@ -171,7 +172,7 @@ def test_childsetup_examples(readmes_mock, mocker):
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def readmes_mock(mocker):
|
||||
async def readmes_mock(mocker: MockerFixture):
|
||||
fixture_infos = {
|
||||
"127.0.0.1": get_fixture_info("KP303(UK)_1.0_1.0.3.json", "IOT"), # Strip
|
||||
"127.0.0.2": get_fixture_info("HS110(EU)_1.0_1.2.5.json", "IOT"), # Plug
|
||||
|
||||
Reference in New Issue
Block a user