Files
computer-playbook/tests/integration/cli/test_help.py
T
kevinveenbirkenbachandClaude Opus 4.7 709f6f73dd refactor(tests/integration): promote remaining top-level tests into topical clusters
Introduce seven new top-level clusters under tests/integration/:
  cli/         - CLI subcommand --help smoke tests
  config/      - uniform rules over roles/*/config/main.yml (non-empty,
                 CSP shape, universal-logout bool)
  lookups/     - custom lookup-plugin behavior (config-path validation,
                 runtime caching perf)
  vars/        - cross-role vars/defaults hygiene (uppercase uniqueness,
                 fact override prohibition)
  inventory/   - utils/manager/inventory integration
  spots/       - role-specific spot checks (dashboard OIDC, keycloak
                 realm import); home for future test_<role>_<aspect>.py
  playbooks/   - playbook-level wiring (invokable-paths filter ->
                 tasks/stages + tasks/groups/*-roles.yml)

Under tests/integration/roles/ add two sub-clusters:
  when/     - block-level when: hygiene (guards, duplication, block size)
  includes/ - include_tasks/import_tasks/include_role/import_role target
              existence (roles-scope and whole-repo-scope, kept separate
              for now)

Move 14 previously unclustered tests into these clusters, adjust path
depths accordingly (from +1 to +2 levels for most, walker-based tests
unchanged), strip stale file-path header comments, and extend
tests/integration/roles/README.md to document the new sub-clusters.
No behavior change; every new cluster passes locally.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-21 12:41:30 +02:00

66 lines
2.1 KiB
Python

import os
import sys
import subprocess
import unittest
class CLIHelpIntegrationTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.project_root = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..", "..")
)
cls.cli_dir = os.path.join(cls.project_root, "cli")
cls.main_py = os.path.join(cls.cli_dir, "__main__.py")
cls.python = sys.executable
def _discover_command_dirs(self):
"""
Discover commands as package directories under cli/ that contain __main__.py.
Rules:
- cli/<...>/__main__.py marks a command package
- cli/__main__.py is the dispatcher, not a command
- ignore __pycache__
Returns:
list[list[str]] command segments, e.g. ["deploy","container"]
"""
commands = []
for root, dirnames, filenames in os.walk(self.cli_dir):
# Prune __pycache__
dirnames[:] = [d for d in dirnames if d != "__pycache__"]
if "__main__.py" not in filenames:
continue
rel_dir = os.path.relpath(root, self.cli_dir)
if rel_dir == ".":
# cli/__main__.py is the dispatcher, not a command
continue
segments = rel_dir.split(os.sep)
commands.append(segments)
# stable order for test output
commands.sort(key=lambda s: "/".join(s))
return commands
def test_all_cli_commands_help(self):
for segments in self._discover_command_dirs():
with self.subTest(command=" ".join(segments)):
cmd = [self.python, self.main_py] + segments + ["--help"]
result = subprocess.run(cmd, capture_output=True, text=True)
self.assertEqual(
result.returncode,
0,
msg=(
f"Command `{' '.join(cmd)}` failed\n"
f"stdout:\n{result.stdout}\n"
f"stderr:\n{result.stderr}"
),
)
if __name__ == "__main__":
unittest.main()