summaryrefslogtreecommitdiff
path: root/tests/test_argparse.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-01-11 09:43:13 -0500
committerGitHub <noreply@github.com>2018-01-11 09:43:13 -0500
commit6895dea2e19210093e38fa411ef28dfb7f99c32c (patch)
tree23f40707099324197b47ba5a4f45dd558b6d5b82 /tests/test_argparse.py
parent0a03ab88f8bb70cc2f384c0b98a18bdead7bd417 (diff)
parent3607a39471eac8123e69b9416e6d77ce5d5b5ddf (diff)
downloadcmd2-git-6895dea2e19210093e38fa411ef28dfb7f99c32c.tar.gz
Merge pull request #248 from python-cmd2/argparse_bugfixes
Argparse bugfix
Diffstat (limited to 'tests/test_argparse.py')
-rw-r--r--tests/test_argparse.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py
index e9dbc1b3..52ce7de8 100644
--- a/tests/test_argparse.py
+++ b/tests/test_argparse.py
@@ -2,6 +2,7 @@
"""
Cmd2 testing for argument parsing
"""
+import re
import argparse
import pytest
@@ -43,6 +44,16 @@ class ArgparseApp(cmd2.Cmd):
self.stdout.write('<{0}>{1}</{0}>'.format(args.tag[0], ' '.join(args.content)))
self.stdout.write('\n')
+ argparser = argparse.ArgumentParser()
+ argparser.add_argument('args', nargs='*')
+ @cmd2.with_argument_parser(argparser)
+ def do_compare(self, cmdline, args=None):
+ cmdline_str = re.sub('\s+', ' ', cmdline)
+ args_str = re.sub('\s+', ' ', ' '.join(args.args))
+ if cmdline_str == args_str:
+ self.stdout.write('True')
+ else:
+ self.stdout.write('False')
@pytest.fixture
def argparse_app():
@@ -88,4 +99,9 @@ def test_argparse_prog(argparse_app):
out = run_cmd(argparse_app, 'help tag')
progname = out[0].split(' ')[1]
assert progname == 'tag'
+
+def test_argparse_cmdline(argparse_app):
+ out = run_cmd(argparse_app, 'compare this is a test')
+ assert out[0] == 'True'
+
\ No newline at end of file