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

Function test_subcommand_attachment_errors

tests/test_cmd2.py:4570–4602  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4568
4569
4570def test_subcommand_attachment_errors() -> None:
4571 class SubcmdErrorApp(cmd2.Cmd):
4572 def __init__(self) -> None:
4573 super().__init__()
4574
4575 test_parser = cmd2.Cmd2ArgumentParser()
4576 test_parser.add_subparsers(required=True)
4577
4578 @cmd2.with_argparser(test_parser)
4579 def do_test(self, _statement: cmd2.Statement) -> None:
4580 pass
4581
4582 def do_no_argparse(self, _statement: cmd2.Statement) -> None:
4583 pass
4584
4585 app = SubcmdErrorApp()
4586
4587 # Test empty command
4588 with pytest.raises(ValueError, match="Command path cannot be empty"):
4589 app.attach_subcommand("", "sub", cmd2.Cmd2ArgumentParser())
4590
4591 # Test non-existent command
4592 with pytest.raises(ValueError, match="Root command 'fake' does not exist"):
4593 app.attach_subcommand("fake", "sub", cmd2.Cmd2ArgumentParser())
4594
4595 # Test command that doesn't use argparse
4596 with pytest.raises(ValueError, match="Command 'no_argparse' does not use argparse"):
4597 app.attach_subcommand("no_argparse", "sub", cmd2.Cmd2ArgumentParser())
4598
4599 # Test duplicate subcommand
4600 app.attach_subcommand("test", "sub", cmd2.Cmd2ArgumentParser())
4601 with pytest.raises(ValueError, match="Subcommand 'sub' already exists for 'test'"):
4602 app.attach_subcommand("test", "sub", cmd2.Cmd2ArgumentParser())

Callers

nothing calls this directly

Calls 2

SubcmdErrorAppClass · 0.85
attach_subcommandMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…