Implemented the full clean rewrite for Gitea
This commit is contained in:
28
tests/test_state.py
Normal file
28
tests/test_state.py
Normal file
@@ -0,0 +1,28 @@
|
||||
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"
|
||||
Reference in New Issue
Block a user