mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-12-20 03:30:12 +00:00
Update test framework for dynamic parametrization (#810)
This commit is contained in:
@@ -4,6 +4,10 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, NamedTuple, Optional, Set
|
||||
|
||||
from kasa.device_factory import _get_device_type_from_sys_info
|
||||
from kasa.device_type import DeviceType
|
||||
from kasa.smart.smartdevice import SmartDevice
|
||||
|
||||
|
||||
class FixtureInfo(NamedTuple):
|
||||
name: str
|
||||
@@ -83,6 +87,7 @@ def filter_fixtures(
|
||||
protocol_filter: Optional[Set[str]] = None,
|
||||
model_filter: Optional[Set[str]] = None,
|
||||
component_filter: Optional[str] = None,
|
||||
device_type_filter: Optional[List[DeviceType]] = None,
|
||||
):
|
||||
"""Filter the fixtures based on supplied parameters.
|
||||
|
||||
@@ -108,6 +113,19 @@ def filter_fixtures(
|
||||
}
|
||||
return component_filter in components
|
||||
|
||||
def _device_type_match(fixture_data: FixtureInfo, device_type):
|
||||
if (component_nego := fixture_data.data.get("component_nego")) is None:
|
||||
return _get_device_type_from_sys_info(fixture_data.data) in device_type
|
||||
components = [component["id"] for component in component_nego["component_list"]]
|
||||
if (info := fixture_data.data.get("get_device_info")) and (
|
||||
type_ := info.get("type")
|
||||
):
|
||||
return (
|
||||
SmartDevice._get_device_type_from_components(components, type_)
|
||||
in device_type
|
||||
)
|
||||
return False
|
||||
|
||||
filtered = []
|
||||
if protocol_filter is None:
|
||||
protocol_filter = {"IOT", "SMART"}
|
||||
@@ -120,6 +138,10 @@ def filter_fixtures(
|
||||
continue
|
||||
if component_filter and not _component_match(fixture_data, component_filter):
|
||||
continue
|
||||
if device_type_filter and not _device_type_match(
|
||||
fixture_data, device_type_filter
|
||||
):
|
||||
continue
|
||||
|
||||
filtered.append(fixture_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user