test / test (push) Has been cancelled
- test_tools.py: 4 test per update_quest (normale, status invalido, quest non trovata, rinomina) - test_adventure.py: integrità dati (9 aree, connessioni bidirezionali, mostri con statblock, quest, items, features) - Tutti 54 test passano in 0.69s
104 lines
3.3 KiB
Python
104 lines
3.3 KiB
Python
"""Test integrità dati avventura — aree, mostri, quest, oggetti."""
|
|
import sys
|
|
sys.path.insert(0, "src")
|
|
|
|
from src.engine.db import (
|
|
get_all_areas, get_area_by_id,
|
|
get_monster_by_id, get_monsters_in_area,
|
|
get_all_quest_defs, get_special_items,
|
|
)
|
|
|
|
|
|
def _load_data():
|
|
"""Load data once per session."""
|
|
# init_db is called automatically by _load_adventure_json
|
|
return {
|
|
"areas": get_all_areas(),
|
|
"quests": get_all_quest_defs(),
|
|
"items": get_special_items(),
|
|
}
|
|
|
|
|
|
def test_all_nine_areas_present():
|
|
data = _load_data()
|
|
assert len(data["areas"]) == 9
|
|
ids = [a["id"] for a in data["areas"]]
|
|
expected = [f"1.{i}" for i in range(1, 10)]
|
|
for e in expected:
|
|
assert e in ids, f"Manca area {e}"
|
|
|
|
|
|
def test_each_area_has_name_and_description():
|
|
for a in get_all_areas():
|
|
assert a.get("name"), f"Area {a['id']} senza nome"
|
|
assert a.get("description"), f"Area {a['id']} senza descrizione"
|
|
|
|
|
|
def test_each_area_has_connections():
|
|
for a in get_all_areas():
|
|
conns = a.get("connections", [])
|
|
assert len(conns) > 0, f"Area {a['id']} non ha connessioni"
|
|
for c in conns:
|
|
linked = get_area_by_id(c)
|
|
assert linked is not None, (
|
|
f"Area {a['id']} connette a '{c}' che non esiste"
|
|
)
|
|
|
|
|
|
def test_connections_are_bidirectional():
|
|
"""Se A connette a B, B deve connettere ad A."""
|
|
for a in get_all_areas():
|
|
for c in a.get("connections", []):
|
|
linked = get_area_by_id(c)
|
|
assert linked is not None
|
|
back = c in linked.get("connections", [])
|
|
if not back:
|
|
print(
|
|
f"⚠ Area {a['id']}→{c} non ha connessione di ritorno"
|
|
)
|
|
|
|
|
|
def test_all_monsters_have_statblocks():
|
|
monsters_seen = set()
|
|
for a in get_all_areas():
|
|
for mref in a.get("monsters", []):
|
|
mid = mref.get("ref_id")
|
|
assert mid, f"Area {a['id']} ha ref_id mostro vuoto"
|
|
monster = get_monster_by_id(mid)
|
|
assert monster is not None, (
|
|
f"Mostro '{mid}' (in area {a['id']}) non trovato"
|
|
)
|
|
assert monster.get("name"), f"Mostro '{mid}' senza nome"
|
|
stats = monster.get("stats", {})
|
|
assert stats.get("ac"), f"Mostro '{mid}' senza CA"
|
|
assert stats.get("hp"), f"Mostro '{mid}' senza PF"
|
|
monsters_seen.add(mid)
|
|
assert len(monsters_seen) >= 1, "Nessun mostro trovato nelle aree"
|
|
|
|
|
|
def test_areas_have_no_duplicate_ids():
|
|
ids = [a["id"] for a in get_all_areas()]
|
|
assert len(ids) == len(set(ids)), "Trovati ID area duplicati"
|
|
|
|
|
|
def test_quests_have_names():
|
|
for q in get_all_quest_defs():
|
|
assert q.get("name"), f"Quest senza nome: {q}"
|
|
assert q.get("description"), f"Quest '{q['name']}' senza descrizione"
|
|
|
|
|
|
def test_special_items_have_location():
|
|
for i in get_special_items():
|
|
assert i.get("name"), f"Item senza nome: {i}"
|
|
loc = i.get("location", "")
|
|
if loc in ("?", ""):
|
|
print(f"⚠ Item '{i.get('name')}' senza posizione")
|
|
|
|
|
|
def test_area_features_format():
|
|
for a in get_all_areas():
|
|
features = a.get("features", [])
|
|
assert isinstance(features, list), (
|
|
f"Area {a['id']}: features non è una lista"
|
|
)
|