80 lines
2.3 KiB
Python
80 lines
2.3 KiB
Python
import pytest
|
|
from click.exceptions import FileError
|
|
|
|
from docforge.cli.mkdocs_utils import (
|
|
_strip_scope,
|
|
build_lib_nav,
|
|
build_wiki_nav_block,
|
|
load_spec_icon,
|
|
)
|
|
|
|
|
|
def test_strip_scope_nested_entries():
|
|
block = [
|
|
{"Home": "wiki/index.md"},
|
|
{
|
|
"Development": [
|
|
{"Environment": "wiki/05_development/01_environment.md"},
|
|
"wiki/05_development/02_quality_gates.md",
|
|
]
|
|
},
|
|
]
|
|
stripped = _strip_scope(block, "wiki")
|
|
assert stripped == [
|
|
{"Home": "index.md"},
|
|
{
|
|
"Development": [
|
|
{"Environment": "05_development/01_environment.md"},
|
|
"05_development/02_quality_gates.md",
|
|
]
|
|
},
|
|
]
|
|
|
|
|
|
def test_strip_scope_leaves_unscoped_paths():
|
|
block = [{"Other": "static/pages.md"}]
|
|
assert _strip_scope(block, "lib") == [{"Other": "static/pages.md"}]
|
|
|
|
|
|
def test_build_lib_nav_reroots_group_paths(tmp_path):
|
|
docs = tmp_path / "docs"
|
|
lib = docs / "lib" / "testpkg"
|
|
lib.mkdir(parents=True)
|
|
(lib / "index.md").write_text("# Pkg", encoding="utf-8")
|
|
(lib / "mod.md").write_text("# Mod", encoding="utf-8")
|
|
|
|
nav_file = tmp_path / "docforge.nav.yml"
|
|
nav_file.write_text(
|
|
"home: lib/testpkg/index.md\n"
|
|
"groups:\n"
|
|
" Reference:\n"
|
|
" - lib/testpkg/mod.md\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
block, icon = build_lib_nav(nav_file, docs)
|
|
assert block == [{"Home": "testpkg/index.md"}, {"Reference": ["testpkg/mod.md"]}]
|
|
assert icon is None
|
|
|
|
|
|
def test_build_lib_nav_missing_spec_raises(tmp_path):
|
|
with pytest.raises(FileError):
|
|
build_lib_nav(tmp_path / "missing.yml", tmp_path)
|
|
|
|
|
|
def test_build_wiki_nav_block_reroots_entries(tmp_path):
|
|
wiki = tmp_path / "docs" / "wiki"
|
|
wiki.mkdir(parents=True)
|
|
(wiki / "index.md").write_text("# Home", encoding="utf-8")
|
|
(wiki / "01_overview.md").write_text("# Overview", encoding="utf-8")
|
|
|
|
block = build_wiki_nav_block(wiki)
|
|
assert block == [{"Home": "index.md"}, {"Overview": "01_overview.md"}]
|
|
|
|
|
|
def test_load_spec_icon(tmp_path):
|
|
nav_file = tmp_path / "docforge.nav.yml"
|
|
nav_file.write_text("home: index.md\nicon:\n logo: material/code-tags\n")
|
|
assert load_spec_icon(nav_file) == {"logo": "material/code-tags"}
|
|
assert load_spec_icon(tmp_path / "missing.yml") is None
|