Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/modules/common/configurable_forecast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ def test_store_update_runs_even_when_no_fetch_is_due():
forecast.store.update.assert_called_once()
forecast.store.set.assert_not_called()
forecast._component_updater.assert_not_called()


def test_real_store_does_not_crash_before_first_fetch():
forecast = _make_forecast()

forecast.update()
3 changes: 1 addition & 2 deletions packages/modules/common/store/_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def _filter_values_for_date(values: Dict[str, float], target_date) -> Dict[str,

class ForecastValueStore(ValueStore[ForecastState]):
def __init__(self):
# erlaubt update() bereits vor dem ersten Abruf
self.state = ForecastState()
pass

def set(self, state: ForecastState) -> None:
self.state = state
Expand Down
19 changes: 15 additions & 4 deletions packages/modules/common/store/_forecast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from control.optional import Optional
from modules.common.component_state import ForecastState
from modules.common.store import _forecast
from modules.common.store._api import LoggingValueStore
from modules.common.store._forecast import ForecastValueStore


Expand Down Expand Up @@ -70,10 +71,20 @@ def test_update_reruns_split_after_midnight_without_new_fetch(monkeypatch: pytes
assert data.data.optional_data.data.forecast.get.tomorrow_kwh == 0.0


def test_update_safe_before_first_fetch():
# ForecastValueStore() muss schon vor dem ersten set() aufrufbar sein (siehe
# ConfigurableForecast.update(), das update() auch ohne fälligen Abruf jeden Zyklus ruft)
ForecastValueStore().update()
def test_update_before_first_fetch_raises_attribute_error():
# signalisiert LoggingValueStore.update(), dass noch nichts zu publizieren ist
with pytest.raises(AttributeError):
ForecastValueStore().update()


def test_logging_store_swallows_missing_state_as_safe_noop(monkeypatch: pytest.MonkeyPatch):
store = LoggingValueStore(ForecastValueStore())
pub = Mock()
monkeypatch.setattr(_forecast, "pub_to_broker", pub)

store.update()

pub.assert_not_called()


def test_dst_transition_does_not_shift_day_boundary(monkeypatch: pytest.MonkeyPatch):
Expand Down
Loading