hatchimera / tests /test_compendium.py
arkai2025's picture
feat(compendium): data module + report tool + first 12 creatures
0e1479c
Raw
History Blame Contribute Delete
1.37 kB
from buddy_fusion import compendium
from buddy_fusion.compendium_data import COMPENDIUM
from buddy_fusion.boxes import repair_boxes
def test_compendium_non_empty():
assert len(COMPENDIUM) >= 10
def test_unique_ids():
ids = [e["id"] for e in COMPENDIUM]
assert len(ids) == len(set(ids)), "compendium ids must be unique"
def test_entries_are_repair_clean():
# Every authored entry must survive repair_boxes unchanged in length (sizes
# already 1-8, all keys present) so the renderer never drops geometry.
for e in COMPENDIUM:
assert e["name"] and e["theme"]
cleaned = repair_boxes(e["boxes"])
assert len(cleaned) == len(e["boxes"]), f"{e['id']} has boxes repair would drop"
for b in e["boxes"]:
assert {"x", "y", "z", "w", "h", "d", "color"} <= set(b)
assert 1 <= b["w"] <= 8 and 1 <= b["h"] <= 8 and 1 <= b["d"] <= 8
def test_as_genome_is_freeform():
g = compendium.as_genome(COMPENDIUM[0])
assert g.boxes and len(g.boxes) == len(COMPENDIUM[0]["boxes"])
assert g.name == COMPENDIUM[0]["name"]
def test_random_sample_distinct():
s = compendium.random_sample(2)
assert len(s) == 2 and s[0]["id"] != s[1]["id"]
def test_get_by_id():
first = COMPENDIUM[0]
assert compendium.get(first["id"]) is first
assert compendium.get("nonexistent-id") is None