Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013GAeg4Jo6xjZzjwy9QDWMQ
56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
from collections.abc import Generator
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def db() -> Generator[None, None, None]:
|
|
"""The engine holds no database state, so these tests need no database."""
|
|
yield
|
|
|
|
|
|
@dataclass
|
|
class _Device:
|
|
kind: str
|
|
id: str
|
|
state: str
|
|
|
|
|
|
@dataclass
|
|
class _House:
|
|
time: str
|
|
outdoor_c: float
|
|
dark: bool
|
|
user_area: str | None
|
|
areas: dict[str, list[_Device]]
|
|
|
|
|
|
class FakeWren:
|
|
"""The model package's surface, answering whatever a test sets ``answer`` to."""
|
|
|
|
AREAS = [
|
|
*("living room", "kitchen", "bathroom", "bedroom", "office"),
|
|
*("garden", "patio", "garage", "driveway", "balcony"),
|
|
]
|
|
KINDS = ["light", "media", "heat", "shutter", "water"]
|
|
Device = _Device
|
|
House = _House
|
|
|
|
def __init__(self) -> None:
|
|
self.answer: tuple[list[Any], float] = ([], 1.0)
|
|
self.houses: list[_House] = []
|
|
|
|
def act(self, command: str, house: _House) -> tuple[list[Any], float]:
|
|
self.houses.append(house)
|
|
return self.answer
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_wren(monkeypatch: pytest.MonkeyPatch) -> FakeWren:
|
|
"""Stands in for the optional model package the wren node imports."""
|
|
fake = FakeWren()
|
|
monkeypatch.setattr("fluksio.flow.nodes.wren._wren", lambda: fake)
|
|
return fake
|