DEVX-122: feat: consolidate docs checks into devx-docs-check target
This commit is contained in:
@@ -55,6 +55,38 @@ class TestExtractCliCommands:
|
||||
assert "real_cmd" in commands
|
||||
assert "pass" not in commands
|
||||
|
||||
def test_command_with_explicit_name_param(self, tmp_path: Path) -> None:
|
||||
"""When a command uses name="explicit-name", that name is extracted."""
|
||||
fake_cli = tmp_path / "cli.py"
|
||||
fake_cli.write_text(
|
||||
'@click.group()\ndef cli():\n pass\n@cli.command(name="my-command")\ndef my_command():\n pass\n'
|
||||
)
|
||||
commands = extract_cli_commands(tmp_path)
|
||||
assert "my-command" in commands
|
||||
assert "my_command" not in commands
|
||||
|
||||
def test_command_with_help_kwarg_uses_def_name(self, tmp_path: Path) -> None:
|
||||
"""When a command uses help= kwarg but no name=, falls back to def name."""
|
||||
fake_cli = tmp_path / "cli.py"
|
||||
fake_cli.write_text(
|
||||
"@click.group()\ndef cli():\n pass\n"
|
||||
'@cli.command(help="Do something useful")\ndef do_something():\n pass\n'
|
||||
)
|
||||
commands = extract_cli_commands(tmp_path)
|
||||
assert "do_something" in commands
|
||||
assert "Do something useful" not in commands
|
||||
|
||||
def test_command_with_help_translation_uses_def_name(self, tmp_path: Path) -> None:
|
||||
"""When a command uses help=_() translation, falls back to def name."""
|
||||
fake_cli = tmp_path / "cli.py"
|
||||
fake_cli.write_text(
|
||||
"@click.group()\ndef cli():\n pass\n"
|
||||
'@cli.command(help=_("Install and configure things"))\ndef install():\n pass\n'
|
||||
)
|
||||
commands = extract_cli_commands(tmp_path)
|
||||
assert "install" in commands
|
||||
assert "Install and configure things" not in commands
|
||||
|
||||
|
||||
class TestCheckCommandDocumented:
|
||||
def test_finds_command_in_heading(self) -> None:
|
||||
@@ -195,3 +227,171 @@ class TestMain:
|
||||
result = runner.invoke(main, ["--docs-dir", str(docs)])
|
||||
# No source dir found, so no CLI commands, but modules/scripts from REQUIRED lists
|
||||
assert result.exit_code == 0
|
||||
|
||||
def test_ci_scripts_dir_empty_skips_ci_checks(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When --ci-scripts-dir is empty string, CI script checks are skipped."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "devx"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(src / "config.py").write_text("# config")
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("config.py")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--docs-dir", str(docs), "--source-dir", str(src), "--ci-scripts-dir", ""])
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
# Should not mention any CI scripts
|
||||
assert "MISSING" not in result.output or "CI script" not in result.output
|
||||
|
||||
def test_ci_scripts_dir_explicit_path(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When --ci-scripts-dir points to a directory, scripts are detected from there."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "myapp"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
ci_dir = tmp_path / "ci"
|
||||
ci_dir.mkdir()
|
||||
(ci_dir / "my_script.py").write_text("# my script")
|
||||
(ci_dir / "__init__.py").write_text("")
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("my_script.py")
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
main, ["--docs-dir", str(docs), "--source-dir", str(src), "--ci-scripts-dir", str(ci_dir)]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "my_script.py" in result.output
|
||||
assert "OK: my_script.py" in result.output
|
||||
|
||||
def test_ci_scripts_dir_nonexistent_skips(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When --ci-scripts-dir points to a non-existent path, CI checks are skipped."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "myapp"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(
|
||||
main, ["--docs-dir", str(docs), "--source-dir", str(src), "--ci-scripts-dir", "/nonexistent"]
|
||||
)
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
|
||||
def test_config_from_pyproject_ci_scripts_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When [tool.devx.doc_coverage] ci_scripts_dir is set in pyproject.toml, it's used."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "myapp"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(src / "config.py").write_text("# config")
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("config.py")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
# Write pyproject.toml with ci_scripts_dir = ""
|
||||
(tmp_path / "pyproject.toml").write_text('[tool.devx.doc_coverage]\nci_scripts_dir = ""\n')
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--docs-dir", str(docs), "--source-dir", str(src)])
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
|
||||
def test_config_from_pyproject_docs_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When [tool.devx.doc_coverage] docs_dir is set in pyproject.toml, it's used."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
custom_docs = tmp_path / "custom-docs"
|
||||
(custom_docs / "user").mkdir(parents=True)
|
||||
(custom_docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "myapp"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(src / "config.py").write_text("# config")
|
||||
(custom_docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(custom_docs / "tech" / "architecture.md").write_text("config.py")
|
||||
(custom_docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
# Write pyproject.toml with custom docs_dir
|
||||
(tmp_path / "pyproject.toml").write_text(
|
||||
f'[tool.devx.doc_coverage]\ndocs_dir = "{custom_docs}"\nci_scripts_dir = ""\n'
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--source-dir", str(src)])
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
|
||||
def test_config_from_pyproject_source_dir(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When [tool.devx.doc_coverage] source_dir is set in pyproject.toml, it's used."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
custom_src = tmp_path / "custom-src" / "myapp"
|
||||
custom_src.mkdir(parents=True)
|
||||
(custom_src / "__init__.py").write_text("")
|
||||
(custom_src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(custom_src / "config.py").write_text("# config")
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("config.py")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
# Write pyproject.toml with custom source_dir
|
||||
(tmp_path / "pyproject.toml").write_text(
|
||||
f'[tool.devx.doc_coverage]\nsource_dir = "{custom_src}"\nci_scripts_dir = ""\n'
|
||||
)
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--docs-dir", str(docs)])
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
|
||||
def test_config_doc_coverage_not_dict(self, tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""When [tool.devx.doc_coverage] is not a dict, falls back to defaults."""
|
||||
monkeypatch.chdir(tmp_path)
|
||||
docs = tmp_path / "docs"
|
||||
(docs / "user").mkdir(parents=True)
|
||||
(docs / "tech").mkdir(parents=True)
|
||||
src = tmp_path / "src" / "myapp"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("")
|
||||
(src / "cli.py").write_text(
|
||||
"@click.group()\ndef cli():\n pass\n@cli.command('release')\ndef release():\n pass\n"
|
||||
)
|
||||
(src / "config.py").write_text("# config")
|
||||
(docs / "user" / "cli-commands.md").write_text("## release\n")
|
||||
(docs / "tech" / "architecture.md").write_text("config.py")
|
||||
(docs / "tech" / "ci-cd-workflow.md").write_text("")
|
||||
# Write pyproject.toml with doc_coverage as a non-dict value
|
||||
(tmp_path / "pyproject.toml").write_text('[tool.devx]\ndoc_coverage = "not-a-dict"\n')
|
||||
runner = CliRunner()
|
||||
result = runner.invoke(main, ["--docs-dir", str(docs), "--source-dir", str(src)])
|
||||
assert result.exit_code == 0
|
||||
assert "100%" in result.output
|
||||
|
||||
Reference in New Issue
Block a user