39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
# pyright: reportMissingImports=false
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest # type: ignore[import-not-found]
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
sys.path.append(str(ROOT))
|
|
|
|
from config import _parse_mappings, load_config # type: ignore[import-not-found]
|
|
from errors import ConfigError # type: ignore[import-not-found]
|
|
|
|
|
|
def test_parse_mappings_rejects_duplicate_thermostat():
|
|
with pytest.raises(ConfigError):
|
|
_parse_mappings(
|
|
[
|
|
{"sensor": "sensor.a", "thermostate": "climate.x"},
|
|
{"sensor": "sensor.b", "thermostate": "climate.x"},
|
|
]
|
|
)
|
|
|
|
|
|
def test_load_config_parses_dry_run(tmp_path: Path):
|
|
payload = {
|
|
"fritzbox": {"url": "http://fritz.box", "password": "secret"},
|
|
"mappings": [{"sensor": "sensor.a", "thermostate": "climate.x"}],
|
|
"update_timeout": 15,
|
|
"dry_run": True,
|
|
}
|
|
config_path = tmp_path / "config.json"
|
|
config_path.write_text(json.dumps(payload), encoding="utf-8")
|
|
|
|
config = load_config(str(config_path))
|
|
assert config.dry_run is True
|