steam-backlog-enforcer/steam_backlog_enforcer/tests/_release_helpers.py
Krzysztof kuhy Rudnicki 681ab14481 Group Config and State fields, keep flat JSON
Config moves the earned-time transports into EarnSources and the budget
switches into PlaytimePolicy; State moves the legacy single pick into
LegacyManualPick and the assignment clocks into AssignmentTimes.
_flat_record writes groups inline at their old position, so config.json
and state.json keep their exact bytes (golden round-trip tests).

Todo: 9b9342ba

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 08:34:14 +01:00

43 lines
1.3 KiB
Python

"""Shared builders for the release-lifecycle and tampering tests."""
from __future__ import annotations
from datetime import UTC, datetime
import json
from steam_backlog_enforcer import config as config_mod
from steam_backlog_enforcer.steam_api import AchievementInfo, GameInfo
from steam_backlog_enforcer.tests._main_helpers import STARTED_AT
RELEASED = datetime(2026, 9, 20, tzinfo=UTC)
def pick(app_id: int, **extra: str) -> dict[str, object]:
"""Build one manual-pick entry started a day ago."""
return {
"app_id": app_id,
"game_name": f"G{app_id}",
"started_at": STARTED_AT,
} | dict(extra.items())
def game(app_id: int, *unlock_times: int, hours: float = 5.0) -> GameInfo:
"""Build a GameInfo with one unlocked achievement per epoch given."""
return GameInfo(
app_id=app_id,
name=f"G{app_id}",
total_achievements=10,
unlocked_achievements=len(unlock_times),
playtime_minutes=60,
completionist_hours=hours,
achievements=[
AchievementInfo(f"a{t}", f"A{t}", achieved=True, unlock_time=t)
for t in unlock_times
],
)
def write_state(data: dict[str, object]) -> None:
"""Write raw JSON to the (conftest-redirected) state file."""
config_mod.STATE_FILE.write_text(json.dumps(data), encoding="utf-8")