diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-25 12:03:49 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-08-25 12:03:49 -0400 |
| commit | 5942f2105eb83140a8ab37e655e2561c4d17d3a2 (patch) | |
| tree | 09f6a2a6da8a0da4c8150b84988f41ad571312f6 /tests | |
| parent | a394ed3b83be17986e168b8d0817892cbabd088f (diff) | |
| parent | 97c348c599d8fa963553593e5c19fb100b85e313 (diff) | |
| download | cmd2-git-5942f2105eb83140a8ab37e655e2561c4d17d3a2.tar.gz | |
Merge branch 'master' into 2.0
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_argparse.py | 23 | ||||
| -rw-r--r-- | tests/test_plugin.py | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py index 0d46b15a..9806c9b5 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -290,6 +290,24 @@ class SubcommandApp(cmd2.Cmd): func(self, args) + # Add a subcommand using as_subcommand_to decorator + has_subcmd_parser = cmd2.Cmd2ArgumentParser(description="Tests as_subcmd_to decorator") + has_subcmd_subparsers = has_subcmd_parser.add_subparsers(dest='subcommand', metavar='SUBCOMMAND') + has_subcmd_subparsers.required = True + + @cmd2.with_argparser(has_subcmd_parser) + def do_test_subcmd_decorator(self, args: argparse.Namespace): + handler = args.get_handler() + handler(args) + + subcmd_parser = cmd2.Cmd2ArgumentParser(add_help=False, description="The subcommand") + + @cmd2.as_subcommand_to('test_subcmd_decorator', 'subcmd', subcmd_parser, help='the subcommand') + def subcmd_func(self, args: argparse.Namespace): + # Make sure printing the Namespace works. The way we originally added get_hander() + # to it resulted in a RecursionError when printing. + print(args) + @pytest.fixture def subcommand_app(): app = SubcommandApp() @@ -373,6 +391,11 @@ def test_add_another_subcommand(subcommand_app): assert new_parser.prog == "base new_sub" +def test_subcmd_decorator(subcommand_app): + out, err = run_cmd(subcommand_app, 'test_subcmd_decorator subcmd') + assert out[0].startswith('Namespace(') + + def test_unittest_mock(): from unittest import mock from cmd2 import CommandSetRegistrationError diff --git a/tests/test_plugin.py b/tests/test_plugin.py index e49cbbfc..d40a9b61 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -279,7 +279,7 @@ class PluggedApp(Plugin, cmd2.Cmd): @with_argparser(parser) def do_argparse_cmd(self, namespace: argparse.Namespace): """Repeat back the arguments""" - self.poutput(namespace.__statement__) + self.poutput(namespace.get_statement()) ### # |
