94 lines
2.7 KiB
Python
94 lines
2.7 KiB
Python
"""Tests for the map YAML schema (map.py)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from pf1e_simulator.map import MapValidationError, load_map, zone_cells
|
|
|
|
MAPS_DIR = Path(__file__).resolve().parents[1] / "data" / "maps"
|
|
|
|
|
|
def _write(tmp_path: Path, body: str) -> Path:
|
|
target = tmp_path / "map.yaml"
|
|
target.write_text(body, encoding="utf-8")
|
|
return target
|
|
|
|
|
|
def _minimal_map() -> str:
|
|
return """
|
|
name: "Test"
|
|
terrain: |
|
|
###
|
|
#.#
|
|
###
|
|
legend:
|
|
"#": { type: wall, blocks_los: true }
|
|
".": { type: floor, move_cost: 1 }
|
|
"""
|
|
|
|
|
|
def test_sample_arena_loads() -> None:
|
|
spec = load_map(MAPS_DIR / "sample_arena.yaml")
|
|
assert spec.square_size_ft == 5
|
|
assert len(spec.terrain) == 8
|
|
assert all(len(row) == 20 for row in spec.terrain)
|
|
assert spec.legend["#"].move_cost is None
|
|
assert spec.legend["#"].blocks_los is True
|
|
assert spec.legend["C"].cover is True
|
|
assert spec.legend["T"].move_cost == 2
|
|
assert spec.deployment == {"players": "A", "monsters": "B"}
|
|
assert spec.markers["autel"] == (1, 16)
|
|
|
|
|
|
def test_sample_arena_zones_and_elevation() -> None:
|
|
spec = load_map(MAPS_DIR / "sample_arena.yaml")
|
|
assert spec.elevation is not None
|
|
assert spec.elevation[1][2] == "1"
|
|
cells_a = zone_cells(spec, "A")
|
|
assert cells_a == [
|
|
(1, 1), (1, 2), (1, 3), (1, 4),
|
|
(2, 1), (2, 2), (2, 3), (2, 4),
|
|
]
|
|
assert len(zone_cells(spec, "B")) == 8
|
|
|
|
|
|
def test_minimal_map_without_optional_layers(tmp_path: Path) -> None:
|
|
spec = load_map(_write(tmp_path, _minimal_map()))
|
|
assert spec.elevation is None
|
|
assert spec.zones is None
|
|
assert spec.markers == {}
|
|
assert zone_cells(spec, "A") == []
|
|
|
|
|
|
def test_rejects_ragged_rows(tmp_path: Path) -> None:
|
|
body = _minimal_map().replace(" #.#\n", " #.##\n")
|
|
with pytest.raises(MapValidationError):
|
|
load_map(_write(tmp_path, body))
|
|
|
|
|
|
def test_rejects_char_missing_from_legend(tmp_path: Path) -> None:
|
|
body = _minimal_map().replace(" #.#\n", " #x#\n")
|
|
with pytest.raises(MapValidationError):
|
|
load_map(_write(tmp_path, body))
|
|
|
|
|
|
def test_rejects_elevation_dimension_mismatch(tmp_path: Path) -> None:
|
|
body = _minimal_map() + "elevation: |\n 000\n 00\n"
|
|
with pytest.raises(MapValidationError):
|
|
load_map(_write(tmp_path, body))
|
|
|
|
|
|
def test_rejects_marker_out_of_bounds(tmp_path: Path) -> None:
|
|
body = _minimal_map() + "markers:\n autel: [9, 1]\n"
|
|
with pytest.raises(MapValidationError):
|
|
load_map(_write(tmp_path, body))
|
|
|
|
|
|
def test_rejects_deployment_without_zone(tmp_path: Path) -> None:
|
|
body = _minimal_map() + "zones: |\n ...\n .A.\n ...\ndeployment:\n players: B\n"
|
|
with pytest.raises(MapValidationError):
|
|
load_map(_write(tmp_path, body))
|