From 65454291845ee0496d747f7d8892df5f16db3921 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Thu, 23 Apr 2020 15:21:58 -0400 Subject: Updated _set_parser_prog() so future calls to add_parser() will set the correct prog value This makes dynamically adding subcommands after the CLI starts easier. --- tests/test_argparse.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_argparse.py b/tests/test_argparse.py index f9ee0d07..db6dea21 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -333,7 +333,14 @@ def test_subcommand_help(subcommand_app): assert out[1] == '' assert out[2] == 'positional arguments:' - def test_subcommand_invalid_help(subcommand_app): out, err = run_cmd(subcommand_app, 'help base baz') assert out[0].startswith('usage: base') + +def test_add_another_subcommand(subcommand_app): + """ + This tests makes sure _set_parser_prog() sets _prog_prefix on every _SubParsersAction so that all future calls + to add_parser() write the correct prog value to the parser being added. + """ + new_parser = subcommand_app.base_subparsers.add_parser('new_sub', help="stuff") + assert new_parser.prog == "base new_sub" -- cgit v1.2.1