32 lines
923 B
Python
32 lines
923 B
Python
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
from tenbackward.state import load_posted, posted_path, save_posted
|
|
|
|
|
|
def test_load_posted_creates_empty_when_missing(tmp_path: Path) -> None:
|
|
state = load_posted(tmp_path)
|
|
assert state == {}
|
|
|
|
|
|
def test_round_trip_persists(tmp_path: Path) -> None:
|
|
state = {"post-1": {"posted_at": "2024-01-01T00:00:00Z"}}
|
|
save_posted(tmp_path, state)
|
|
|
|
assert posted_path(tmp_path).exists()
|
|
again = load_posted(tmp_path)
|
|
assert again == state
|
|
|
|
|
|
def test_load_posted_handles_corrupt_file(tmp_path: Path) -> None:
|
|
posted_path(tmp_path).parent.mkdir(parents=True, exist_ok=True)
|
|
posted_path(tmp_path).write_text("not-json")
|
|
assert load_posted(tmp_path) == {}
|
|
|
|
|
|
def test_save_posted_creates_parent_dirs(tmp_path: Path) -> None:
|
|
nested = tmp_path / "deep" / "data"
|
|
save_posted(nested, {"x": 1})
|
|
assert posted_path(nested).exists()
|