|
9 | 9 | import pytest
|
10 | 10 | from cmd2.cmd2 import Cmd, with_argparser
|
11 | 11 | from cmd2 import argparse_completer
|
12 |
| -from .conftest import run_cmd |
| 12 | +from .conftest import run_cmd, normalize |
13 | 13 | from cmd2.utils import namedtuple_with_defaults, StdSim
|
14 | 14 |
|
15 | 15 |
|
@@ -234,3 +234,20 @@ def test_pyscript_custom_name(ps_echo, request):
|
234 | 234 | out = run_cmd(ps_echo, 'pyscript {}'.format(python_script))
|
235 | 235 | assert out
|
236 | 236 | assert message == out[0]
|
| 237 | + |
| 238 | + |
| 239 | +def test_pyscript_argparse_checks(ps_app, capsys): |
| 240 | + # Test command that has nargs.REMAINDER and make sure all tokens are accepted |
| 241 | + run_cmd(ps_app, 'py app.alias.create("my_alias", "alias_command", "command_arg1", "command_arg2")') |
| 242 | + out = run_cmd(ps_app, 'alias list my_alias') |
| 243 | + assert out == normalize('alias create my_alias alias_command command_arg1 command_arg2') |
| 244 | + |
| 245 | + # Specify flag outside of keyword argument |
| 246 | + run_cmd(ps_app, 'py app.help("-h")') |
| 247 | + _, err = capsys.readouterr() |
| 248 | + assert '-h appears to be a flag' in err |
| 249 | + |
| 250 | + # Specify list with flag outside of keyword argument |
| 251 | + run_cmd(ps_app, 'py app.help(["--help"])') |
| 252 | + _, err = capsys.readouterr() |
| 253 | + assert '--help appears to be a flag' in err |
0 commit comments