-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path__init__.py
More file actions
62 lines (43 loc) · 1.73 KB
/
__init__.py
File metadata and controls
62 lines (43 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Unittests for devolo_plc_api."""
from __future__ import annotations
import json
from dataclasses import dataclass
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING
from syrupy.extensions.amber import AmberSnapshotExtension
from devolo_plc_api.device_api import SERVICE_TYPE as DEVICE_API
from devolo_plc_api.plcnet_api import SERVICE_TYPE as PLCNET_API
from devolo_plc_api.zeroconf import ZeroconfServiceInfo
if TYPE_CHECKING:
from syrupy.location import PyTestLocation
class DeviceType(Enum):
"""Different device types."""
REPEATER = 1
PLC = 2
class DifferentDirectoryExtension(AmberSnapshotExtension):
"""Extention for Syrupy to change the directory in which snapshots are stored."""
@classmethod
def dirname(cls: type[DifferentDirectoryExtension], *, test_location: PyTestLocation) -> str:
"""Store snapshots in `snapshots`rather than `__snapshots__`."""
return str(Path(test_location.filepath).parent.joinpath("snapshots"))
@dataclass
class TestData:
"""Test data for a devolo device."""
__test__ = False
ip: str
"""IP address of a device."""
hostname: str
"""Hostname of a device."""
device_info: dict[str, ZeroconfServiceInfo]
"""Zeroconf info a device delivers."""
def load_test_data():
"""Load test data from file."""
file = Path(__file__).parent / "test_data.json"
with file.open("r") as handler:
data = json.load(handler)
device_info = {
DEVICE_API: ZeroconfServiceInfo(hostname=data["hostname"], **data["device_info"][DEVICE_API]),
PLCNET_API: ZeroconfServiceInfo(**data["device_info"][PLCNET_API]),
}
return TestData(ip=data["ip"], hostname=data["hostname"], device_info=device_info)