MIL-004: High score file #38

Merged
Tirsvad merged 6 commits from mil-004-high-score-file into main 2026-10-13 08:41:38 +02:00
2 changed files with 28 additions and 0 deletions
Showing only changes of commit ba0ae0e698 - Show all commits
+16
View File
@@ -0,0 +1,16 @@
"""Shared pytest configuration for the snake game tests."""
from pathlib import Path
import pytest
@pytest.fixture(autouse=True)
def isolated_working_directory(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
"""Run every test in an empty temporary working directory.
The high score file has a relative default path (`data.txt`). Without this
fixture, a test that uses the default would read and write the real file of
the repository or of the directory pytest was started from.
"""
monkeypatch.chdir(tmp_path)
+12
View File
@@ -1,5 +1,7 @@
"""Tests of the main flow, with fakes instead of a real screen.""" """Tests of the main flow, with fakes instead of a real screen."""
from pathlib import Path
import pytest import pytest
from fakes import ( from fakes import (
@@ -131,6 +133,16 @@ def test_main_sets_up_the_screen_turns_off_drawing_and_binds_the_keys(
assert sorted(screens[0].bindings) == sorted(ARROW_KEYS) assert sorted(screens[0].bindings) == sorted(ARROW_KEYS)
def test_main_creates_data_txt_in_the_working_directory_holding_0(
monkeypatch: pytest.MonkeyPatch, sleeps: list[float], tmp_path: Path
) -> None:
install_fake_turtle(monkeypatch)
main()
assert (tmp_path / constants.HIGH_SCORE_FILE).read_text(encoding="utf-8") == "0"
def test_register_head_shape_builds_two_components_from_the_constants( def test_register_head_shape_builds_two_components_from_the_constants(
monkeypatch: pytest.MonkeyPatch, monkeypatch: pytest.MonkeyPatch,
) -> None: ) -> None: