139 lines
3.8 KiB
Python
139 lines
3.8 KiB
Python
from pathlib import Path
|
|
|
|
from docforge.cli.main import cli
|
|
|
|
|
|
def test_wiki_only_build_requires_no_module(
|
|
cli_runner,
|
|
mock_mkdocs_build,
|
|
mock_mkdocs_load_config,
|
|
):
|
|
with cli_runner.isolated_filesystem():
|
|
cwd = Path.cwd()
|
|
|
|
wiki = cwd / "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")
|
|
|
|
result = cli_runner.invoke(
|
|
cli,
|
|
[
|
|
"build",
|
|
"--wiki",
|
|
"--site-name",
|
|
"Wiki Site",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0, result.output
|
|
assert mock_mkdocs_build() is True
|
|
config = cwd / "docs" / "mkdocs.wiki.yml"
|
|
assert config.exists()
|
|
|
|
content = config.read_text(encoding="utf-8")
|
|
assert "docs_dir: wiki" in content
|
|
assert "site_dir: ../site/wiki" in content
|
|
assert "Home: index.md" in content
|
|
assert "Overview: 01_overview.md" in content
|
|
|
|
|
|
def test_wiki_and_mkdocs_emit_separate_configs(
|
|
cli_runner,
|
|
mock_mkdocs_build,
|
|
mock_mkdocs_load_config,
|
|
):
|
|
with cli_runner.isolated_filesystem():
|
|
cwd = Path.cwd()
|
|
|
|
pkg = cwd / "testpkg"
|
|
pkg.mkdir()
|
|
(pkg / "__init__.py").write_text("")
|
|
(pkg / "mod.py").write_text("def f(): ...\n")
|
|
|
|
nav_file = cwd / "docforge.nav.yml"
|
|
nav_file.write_text(
|
|
"home: lib/testpkg/index.md\ngroups: {}\n",
|
|
encoding="utf-8",
|
|
)
|
|
|
|
wiki = cwd / "docs" / "wiki"
|
|
wiki.mkdir(parents=True)
|
|
(wiki / "index.md").write_text("# Home", encoding="utf-8")
|
|
|
|
result = cli_runner.invoke(
|
|
cli,
|
|
[
|
|
"build",
|
|
"--mkdocs",
|
|
"--wiki",
|
|
"--module",
|
|
"testpkg",
|
|
"--site-name",
|
|
"Split Site",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code == 0, result.output
|
|
assert mock_mkdocs_build() is True
|
|
assert (cwd / "docs" / "lib" / "testpkg" / "mod.md").exists()
|
|
|
|
lib_config = (cwd / "docs" / "mkdocs.lib.yml").read_text(encoding="utf-8")
|
|
wiki_config = (cwd / "docs" / "mkdocs.wiki.yml").read_text(encoding="utf-8")
|
|
|
|
assert "docs_dir: lib" in lib_config
|
|
assert "site_dir: ../site/lib" in lib_config
|
|
assert "Home: testpkg/index.md" in lib_config
|
|
|
|
assert "docs_dir: wiki" in wiki_config
|
|
assert "site_dir: ../site/wiki" in wiki_config
|
|
assert "Home: index.md" in wiki_config
|
|
|
|
|
|
def test_wiki_without_module_flag_ok(
|
|
cli_runner,
|
|
mock_mkdocs_build,
|
|
mock_mkdocs_load_config,
|
|
):
|
|
with cli_runner.isolated_filesystem():
|
|
cwd = Path.cwd()
|
|
|
|
wiki = cwd / "docs" / "wiki"
|
|
wiki.mkdir(parents=True)
|
|
(wiki / "index.md").write_text("# Home", encoding="utf-8")
|
|
|
|
result = cli_runner.invoke(
|
|
cli,
|
|
["build", "--wiki", "--site-name", "S"],
|
|
)
|
|
|
|
assert result.exit_code == 0, result.output
|
|
assert mock_mkdocs_build() is True
|
|
|
|
|
|
def test_missing_wiki_dir_errors(cli_runner, mock_mkdocs_build):
|
|
with cli_runner.isolated_filesystem():
|
|
cwd = Path.cwd()
|
|
(cwd / "docs").mkdir()
|
|
|
|
result = cli_runner.invoke(
|
|
cli,
|
|
[
|
|
"build",
|
|
"--wiki",
|
|
"--site-name",
|
|
"S",
|
|
"--wiki-dir",
|
|
"docs/wiki",
|
|
],
|
|
)
|
|
|
|
assert result.exit_code != 0
|
|
assert "Wiki dir not found" in result.output
|
|
|
|
|
|
def test_no_flag_raises_usage_error(cli_runner):
|
|
result = cli_runner.invoke(cli, ["build"])
|
|
assert result.exit_code != 0
|
|
assert "--mcp, --mkdocs, --wiki, or --api" in result.output
|