Test detaching a subcommand using one of its alias names.
()
| 411 | |
| 412 | |
| 413 | def 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 | |
| 448 | def test_subcommand_attachment_errors() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…