chore(release): 0.0.7
Squash-merge lib-standardisation: adopt repo standards across packaging, tooling, docs, and CI. - standardize pyproject.toml (canonical packaging, lint config, extras, GSDFC pydoclint) - add py.typed marker, modernize type hints and Google-style docstrings - nest generated docs under docs/lib and docs/mcp; add hand-written wiki - adopt standard Type A PyPI CI pipeline (tag==version guard + quality gate) - promote generated CHANGELOG.md; bump version to 0.0.7
This commit is contained in:
165
tests/cli/test_build_wiki.py
Normal file
165
tests/cli/test_build_wiki.py
Normal file
@@ -0,0 +1,165 @@
|
||||
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_wiki_existing_config_used_verbatim_without_refresh(
|
||||
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")
|
||||
|
||||
config = cwd / "docs" / "mkdocs.wiki.yml"
|
||||
sentinel = "site_name: Custom Wiki\nnav: []\n"
|
||||
config.write_text(sentinel, 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
|
||||
assert config.read_text(encoding="utf-8") == sentinel
|
||||
assert "Using existing MkDocs config" in result.output
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user