nav submodule
This commit is contained in:
71
tests/nav/test_spec.py
Normal file
71
tests/nav/test_spec.py
Normal file
@@ -0,0 +1,71 @@
|
||||
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
|
||||
Reference in New Issue
Block a user