diff options
author | kotfu <kotfu@kotfu.net> | 2018-01-07 14:12:57 -0700 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-01-07 14:12:57 -0700 |
commit | c25a2b7949c02449279f548db1c8de9d10214cdc (patch) | |
tree | a5ae8d39b04c50d37bc178308e2ccf2d56834f02 /tests | |
parent | 49bf448d2f5833a6a8710a92ed7a6cf6228f6c0e (diff) | |
download | cmd2-git-c25a2b7949c02449279f548db1c8de9d10214cdc.tar.gz |
Add tests for POSIX=true and arguments containing spaces
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_argparse.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py index dec54c5d..9b49267e 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -37,6 +37,18 @@ class ArgparseApp(cmd2.Cmd): self.stdout.write(' '.join(words)) self.stdout.write('\n') + argparser = argparse.ArgumentParser( + prog='tag', + description='create an html tag, the first argument is the tag, the rest is the contents' + ) + argparser.add_argument('tag', nargs=1, help='tag') + argparser.add_argument('content', nargs='+', help='content to surround with tag') + @cmd2.with_argument_parser(argparser) + def do_tag(self, cmdline, args=None): + self.stdout.write('<{0}>{1}</{0}>'.format(args.tag[0], ' '.join(args.content))) + self.stdout.write('\n') + + @pytest.fixture def argparse_app(): app = ArgparseApp() @@ -53,8 +65,18 @@ def test_argparse_quoted_arguments(argparse_app): out = run_cmd(argparse_app, 'say "hello there"') assert out == ['hello there'] -def test_pargparse_quoted_arguments_too_many(argparse_app): +def test_argparse_quoted_arguments_multiple(argparse_app): argparse_app.POSIX = False argparse_app.STRIP_QUOTES_FOR_NON_POSIX = True - out = run_cmd(argparse_app, 'say "hello there" morty') - assert out == ['hello there morty'] + out = run_cmd(argparse_app, 'say "hello there" "rick & morty"') + assert out == ['hello there rick & morty'] + +def test_argparse_quoted_arguments_posix(argparse_app): + argparse_app.POSIX = True + out = run_cmd(argparse_app, 'tag strong this should be loud') + assert out == ['<strong>this should be loud</strong>'] + +def test_argparse_quoted_arguments_posix_multiple(argparse_app): + argparse_app.POSIX = True + out = run_cmd(argparse_app, 'tag strong this "should be" loud') + assert out == ['<strong>this should be loud</strong>'] |