79 lines
2 KiB
Python
79 lines
2 KiB
Python
"""Tests for TOML help topic loading."""
|
|
|
|
import textwrap
|
|
|
|
import pytest
|
|
|
|
from mudlib.content import load_help_topics
|
|
|
|
|
|
@pytest.fixture
|
|
def help_dir(tmp_path):
|
|
"""Create a temp directory with sample help TOML files."""
|
|
topic = tmp_path / "combat.toml"
|
|
topic.write_text(
|
|
textwrap.dedent("""\
|
|
name = "combat"
|
|
title = "combat primer"
|
|
body = \"\"\"
|
|
combat is initiated when you attack another entity.
|
|
use skills to learn your available moves.
|
|
\"\"\"
|
|
""")
|
|
)
|
|
|
|
admin_topic = tmp_path / "building.toml"
|
|
admin_topic.write_text(
|
|
textwrap.dedent("""\
|
|
name = "building"
|
|
title = "builder's guide"
|
|
admin = true
|
|
body = \"\"\"
|
|
use @dig to create zones and @paint to edit terrain.
|
|
\"\"\"
|
|
""")
|
|
)
|
|
return tmp_path
|
|
|
|
|
|
def test_load_help_topics(help_dir):
|
|
topics = load_help_topics(help_dir)
|
|
assert "combat" in topics
|
|
assert "building" in topics
|
|
|
|
|
|
def test_help_topic_fields(help_dir):
|
|
topics = load_help_topics(help_dir)
|
|
combat = topics["combat"]
|
|
assert combat.name == "combat"
|
|
assert combat.title == "combat primer"
|
|
assert combat.admin is False
|
|
assert "combat is initiated" in combat.body
|
|
|
|
|
|
def test_help_topic_admin_flag(help_dir):
|
|
topics = load_help_topics(help_dir)
|
|
building = topics["building"]
|
|
assert building.admin is True
|
|
|
|
|
|
def test_help_topic_title_defaults_to_name(tmp_path):
|
|
topic = tmp_path / "simple.toml"
|
|
topic.write_text('name = "simple"\nbody = "just a test"\n')
|
|
topics = load_help_topics(tmp_path)
|
|
assert topics["simple"].title == "simple"
|
|
|
|
|
|
def test_load_help_topics_empty_dir(tmp_path):
|
|
topics = load_help_topics(tmp_path)
|
|
assert topics == {}
|
|
|
|
|
|
def test_load_help_topics_skips_bad_files(tmp_path):
|
|
bad = tmp_path / "broken.toml"
|
|
bad.write_text("not valid toml [[[")
|
|
good = tmp_path / "good.toml"
|
|
good.write_text('name = "good"\nbody = "works"\n')
|
|
topics = load_help_topics(tmp_path)
|
|
assert "good" in topics
|
|
assert "broken" not in topics
|