124 lines
2.5 KiB
Python
124 lines
2.5 KiB
Python
from pathlib import Path
|
|
|
|
import yaml
|
|
from click.testing import CliRunner
|
|
|
|
from docforge.cli.main import cli
|
|
|
|
|
|
def _write_nav_spec(path: Path) -> None:
|
|
path.write_text(
|
|
"""
|
|
home: openapi_first/index.md
|
|
groups:
|
|
Core:
|
|
- openapi_first/app.md
|
|
- openapi_first/client.md
|
|
""".strip(),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
|
|
def _write_docs(docs: Path) -> None:
|
|
files = [
|
|
"openapi_first/index.md",
|
|
"openapi_first/app.md",
|
|
"openapi_first/client.md",
|
|
]
|
|
for rel in files:
|
|
p = docs / rel
|
|
p.parent.mkdir(parents=True, exist_ok=True)
|
|
p.write_text(f"# {rel}", encoding="utf-8")
|
|
|
|
|
|
def test_mkdocs_uses_builtin_template(tmp_path: Path) -> None:
|
|
docs = tmp_path / "docs"
|
|
docs.mkdir()
|
|
|
|
nav_file = tmp_path / "docforge.nav.yml"
|
|
out_file = tmp_path / "mkdocs.yml"
|
|
|
|
_write_docs(docs)
|
|
_write_nav_spec(nav_file)
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
cli,
|
|
[
|
|
"mkdocs",
|
|
"--site-name",
|
|
"DocForge",
|
|
"--docs-dir",
|
|
str(docs),
|
|
"--nav",
|
|
str(nav_file),
|
|
"--out",
|
|
str(out_file),
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert out_file.exists()
|
|
|
|
|
|
def test_mkdocs_overrides_template(tmp_path: Path) -> None:
|
|
docs = tmp_path / "docs"
|
|
docs.mkdir()
|
|
|
|
nav_file = tmp_path / "docforge.nav.yml"
|
|
template = tmp_path / "custom.yml"
|
|
out_file = tmp_path / "mkdocs.yml"
|
|
|
|
_write_docs(docs)
|
|
_write_nav_spec(nav_file)
|
|
|
|
template.write_text(
|
|
"""
|
|
site_name: Custom Site
|
|
theme:
|
|
name: readthedocs
|
|
""".strip(),
|
|
encoding="utf-8",
|
|
)
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
cli,
|
|
[
|
|
"mkdocs",
|
|
"--site-name",
|
|
"Override Site",
|
|
"--docs-dir",
|
|
str(docs),
|
|
"--nav",
|
|
str(nav_file),
|
|
"--template",
|
|
str(template),
|
|
"--out",
|
|
str(out_file),
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0
|
|
assert out_file.exists()
|
|
|
|
|
|
def test_mkdocs_missing_nav_fails(tmp_path: Path) -> None:
|
|
docs = tmp_path / "docs"
|
|
docs.mkdir()
|
|
|
|
runner = CliRunner()
|
|
result = runner.invoke(
|
|
cli,
|
|
[
|
|
"mkdocs",
|
|
"--site-name",
|
|
"DocForge",
|
|
"--docs-dir",
|
|
str(docs),
|
|
],
|
|
)
|
|
|
|
assert result.exit_code != 0
|
|
assert "Nav spec not found" in result.output
|