diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-01-22 00:08:27 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-01-22 00:08:27 -0500 |
commit | f28c10a50535f753419bd2120ac6cb0bea9f56e2 (patch) | |
tree | 102b200c4a3dff1adad4bf326ea3f6de9cd56baf /tests/test_argparse.py | |
parent | c9f7c012bda012b4df7a8c5e853bd5d3e6d99b1b (diff) | |
download | cmd2-git-f28c10a50535f753419bd2120ac6cb0bea9f56e2.tar.gz |
help command temporarily redirects sys.stdout and sys.stderr to self.stdout for argparse commands
In order to make "help" behave more consistently for decorated and undecorated commands, argparse output is temporarily redirected to self.stdout. So doing "help history" is similar to "help load".
However, when using the "-h" with argparse commands without using the "help" command, the output from argparse isn't redirected to self.stdout. Fixing this would be rather difficult and would essentially involve creating a pyparsing rule to detect it at the parser level.
Diffstat (limited to 'tests/test_argparse.py')
-rw-r--r-- | tests/test_argparse.py | 40 |
1 files changed, 14 insertions, 26 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py index ecaa1049..d3646046 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -139,26 +139,20 @@ def test_argparse_quoted_arguments_posix_multiple(argparse_app): out = run_cmd(argparse_app, 'tag strong this "should be" loud') assert out == ['<strong>this should be loud</strong>'] -def test_argparse_help_docstring(argparse_app, capsys): - run_cmd(argparse_app, 'help say') - out, err = capsys.readouterr() - out = out.splitlines() +def test_argparse_help_docstring(argparse_app): + out = run_cmd(argparse_app, 'help say') assert out[0].startswith('usage: say') assert out[1] == '' assert out[2] == 'Repeat what you tell me to.' -def test_argparse_help_description(argparse_app, capsys): - run_cmd(argparse_app, 'help tag') - out, err = capsys.readouterr() - out = out.splitlines() +def test_argparse_help_description(argparse_app): + out = run_cmd(argparse_app, 'help tag') assert out[0].startswith('usage: tag') assert out[1] == '' assert out[2] == 'create a html tag' -def test_argparse_prog(argparse_app, capsys): - run_cmd(argparse_app, 'help tag') - out, err = capsys.readouterr() - out = out.splitlines() +def test_argparse_prog(argparse_app): + out = run_cmd(argparse_app, 'help tag') progname = out[0].split(' ')[1] assert progname == 'tag' @@ -237,26 +231,20 @@ def test_subcommand_invalid(subcommand_app, capsys): assert err[0].startswith('usage: base') assert err[1].startswith("base: error: invalid choice: 'baz'") -def test_subcommand_base_help(subcommand_app, capsys): - run_cmd(subcommand_app, 'help base') - out, err = capsys.readouterr() - out = out.splitlines() +def test_subcommand_base_help(subcommand_app): + out = run_cmd(subcommand_app, 'help base') assert out[0].startswith('usage: base') assert out[1] == '' assert out[2] == 'Base command help' -def test_subcommand_help(subcommand_app, capsys): - run_cmd(subcommand_app, 'help base foo') - out, err = capsys.readouterr() - out = out.splitlines() +def test_subcommand_help(subcommand_app): + out = run_cmd(subcommand_app, 'help base foo') assert out[0].startswith('usage: base foo') assert out[1] == '' assert out[2] == 'positional arguments:' -def test_subcommand_invalid_help(subcommand_app, capsys): - run_cmd(subcommand_app, 'help base baz') - out, err = capsys.readouterr() - err = err.splitlines() - assert err[0].startswith('usage: base') - assert err[1].startswith("base: error: invalid choice: 'baz'") +def test_subcommand_invalid_help(subcommand_app): + out = run_cmd(subcommand_app, 'help base baz') + assert out[0].startswith('usage: base') + assert out[1].startswith("base: error: invalid choice: 'baz'") |