from pathlib import Path import pytest from content_build.errors import BuildError from content_build.parse import parse_bible BIBLE = """# A bible Some prose that must be ignored. ```yaml id: town.a type: town status: canon secrecy: 0 related: [] body: > Town A. ``` More prose. ```yaml id: rumor.x type: rumor status: canon secrecy: 1 related: [town.a] body: > A rumor. ``` """ def _write(tmp_path: Path, text: str) -> Path: p = tmp_path / "bible.md" p.write_text(text) return p def test_extracts_yaml_blocks_and_ignores_prose(tmp_path): entries = parse_bible(_write(tmp_path, BIBLE)) assert [e.data["id"] for e in entries] == ["town.a", "rumor.x"] def test_source_carries_filename_and_line(tmp_path): entries = parse_bible(_write(tmp_path, BIBLE)) assert entries[0].source.startswith("bible.md:") def test_unterminated_block_raises(tmp_path): bad = "```yaml\nid: town.a\n" # no closing fence with pytest.raises(BuildError): parse_bible(_write(tmp_path, bad)) def test_non_mapping_block_raises(tmp_path): bad = "```yaml\n- just\n- a\n- list\n```\n" with pytest.raises(BuildError): parse_bible(_write(tmp_path, bad))