"""CLI smoke tests: the tool must be invocable as ``python -m govtool``.""" from __future__ import annotations import re from tests.helpers import run_cli SEMVER_ANYWHERE = re.compile(r"\d+\.\d+\.\d+") def test_help_exits_zero(): result = run_cli("--help") assert result.returncode == 0, result.stderr out = (result.stdout + result.stderr).lower() assert "usage" in out or "govtool" in out def test_bare_invocation_does_not_crash(): result = run_cli() # argparse conventionally exits 2 with usage on missing subcommand; # exiting 0 with help is also acceptable. A traceback (exit 1 with # 'Traceback' in stderr) is not. assert result.returncode in (0, 1, 2) assert "Traceback" not in result.stderr, result.stderr def test_unknown_subcommand_fails_cleanly(): result = run_cli("definitely-not-a-real-subcommand") assert result.returncode != 0 assert "Traceback" not in result.stderr, result.stderr def test_version_flag_if_present(): result = run_cli("--version") if result.returncode == 0: assert SEMVER_ANYWHERE.search(result.stdout + result.stderr), ( "--version should print a semantic version" )