From 405f4e4e951e0af46c7c5d746459f24e5c316eab Mon Sep 17 00:00:00 2001 From: kotfu Date: Fri, 12 Jan 2018 23:11:53 -0700 Subject: add use_argument_list setting new attribute on Cmd2.cmd which defaults to false, but if set true, causes all do_* commands to receive a list of arguments, instead of a string of what the user typed. --- tests/test_argparse.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests/test_argparse.py') diff --git a/tests/test_argparse.py b/tests/test_argparse.py index 308824cf..7d6d99de 100644 --- a/tests/test_argparse.py +++ b/tests/test_argparse.py @@ -71,12 +71,29 @@ class ArgparseApp(cmd2.Cmd): else: self.stdout.write('False') +class ArglistApp(cmd2.Cmd): + def __init__(self): + self.use_argument_list = True + cmd2.Cmd.__init__(self) + + def do_arglist(self, arglist): + if isinstance(arglist, list): + self.stdout.write('True') + else: + self.stdout.write('False') + @pytest.fixture def argparse_app(): app = ArgparseApp() app.stdout = StdOut() return app +@pytest.fixture +def arglist_app(): + app = ArglistApp() + app.stdout = StdOut() + return app + def test_argparse_basic_command(argparse_app): out = run_cmd(argparse_app, 'say hello') assert out == ['hello'] @@ -127,3 +144,7 @@ def test_argparse_arglist(argparse_app): def test_arglist(argparse_app): out = run_cmd(argparse_app, 'arglist "we should" get these in a list, not a string') assert out[0] == 'True' + +def test_use_argument_list(arglist_app): + out = run_cmd(arglist_app, 'arglist "we should" get these in a list, not a string') + assert out[0] == 'True' -- cgit v1.2.1