86 lines
3.3 KiB
Python
86 lines
3.3 KiB
Python
|
|
"""Tests for MD→DOCX builder (FR-200, FR-501–508)."""
|
|||
|
|
|
|||
|
|
from __future__ import annotations
|
|||
|
|
|
|||
|
|
from pathlib import Path
|
|||
|
|
|
|||
|
|
from markidocx.builder import build_document
|
|||
|
|
from markidocx.manifest import load_manifest
|
|||
|
|
|
|||
|
|
|
|||
|
|
class TestBuildDocument:
|
|||
|
|
def test_build_produces_docx(self, tmp_project: Path) -> None:
|
|||
|
|
manifest = load_manifest(tmp_project / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.success
|
|||
|
|
assert result.output_path.exists()
|
|||
|
|
assert result.output_path.suffix == ".docx"
|
|||
|
|
|
|||
|
|
def test_build_result_has_family_and_level(self, tmp_project: Path) -> None:
|
|||
|
|
manifest = load_manifest(tmp_project / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.family == "article"
|
|||
|
|
assert result.feature_level == "level1"
|
|||
|
|
|
|||
|
|
def test_build_creates_output_dir(self, tmp_path: Path) -> None:
|
|||
|
|
(tmp_path / "doc.md").write_text("# Hello\n\nContent.", encoding="utf-8")
|
|||
|
|
import yaml
|
|||
|
|
|
|||
|
|
(tmp_path / "manifest.yaml").write_text(
|
|||
|
|
yaml.dump(
|
|||
|
|
{
|
|||
|
|
"project": {"name": "Test", "feature_level": "level1", "family": "article"},
|
|||
|
|
"sources": [{"path": "doc.md"}],
|
|||
|
|
"output": {"dir": "./out/nested"},
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
manifest = load_manifest(tmp_path / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.success
|
|||
|
|
assert result.output_path.exists()
|
|||
|
|
|
|||
|
|
def test_build_all_families(self, tmp_path: Path) -> None:
|
|||
|
|
import yaml
|
|||
|
|
|
|||
|
|
(tmp_path / "doc.md").write_text("# Hello\n\nContent.", encoding="utf-8")
|
|||
|
|
for family in ("article", "book", "website"):
|
|||
|
|
(tmp_path / "manifest.yaml").write_text(
|
|||
|
|
yaml.dump(
|
|||
|
|
{
|
|||
|
|
"project": {"name": family, "feature_level": "level1", "family": family},
|
|||
|
|
"sources": [{"path": "doc.md"}],
|
|||
|
|
"output": {"dir": f"./dist/{family}"},
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
manifest = load_manifest(tmp_path / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.success, f"Build failed for family {family}"
|
|||
|
|
assert result.output_path.exists()
|
|||
|
|
|
|||
|
|
def test_build_with_metadata(self, tmp_path: Path) -> None:
|
|||
|
|
import yaml
|
|||
|
|
|
|||
|
|
(tmp_path / "doc.md").write_text("# Hello\n\nContent.", encoding="utf-8")
|
|||
|
|
(tmp_path / "manifest.yaml").write_text(
|
|||
|
|
yaml.dump(
|
|||
|
|
{
|
|||
|
|
"project": {"name": "Meta Doc", "feature_level": "level1", "family": "article"},
|
|||
|
|
"sources": [{"path": "doc.md"}],
|
|||
|
|
"output": {"dir": "./dist"},
|
|||
|
|
"metadata": {"title": "My Title", "author": "Alice"},
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
)
|
|||
|
|
manifest = load_manifest(tmp_path / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.success
|
|||
|
|
|
|||
|
|
def test_build_level1_constructs(self, tmp_project: Path) -> None:
|
|||
|
|
"""Build with headings, lists, tables present in SIMPLE_MARKDOWN."""
|
|||
|
|
manifest = load_manifest(tmp_project / "manifest.yaml")
|
|||
|
|
result = build_document(manifest)
|
|||
|
|
assert result.success
|
|||
|
|
assert not result.errors
|