Something went wrong. Try again.
A 5e storytelling engine with an LLM DM
Something went wrong. Try again.
Python
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768"""Tests for the DM notification channel."""
from pathlib import Path
import pytest
from storied import notifications
@pytest.fixturedef world(tmp_path: Path) -> str: """Return the world_id with world directory created under the autouse-isolated data home.""" world_dir = tmp_path / "worlds" / "test-world" world_dir.mkdir(parents=True) return "test-world"
class TestAppendAndDrain: def test_drain_empty(self, world: str): assert notifications.drain(world) == []
def test_append_then_drain(self, world: str): notifications.append(world, "Something happened")
messages = notifications.drain(world) assert messages == ["Something happened"]
def test_drain_clears(self, world: str): notifications.append(world, "First")
notifications.drain(world) assert notifications.drain(world) == []
def test_multiple_messages(self, world: str): notifications.append(world, "First thing") notifications.append(world, "Second thing") notifications.append(world, "Third thing")
messages = notifications.drain(world) assert messages == ["First thing", "Second thing", "Third thing"]
def test_file_removed_after_drain(self, world: str, tmp_path: Path): notifications.append(world, "Temporary")
notifications.drain(world) path = tmp_path / "worlds" / "test-world" / "dm_notifications.md" assert not path.exists()
def test_creates_world_dir_if_missing(self): notifications.append("new-world", "Hello")
messages = notifications.drain("new-world") assert messages == ["Hello"]
def test_drain_empty_existing_file_returns_empty( self, world: str, tmp_path: Path, ): """An existing notifications file with only whitespace drains as empty and is removed.""" path = tmp_path / "worlds" / "test-world" / "dm_notifications.md" path.write_text(" \n \n")
assert notifications.drain(world) == [] assert not path.exists()