Files
mytoolkit/tests/test_cli_smoke.py
Zhengshou Lai 06704acf60 test: add pytest suite — CLI smoke + config/templates/md_to_pdf units
- tests/conftest.py redirects MYTOOLKIT_HOME to a temp dir before imports
  so the module-level Config singleton never touches the real ~/.mytoolkit
- CLI smoke: every registered command answers --help with exit code 0
- unit tests: Config get/set/migrate, templates_registry override/fallback,
  md_to_pdf pure helpers (pandoc-dependent cases skipif-guarded)
- pyproject: dev dependency group (pytest) + pytest config; Makefile: make test
2026-07-18 11:45:40 +08:00

42 lines
1.3 KiB
Python

"""CLI smoke tests: import chain, command registration, --help exit codes."""
from click.testing import CliRunner
from mytoolkit.cli import cli
def test_top_level_help():
result = CliRunner().invoke(cli, ["--help"])
assert result.exit_code == 0
assert "convert" in result.output
def test_every_registered_command_help():
"""Every top-level command/group must respond to --help cleanly.
Catches broken imports and registration mistakes — the most common
ways a CLI dies.
"""
assert len(cli.commands) >= 15, "suspiciously few commands registered"
for name in sorted(cli.commands):
result = CliRunner().invoke(cli, [name, "--help"])
assert result.exit_code == 0, f"{name} --help failed:\n{result.output}"
def test_info_paths():
result = CliRunner().invoke(cli, ["info", "paths"])
assert result.exit_code == 0
for key in ("package:", "templates:", "references:", "scaffolds:"):
assert key in result.output
def test_info_docs_convert():
result = CliRunner().invoke(cli, ["info", "docs", "convert"])
assert result.exit_code == 0
assert result.output.strip(), "info docs convert printed nothing"
def test_info_docs_missing_name_fails():
result = CliRunner().invoke(cli, ["info", "docs", "no-such-doc"])
assert result.exit_code != 0