52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
|
|
"""Tests for template family registry (FR-600)."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
import pytest
|
||
|
|
|
||
|
|
from markidocx.templates import FamilyRegistry, RegistrationError
|
||
|
|
|
||
|
|
|
||
|
|
class TestFamilyRegistry:
|
||
|
|
def test_lists_three_builtin_families(self) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
families = registry.list_families()
|
||
|
|
names = {f.name for f in families}
|
||
|
|
assert names == {"article", "book", "website"}
|
||
|
|
|
||
|
|
def test_get_existing_family(self) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
info = registry.get("article")
|
||
|
|
assert info is not None
|
||
|
|
assert info.name == "article"
|
||
|
|
assert info.description
|
||
|
|
|
||
|
|
def test_get_missing_family_returns_none(self) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
assert registry.get("nonexistent") is None
|
||
|
|
|
||
|
|
def test_register_invalid_path_raises(self, tmp_path: Path) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
with pytest.raises(RegistrationError, match="not found"):
|
||
|
|
registry.register(tmp_path / "missing.docx", "custom")
|
||
|
|
|
||
|
|
def test_register_non_docx_raises(self, tmp_path: Path) -> None:
|
||
|
|
f = tmp_path / "template.txt"
|
||
|
|
f.write_text("not a docx")
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
with pytest.raises(RegistrationError, match=".docx"):
|
||
|
|
registry.register(f, "custom")
|
||
|
|
|
||
|
|
def test_create_document_for_each_family(self) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
for family in ("article", "book", "website"):
|
||
|
|
doc = registry.create_document(family)
|
||
|
|
assert doc is not None
|
||
|
|
|
||
|
|
def test_create_document_unknown_family_falls_back(self) -> None:
|
||
|
|
registry = FamilyRegistry()
|
||
|
|
doc = registry.create_document("unknown")
|
||
|
|
assert doc is not None
|