tests: fix typos, child device subtype, CLI patch path, and deprecation test logic (#1677)

This commit is contained in:
ZeliardM
2026-07-05 12:16:41 -04:00
committed by GitHub
parent 76d9f68547
commit 440f1f453b
6 changed files with 22 additions and 13 deletions

View File

@@ -130,9 +130,7 @@ async def test_list_devices(discovery_mock, runner):
async def test_discover_raw(discovery_mock, runner, mocker):
"""Test the discover raw command."""
redact_spy = mocker.patch(
"kasa.protocols.protocol.redact_data", side_effect=redact_data
)
redact_spy = mocker.patch("kasa.cli.discover.redact_data", side_effect=redact_data)
res = await runner.invoke(
cli,
["--username", "foo", "--password", "bar", "discover", "raw"],

View File

@@ -217,6 +217,13 @@ deprecated_is_device_type = {
"is_strip": DeviceType.Strip,
"is_strip_socket": DeviceType.StripSocket,
}
deprecated_warns_before_attribute_error = {
"has_effects",
"is_color",
"is_dimmable",
"is_variable_color_temp",
"valid_temperature_range",
}
deprecated_is_light_function_smart_module = {
"is_color": "Color",
"is_dimmable": "Brightness",
@@ -244,20 +251,23 @@ def test_deprecated_device_type_attributes(dev: SmartDevice):
async def _test_attribute(
dev: Device, attribute_name, is_expected, module_name, *args, will_raise=False
):
if is_expected and will_raise:
will_warn = is_expected or attribute_name in deprecated_warns_before_attribute_error
if will_raise:
ctx: AbstractContextManager | nullcontext = pytest.raises(will_raise)
dep_context: pytest.WarningsRecorder | nullcontext = pytest.deprecated_call(
match=(f"{attribute_name} is deprecated, use:")
)
dep_context: pytest.WarningsRecorder | nullcontext
elif is_expected:
ctx = nullcontext()
dep_context = pytest.deprecated_call(
match=(f"{attribute_name} is deprecated, use:")
)
else:
ctx = pytest.raises(
AttributeError, match=f"Device has no attribute '{attribute_name}'"
)
if will_warn:
dep_context = pytest.deprecated_call(
match=(f"{attribute_name} is deprecated, use:")
)
else:
dep_context = nullcontext()
with dep_context, ctx:

View File

@@ -415,7 +415,7 @@ async def test_device_update_from_new_discovery_info(discovery_mock):
KasaException,
match=re.escape("You need to await update() to access the data"),
):
assert device.supported_modules
assert device.modules
async def test_discover_single_http_client(discovery_mock, mocker):