summaryrefslogtreecommitdiff
path: root/tests/test_argparse.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-01-07 13:51:53 -0700
committerkotfu <kotfu@kotfu.net>2018-01-07 13:51:53 -0700
commitcc32105daa5c096a5c7fcd2b47729eebc871ebef (patch)
tree5a8ffda0edf7338a6b5f85e7ecf9ec75c3aa24cf /tests/test_argparse.py
parent4f54d10f4c8d5b5c03626a88f8198318a8080fc6 (diff)
downloadcmd2-git-cc32105daa5c096a5c7fcd2b47729eebc871ebef.tar.gz
Default posix and quote removal working.
Diffstat (limited to 'tests/test_argparse.py')
-rw-r--r--tests/test_argparse.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/tests/test_argparse.py b/tests/test_argparse.py
index 82932e6d..dec54c5d 100644
--- a/tests/test_argparse.py
+++ b/tests/test_argparse.py
@@ -20,19 +20,21 @@ class ArgparseApp(cmd2.Cmd):
argparser.add_argument('-p', '--piglatin', action='store_true', help='atinLay')
argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
argparser.add_argument('-r', '--repeat', type=int, help='output [n] times')
- argparser.add_argument('word', nargs='?', help='word to say')
+ argparser.add_argument('words', nargs='+', help='words to say')
@cmd2.with_argument_parser(argparser)
def do_say(self, cmdline, args=None):
- word = args.word
- if word is None:
- word = ''
- if args.piglatin:
- word = '%s%say' % (word[1:], word[0])
- if args.shout:
- word = word.upper()
+ words = []
+ for word in args.words:
+ if word is None:
+ word = ''
+ if args.piglatin:
+ word = '%s%say' % (word[1:], word[0])
+ if args.shout:
+ word = word.upper()
+ words.append(word)
repetitions = args.repeat or 1
for i in range(min(repetitions, self.maxrepeats)):
- self.stdout.write(word)
+ self.stdout.write(' '.join(words))
self.stdout.write('\n')
@pytest.fixture
@@ -45,10 +47,14 @@ def test_argparse_basic_command(argparse_app):
out = run_cmd(argparse_app, 'say hello')
assert out == ['hello']
-#def test_argparse_quoted_arguments(argparse_app):
-# out = run_cmd(argparse_app, 'say "hello there"')
-# assert out == ['hello there']
+def test_argparse_quoted_arguments(argparse_app):
+ argparse_app.POSIX = False
+ argparse_app.STRIP_QUOTES_FOR_NON_POSIX = True
+ out = run_cmd(argparse_app, 'say "hello there"')
+ assert out == ['hello there']
-#def test_pargparse_quoted_arguments_too_many(argparse_app):
-# out = run_cmd(argparse_app, 'say "hello there" morty')
-# assert out == ['hello there morty']
+def test_pargparse_quoted_arguments_too_many(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']