Files
daily-blackout-check/tests/test_state.py
Meghdad 4218e4ac36
All checks were successful
Test blackout notifier / test (push) Successful in 3m41s
Hourly blackout check / check (push) Successful in 8s
Implemented the full clean rewrite for Gitea
2026-07-17 04:33:16 +03:30

29 lines
847 B
Python

from __future__ import annotations
from pathlib import Path
import pytest
from blackout_notifier.state import StateError, StateRepository, empty_state
def test_state_round_trip_is_deterministic(tmp_path: Path) -> None:
repository = StateRepository(tmp_path / "nested" / "outages.json")
repository.save(empty_state())
first = repository.path.read_text(encoding="utf-8")
repository.save(repository.load())
assert repository.load() == empty_state()
assert repository.path.read_text(encoding="utf-8") == first
def test_corrupt_state_fails_closed(tmp_path: Path) -> None:
path = tmp_path / "outages.json"
path.write_text("not json", encoding="utf-8")
with pytest.raises(StateError, match="Cannot read state"):
StateRepository(path).load()
assert path.read_text(encoding="utf-8") == "not json"