diff --git a/justfile b/justfile index 0aaf144..b9db370 100644 --- a/justfile +++ b/justfile @@ -15,3 +15,7 @@ basic *args: # Run the test suite; extra arguments go to pytest test *args: uv run pytest {{args}} + +# Re-record the gameplay parity fixtures (only when gameplay should change) +record-traces: + uv run python tests/game_trace.py diff --git a/tests/game_trace.py b/tests/game_trace.py index 131607d..a02b292 100644 --- a/tests/game_trace.py +++ b/tests/game_trace.py @@ -1,5 +1,6 @@ import datetime import typing as T +from pathlib import Path from pqcli import random from pqcli.config import StatType @@ -67,3 +68,15 @@ def run_trace(seed: str, ticks: int = 3000) -> T.List[str]: for quest in player.quest_book.quests: lines.append(f"quest: {quest}") return lines + + +SEEDS = ["alpha", "beta", "gamma"] +FIXTURES = Path(__file__).parent / "fixtures" + + +if __name__ == "__main__": + # Re-record the parity fixtures. Only do this on purpose, when a change + # is meant to alter gameplay. + for seed in SEEDS: + lines = run_trace(seed) + (FIXTURES / f"parity_{seed}.txt").write_text("\n".join(lines) + "\n") diff --git a/tests/test_parity.py b/tests/test_parity.py index 88010c1..08303c1 100644 --- a/tests/test_parity.py +++ b/tests/test_parity.py @@ -1,14 +1,10 @@ -from pathlib import Path - import pytest -from game_trace import run_trace - -FIXTURES = Path(__file__).parent / "fixtures" +from game_trace import FIXTURES, SEEDS, run_trace -@pytest.mark.parametrize("seed", ["alpha", "beta", "gamma"]) +@pytest.mark.parametrize("seed", SEEDS) def test_gameplay_matches_recorded_trace(seed: str) -> None: - # The fixtures were recorded before the word lists moved to data files; - # stock data must reproduce them exactly, RNG stream included. + # The fixtures pin down gameplay, RNG stream included. When a change is + # meant to alter gameplay, re-record them with `just record-traces`. expected = (FIXTURES / f"parity_{seed}.txt").read_text().splitlines() assert run_trace(seed) == expected