diff options
author | Eric Lin <anselor@gmail.com> | 2020-08-20 15:47:22 -0400 |
---|---|---|
committer | Eric Lin <anselor@gmail.com> | 2020-08-20 18:08:45 -0400 |
commit | 27b10936b123053accc41f20246a0c027d0cbb66 (patch) | |
tree | 075c3bc028e1e9f711c9fa6f63301a418d7ee4c9 /tests_isolated/test_commandset | |
parent | dddf868439edf24a0f642ce1f39ba66ef82bead3 (diff) | |
download | cmd2-git-27b10936b123053accc41f20246a0c027d0cbb66.tar.gz |
Added tests for invalid subcommands
Diffstat (limited to 'tests_isolated/test_commandset')
-rw-r--r-- | tests_isolated/test_commandset/test_commandset.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests_isolated/test_commandset/test_commandset.py b/tests_isolated/test_commandset/test_commandset.py index ffeadf75..6856881a 100644 --- a/tests_isolated/test_commandset/test_commandset.py +++ b/tests_isolated/test_commandset/test_commandset.py @@ -844,3 +844,30 @@ def test_path_complete(command_sets_manual): first_match = complete_tester(text, line, begidx, endidx, command_sets_manual) assert first_match is not None + + +def test_bad_subcommand(): + class BadSubcommandApp(cmd2.Cmd): + """Class for testing usage of `as_subcommand_to` decorator directly in a Cmd2 subclass.""" + + def __init__(self, *args, **kwargs): + super(BadSubcommandApp, self).__init__(*args, **kwargs) + + cut_parser = cmd2.Cmd2ArgumentParser('cut') + cut_subparsers = cut_parser.add_subparsers(title='item', help='item to cut') + + @cmd2.with_argparser(cut_parser) + def do_cut(self, ns: argparse.Namespace): + """Cut something""" + pass + + banana_parser = cmd2.Cmd2ArgumentParser(add_help=False) + banana_parser.add_argument('direction', choices=['discs', 'lengthwise']) + + @cmd2.as_subcommand_to('cut', 'bad name', banana_parser, help='This should fail') + def cut_banana(self, ns: argparse.Namespace): + """Cut banana""" + self.poutput('cutting banana: ' + ns.direction) + + with pytest.raises(CommandSetRegistrationError): + app = BadSubcommandApp() |