72 lines
1.4 KiB
Python
72 lines
1.4 KiB
Python
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from docforge.nav import NavSpec
|
|
|
|
|
|
def test_load_valid_nav_spec(tmp_path: Path):
|
|
nav_yml = tmp_path / "docforge.nav.yml"
|
|
nav_yml.write_text(
|
|
"""
|
|
home: openapi_first/index.md
|
|
|
|
groups:
|
|
Core:
|
|
- openapi_first/app.md
|
|
- openapi_first/client.md
|
|
CLI:
|
|
- openapi_first/cli.md
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
spec = NavSpec.load(nav_yml)
|
|
|
|
assert spec.home == "openapi_first/index.md"
|
|
assert "Core" in spec.groups
|
|
assert spec.groups["Core"] == [
|
|
"openapi_first/app.md",
|
|
"openapi_first/client.md",
|
|
]
|
|
|
|
|
|
def test_missing_file_raises(tmp_path: Path):
|
|
with pytest.raises(FileNotFoundError):
|
|
NavSpec.load(tmp_path / "missing.yml")
|
|
|
|
|
|
def test_invalid_schema_raises(tmp_path: Path):
|
|
nav_yml = tmp_path / "docforge.nav.yml"
|
|
nav_yml.write_text(
|
|
"""
|
|
groups:
|
|
- not_a_mapping
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
with pytest.raises(ValueError):
|
|
NavSpec.load(nav_yml)
|
|
|
|
|
|
def test_all_patterns_includes_home_and_groups(tmp_path: Path):
|
|
nav_yml = tmp_path / "docforge.nav.yml"
|
|
nav_yml.write_text(
|
|
"""
|
|
home: a.md
|
|
groups:
|
|
X:
|
|
- b.md
|
|
- c/*.md
|
|
""",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
spec = NavSpec.load(nav_yml)
|
|
patterns = spec.all_patterns()
|
|
|
|
assert "a.md" in patterns
|
|
assert "b.md" in patterns
|
|
assert "c/*.md" in patterns
|