28 lines
933 B
Python
28 lines
933 B
Python
import json
|
|
|
|
import app.content as content
|
|
|
|
|
|
def test_load_npc_returns_parsed_file(tmp_path, monkeypatch):
|
|
root = tmp_path / "content"
|
|
(root / "world" / "npcs").mkdir(parents=True)
|
|
(root / "world" / "npcs" / "fenn.json").write_text(
|
|
json.dumps({"id": "fenn", "name": "Fenn", "persona": "clerk",
|
|
"knowledge": ["a"], "capabilities": {}})
|
|
)
|
|
monkeypatch.setenv("CONTENT_ROOT", str(root))
|
|
npc = content.load_npc("fenn")
|
|
assert npc["name"] == "Fenn"
|
|
assert npc["knowledge"] == ["a"]
|
|
|
|
|
|
def test_load_npc_unknown_returns_none(tmp_path, monkeypatch):
|
|
(tmp_path / "content" / "world").mkdir(parents=True)
|
|
monkeypatch.setenv("CONTENT_ROOT", str(tmp_path / "content"))
|
|
assert content.load_npc("nobody") is None
|
|
|
|
|
|
def test_content_root_env_override(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("CONTENT_ROOT", str(tmp_path))
|
|
assert content._content_root() == tmp_path
|