Skip to content

Commit dd5e685

Browse files
mo-kiJenkins
authored andcommitted
Add CLI subcommand tests driving main()
cli.py is the largest module in the package (881 lines) and had a single test. Drive main() per subcommand via sys.argv, which also covers the table and manifest rendering helpers through their output: - argument parsing: no arguments shows the help, an unknown command exits, and site-only commands are absent without a site context - read-only commands: path-config-template, template, find (table and json), inspect (table and json), list, show-all - the add -> enable -> disable -> release/remove lifecycle against a real store on tmp_path, asserting the state shown by list - the error surface: unknown packages return 1 and report to stderr, and --debug re-raises instead Change-Id: I15091ec6ec964ecd4f989c759b6546f3720b3e20
1 parent f3314d2 commit dd5e685

2 files changed

Lines changed: 351 additions & 7 deletions

File tree

packages/cmk-mkp-tool/cmk/mkp_tool/cli.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ def _get_package_id(
783783
)
784784

785785

786-
def _parse_arguments(argv: list[str], site_context: SiteContext | None) -> argparse.Namespace:
786+
def _parse_arguments(argv: Sequence[str], site_context: SiteContext | None) -> argparse.Namespace:
787787
parser = argparse.ArgumentParser(
788788
prog="mkp",
789789
description=__doc__,
@@ -862,8 +862,9 @@ def main(
862862
path_config: PathConfig | None = None,
863863
site_context: SiteContext | None = None,
864864
persisting_function: Callable[[Path, bytes], None] = simple_file_write,
865+
argv: Sequence[str] = sys.argv[1:] or ["--help"],
865866
) -> int:
866-
args = _parse_arguments(sys.argv[1:] or ["--help"], site_context)
867+
args = _parse_arguments(argv, site_context)
867868
set_up_logging(args.verbose)
868869

869870
try:

0 commit comments

Comments
 (0)