feat(content-build): typed Entry model + category predicates
This commit is contained in:
50
tools/content_build/tests/test_model.py
Normal file
50
tools/content_build/tests/test_model.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import pytest
|
||||
|
||||
from content_build.errors import BuildError
|
||||
from content_build.model import Entry, entry_from_raw
|
||||
from content_build.parse import RawEntry
|
||||
|
||||
|
||||
def _raw(**over) -> RawEntry:
|
||||
data = {"id": "town.a", "type": "town", "status": "canon",
|
||||
"secrecy": 0, "related": []}
|
||||
data.update(over)
|
||||
return RawEntry(data=data, source="t:1")
|
||||
|
||||
|
||||
def test_namespace_and_slug():
|
||||
e = entry_from_raw(_raw(id="npc.mera-fenn", type="person",
|
||||
start_disposition="cold",
|
||||
knows=[{"fact": "rumor.x", "gate": "warm"}]))
|
||||
assert e.namespace == "npc"
|
||||
assert e.slug == "mera-fenn"
|
||||
|
||||
|
||||
def test_category_predicates():
|
||||
npc = entry_from_raw(_raw(id="npc.t", type="person",
|
||||
start_disposition="cold",
|
||||
knows=[{"fact": "rumor.x", "gate": "warm"}]))
|
||||
person = entry_from_raw(_raw(id="person.p", type="person"))
|
||||
rumor = entry_from_raw(_raw(id="rumor.x", type="rumor", secrecy=1))
|
||||
assert npc.is_npc_layer and not npc.is_canon_entity
|
||||
assert person.is_canon_entity and not person.is_npc_layer
|
||||
assert rumor.is_knowledge and not rumor.is_canon_entity
|
||||
|
||||
|
||||
def test_knows_parsed_into_links():
|
||||
e = entry_from_raw(_raw(id="npc.t", type="person", start_disposition="cold",
|
||||
knows=[{"fact": "rumor.x", "gate": "neutral"}]))
|
||||
assert e.knows[0].fact_id == "rumor.x"
|
||||
assert e.knows[0].gate == "neutral"
|
||||
|
||||
|
||||
def test_missing_required_field_raises():
|
||||
bad = RawEntry(data={"id": "town.a", "type": "town"}, source="t:1")
|
||||
with pytest.raises(BuildError):
|
||||
entry_from_raw(bad)
|
||||
|
||||
|
||||
def test_knows_missing_gate_raises():
|
||||
with pytest.raises(BuildError):
|
||||
entry_from_raw(_raw(id="npc.t", type="person", start_disposition="cold",
|
||||
knows=[{"fact": "rumor.x"}]))
|
||||
Reference in New Issue
Block a user