MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_detach_subcommand_by_alias

Function test_detach_subcommand_by_alias

tests/test_argparse_utils.py:413–445  ·  view source on GitHub ↗

Test detaching a subcommand using one of its alias names.

()

Source from the content-addressed store, hash-verified

411
412
413def test_detach_subcommand_by_alias() -> None:
414 """Test detaching a subcommand using one of its alias names."""
415 root_parser = Cmd2ArgumentParser(prog="root")
416 root_subparsers = root_parser.add_subparsers()
417
418 child_parser = Cmd2ArgumentParser(prog="child")
419 root_parser.attach_subcommand(
420 [],
421 "child",
422 child_parser,
423 help="a child command",
424 aliases=["alias1", "alias2"],
425 )
426
427 # Verify all names map to the parser
428 assert root_subparsers._name_parser_map["child"] is child_parser
429 assert root_subparsers._name_parser_map["alias1"] is child_parser
430 assert root_subparsers._name_parser_map["alias2"] is child_parser
431
432 # Verify help entry is present
433 assert any(action.dest == "child" for action in root_subparsers._choices_actions)
434
435 # Detach using an alias
436 detached = root_parser.detach_subcommand([], "alias1")
437 assert detached is child_parser
438
439 # Verify all names are gone
440 assert "child" not in root_subparsers._name_parser_map
441 assert "alias1" not in root_subparsers._name_parser_map
442 assert "alias2" not in root_subparsers._name_parser_map
443
444 # Verify help entry is gone
445 assert not any(action.dest == "child" for action in root_subparsers._choices_actions)
446
447
448def test_subcommand_attachment_errors() -> None:

Callers

nothing calls this directly

Calls 3

attach_subcommandMethod · 0.95
detach_subcommandMethod · 0.95
Cmd2ArgumentParserClass · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…