mud/tests/test_hub_zone.py

67 lines
2.2 KiB
Python

"""Tests for the hub zone."""
import pathlib
from mudlib.zones import load_zone
def test_load_hub_zone():
"""Load the hub zone from TOML file."""
project_root = pathlib.Path(__file__).resolve().parents[1]
hub_path = project_root / "content" / "zones" / "hub.toml"
zone = load_zone(hub_path)
assert zone.name == "hub"
assert zone.width == 15
assert zone.height == 15
assert zone.toroidal is False
assert zone.spawn_x == 7
assert zone.spawn_y == 7
def test_hub_zone_has_portals():
"""Hub zone has portals to overworld, tavern, and treehouse."""
project_root = pathlib.Path(__file__).resolve().parents[1]
hub_path = project_root / "content" / "zones" / "hub.toml"
zone = load_zone(hub_path)
# Find portals in zone contents
portals = [obj for obj in zone._contents if obj.__class__.__name__ == "Portal"]
assert len(portals) == 3
# Check that we have portals to each target zone
target_zones = {p.target_zone for p in portals}
assert target_zones == {"overworld", "tavern", "treehouse"}
def test_hub_zone_portals_at_correct_positions():
"""Portals are at expected coordinates on the map."""
project_root = pathlib.Path(__file__).resolve().parents[1]
hub_path = project_root / "content" / "zones" / "hub.toml"
zone = load_zone(hub_path)
portals = [obj for obj in zone._contents if obj.__class__.__name__ == "Portal"]
# North portal to overworld at (7, 0)
overworld_portal = [p for p in portals if p.target_zone == "overworld"][0]
assert overworld_portal.x == 7
assert overworld_portal.y == 0
assert overworld_portal.target_x == 500
assert overworld_portal.target_y == 500
# East portal to tavern at (14, 7)
tavern_portal = [p for p in portals if p.target_zone == "tavern"][0]
assert tavern_portal.x == 14
assert tavern_portal.y == 7
assert tavern_portal.target_x == 4
assert tavern_portal.target_y == 5
# South portal to treehouse at (7, 14)
treehouse_portal = [p for p in portals if p.target_zone == "treehouse"][0]
assert treehouse_portal.x == 7
assert treehouse_portal.y == 14
assert treehouse_portal.target_x == 0
assert treehouse_portal.target_y == 7