Skip to content

Commit 082fcc1

Browse files
committed
Added unit tests
1 parent b43e3d9 commit 082fcc1

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tests/test_pyscript.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import pytest
1010
from cmd2.cmd2 import Cmd, with_argparser
1111
from cmd2 import argparse_completer
12-
from .conftest import run_cmd
12+
from .conftest import run_cmd, normalize
1313
from cmd2.utils import namedtuple_with_defaults, StdSim
1414

1515

@@ -234,3 +234,20 @@ def test_pyscript_custom_name(ps_echo, request):
234234
out = run_cmd(ps_echo, 'pyscript {}'.format(python_script))
235235
assert out
236236
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

Comments
 (0)