Skip to content

Commit bbf463a

Browse files
DJ-Meyersclaude
andcommitted
fix: convert CSV validation tests from pytest to Django unittest
The CI runs `python manage.py test` (Django's unittest runner), which does not have pytest installed. Rewrites the test infrastructure to use Django's SimpleTestCase and standard unittest patterns: - Rename conftest.py to csv_data.py (conftest is a pytest convention) - Replace pytest fixtures with module-level cached data - Replace pytest parametrize with subTest loops - Use django.test.SimpleTestCase (no DB access needed) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9989fb4 commit bbf463a

3 files changed

Lines changed: 201 additions & 206 deletions

File tree

tests/csv_validation/conftest.py

Lines changed: 0 additions & 92 deletions
This file was deleted.

tests/csv_validation/csv_data.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""
2+
CSV data loading helpers for encounter validation tests.
3+
4+
Design for CI/CD efficiency:
5+
- Module-level caching loads CSVs once per import
6+
- In-memory validation only (no DB/API calls)
7+
"""
8+
9+
import csv
10+
from pathlib import Path
11+
from typing import Any
12+
13+
from .game_config import GAME_CONFIGS
14+
15+
CSV_DIR = Path(__file__).parent.parent.parent / "data" / "v2" / "csv"
16+
17+
18+
def load_csv(filename: str) -> list[dict[str, Any]]:
19+
filepath = CSV_DIR / filename
20+
if not filepath.exists():
21+
raise FileNotFoundError(f"CSV file not found: {filepath}")
22+
with open(filepath, "r", encoding="utf-8") as f:
23+
return list(csv.DictReader(f))
24+
25+
26+
def get_encounters_for_version_group(
27+
encounters: list[dict],
28+
slots: dict[str, dict],
29+
version_group_id: int,
30+
) -> list[dict]:
31+
valid_slot_ids = {
32+
slot_id
33+
for slot_id, slot in slots.items()
34+
if slot.get("version_group_id") == str(version_group_id)
35+
}
36+
return [enc for enc in encounters if enc.get("encounter_slot_id") in valid_slot_ids]
37+
38+
39+
# Module-level cached data (loaded once on import)
40+
encounters_data = load_csv("encounters.csv")
41+
encounter_slots_data = load_csv("encounter_slots.csv")
42+
encounter_methods_data = load_csv("encounter_methods.csv")
43+
location_areas_data = load_csv("location_areas.csv")
44+
45+
encounter_methods_lookup = {row["id"]: row for row in encounter_methods_data}
46+
encounter_slots_lookup = {row["id"]: row for row in encounter_slots_data}
47+
location_areas_lookup = {row["id"]: row for row in location_areas_data}
48+
49+
game_configs = list(GAME_CONFIGS.values())

0 commit comments

Comments
 (0)