Chessistics/tools/automation/test_quicksave.py

49 lines
1.4 KiB
Python
Raw Permalink Normal View History

"""End-to-end smoke test for quick save / quick load."""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[2]))
from tools.automation.harness import Harness
def main():
with Harness.launch(run_name="quicksave") as h:
h.load_mission("campaign_01", 0)
h.screenshot("01_loaded")
initial = h.state()
print(f"[initial] turn={initial['turn']} pieces={len(initial['pieces'])}")
# Save a clean checkpoint
saved = h.quick_save()
print(f"[quick_save] {saved}")
# Mutate: place a piece and step
h.place("Pawn", (0, 0), (0, 1))
h.screenshot("02_after_place")
h.set_speed(0.1)
h.play()
import time as _t
_t.sleep(1.5)
h.pause()
dirty = h.state()
print(f"[dirty] turn={dirty['turn']} pieces={len(dirty['pieces'])}")
# Load — should be back to initial state
loaded = h.quick_load()
print(f"[quick_load] {loaded}")
h.screenshot("03_after_load")
restored = h.state()
print(f"[restored] turn={restored['turn']} pieces={len(restored['pieces'])}")
assert restored['turn'] == initial['turn'], "Turn mismatch after restore"
assert len(restored['pieces']) == len(initial['pieces']), "Piece count mismatch"
print("OK — quick save/load roundtrip successful")
if __name__ == "__main__":
main()