Add tests for dump_devinfo parent/child smartcam fixture generation (#1428)
Some checks failed
CI / Perform linting checks (3.13) (push) Has been cancelled
CodeQL checks / Analyze (python) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.11) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.12) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, macos-latest, 3.13) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.11) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.12) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, ubuntu-latest, 3.13) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.11) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.12) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (false, windows-latest, 3.13) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.11) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.12) (push) Has been cancelled
CI / Python ${{ matrix.python-version}} on ${{ matrix.os }}${{ fromJSON('[" (extras)", ""]')[matrix.extras == ''] }} (true, ubuntu-latest, 3.13) (push) Has been cancelled

Currently the dump_devinfo fixture generation tests do not test
generation for hub and their children.

This PR enables tests for `smartcam` hubs and their child fixtures. It
does not enable support for `smart` hub fixtures as not all the fixtures
currently have the required info. This can be addressed in a subsequent
PR.
This commit is contained in:
Steven B.
2025-01-08 21:51:35 +00:00
committed by GitHub
parent debcff9f9b
commit 2e3b1bc376
4 changed files with 80 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
"""Module for dump_devinfo tests."""
import copy
import pytest
from devtools.dump_devinfo import get_legacy_fixture, get_smart_fixtures
@@ -11,6 +13,7 @@ from kasa.smartcam import SmartCamDevice
from .conftest import (
FixtureInfo,
get_device_for_fixture,
get_fixture_info,
parametrize,
)
@@ -64,22 +67,54 @@ async def test_smart_fixtures(fixture_info: FixtureInfo):
assert fixture_info.data == fixture_result.data
def _normalize_child_device_ids(info: dict):
"""Scrubbed child device ids in hubs may not match ids in child fixtures.
Different hub fixtures could create the same child fixture so we scrub
them again for the purpose of the test.
"""
if dev_info := info.get("get_device_info"):
dev_info["device_id"] = "SCRUBBED"
elif (
dev_info := info.get("getDeviceInfo", {})
.get("device_info", {})
.get("basic_info")
):
dev_info["dev_id"] = "SCRUBBED"
@smartcam_fixtures
async def test_smartcam_fixtures(fixture_info: FixtureInfo):
"""Test that smartcam fixtures are created the same."""
dev = await get_device_for_fixture(fixture_info, verbatim=True)
assert isinstance(dev, SmartCamDevice)
if dev.children:
pytest.skip("Test not currently implemented for devices with children.")
fixtures = await get_smart_fixtures(
created_fixtures = await get_smart_fixtures(
dev.protocol,
discovery_info=fixture_info.data.get("discovery_result"),
batch_size=5,
)
fixture_result = fixtures[0]
fixture_result = created_fixtures.pop(0)
assert fixture_info.data == fixture_result.data
for created_child_fixture in created_fixtures:
child_fixture_info = get_fixture_info(
created_child_fixture.filename + ".json",
created_child_fixture.protocol_suffix,
)
assert child_fixture_info
_normalize_child_device_ids(created_child_fixture.data)
saved_fixture_data = copy.deepcopy(child_fixture_info.data)
_normalize_child_device_ids(saved_fixture_data)
saved_fixture_data = {
key: val for key, val in saved_fixture_data.items() if val != -1001
}
assert saved_fixture_data == created_child_fixture.data
@iot_fixtures
async def test_iot_fixtures(fixture_info: FixtureInfo):