mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-17 13:08:19 -04:00
Add comprehensive test suite achieving 99% code coverage
Added 35 test files with 502 tests covering all Python modules including API routes, ORM models, splendor game logic/TUI, heater controller, weather service, NixOS installer, ZFS dataset management, and utilities. Coverage improved from 11% to 99% (2540/2564 statements covered). https://claude.ai/code/session_01SVzgLDUS1Cdc4eh1ijETTh
This commit is contained in:
88
tests/test_splendor_simulat.py
Normal file
88
tests/test_splendor_simulat.py
Normal file
@@ -0,0 +1,88 @@
|
||||
"""Tests for python/splendor/simulat.py."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import random
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from python.splendor.base import load_cards, load_nobles
|
||||
from python.splendor.simulat import main
|
||||
|
||||
|
||||
def test_simulat_main(tmp_path: Path) -> None:
|
||||
"""Test simulat main function with mock game data."""
|
||||
random.seed(42)
|
||||
|
||||
# Create temporary game data
|
||||
cards_dir = tmp_path / "game_data" / "cards"
|
||||
nobles_dir = tmp_path / "game_data" / "nobles"
|
||||
cards_dir.mkdir(parents=True)
|
||||
nobles_dir.mkdir(parents=True)
|
||||
|
||||
cards = []
|
||||
for tier in (1, 2, 3):
|
||||
for color in ("white", "blue", "green", "red", "black"):
|
||||
cards.append({
|
||||
"tier": tier,
|
||||
"points": tier,
|
||||
"color": color,
|
||||
"cost": {"white": tier, "blue": 0, "green": 0, "red": 0, "black": 0, "gold": 0},
|
||||
})
|
||||
(cards_dir / "default.json").write_text(json.dumps(cards))
|
||||
|
||||
nobles = [
|
||||
{"name": f"Noble {i}", "points": 3, "requirements": {"white": 3, "blue": 3, "green": 3}}
|
||||
for i in range(5)
|
||||
]
|
||||
(nobles_dir / "default.json").write_text(json.dumps(nobles))
|
||||
|
||||
# Patch Path(__file__).parent to point to tmp_path
|
||||
fake_parent = tmp_path
|
||||
with patch("python.splendor.simulat.Path") as mock_path_cls:
|
||||
mock_path_cls.return_value.__truediv__ = Path.__truediv__
|
||||
mock_file = mock_path_cls().__truediv__("simulat.py")
|
||||
# Make Path(__file__).parent return tmp_path
|
||||
mock_path_cls.reset_mock()
|
||||
mock_path_instance = mock_path_cls.return_value
|
||||
mock_path_instance.parent = fake_parent
|
||||
|
||||
# Actually just patch load_cards and load_nobles
|
||||
cards_data = load_cards(cards_dir / "default.json")
|
||||
nobles_data = load_nobles(nobles_dir / "default.json")
|
||||
|
||||
with (
|
||||
patch("python.splendor.simulat.load_cards", return_value=cards_data),
|
||||
patch("python.splendor.simulat.load_nobles", return_value=nobles_data),
|
||||
):
|
||||
main()
|
||||
|
||||
|
||||
def test_load_cards_and_nobles(tmp_path: Path) -> None:
|
||||
"""Test that load_cards and load_nobles work correctly."""
|
||||
cards_dir = tmp_path / "cards"
|
||||
cards_dir.mkdir()
|
||||
|
||||
cards = [
|
||||
{
|
||||
"tier": 1,
|
||||
"points": 0,
|
||||
"color": "white",
|
||||
"cost": {"white": 1, "blue": 0, "green": 0, "red": 0, "black": 0, "gold": 0},
|
||||
}
|
||||
]
|
||||
cards_file = cards_dir / "default.json"
|
||||
cards_file.write_text(json.dumps(cards))
|
||||
loaded = load_cards(cards_file)
|
||||
assert len(loaded) == 1
|
||||
assert loaded[0].color == "white"
|
||||
|
||||
nobles_dir = tmp_path / "nobles"
|
||||
nobles_dir.mkdir()
|
||||
nobles = [{"name": "Noble A", "points": 3, "requirements": {"white": 3}}]
|
||||
nobles_file = nobles_dir / "default.json"
|
||||
nobles_file.write_text(json.dumps(nobles))
|
||||
loaded_nobles = load_nobles(nobles_file)
|
||||
assert len(loaded_nobles) == 1
|
||||
assert loaded_nobles[0].name == "Noble A"
|
||||
Reference in New Issue
Block a user