diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-03 00:30:44 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-02-03 00:30:44 -0500 |
commit | 4ffaf5397eeeb622c7a0dfaa3527a51c34f26618 (patch) | |
tree | 1d01a81bbbc0cfb6f0dc6f0ac9a4e97751058ee9 /tests/test_transcript.py | |
parent | a9b9cce70bd9aea81141c7e02d4be953cafe5ec2 (diff) | |
download | cmd2-git-4ffaf5397eeeb622c7a0dfaa3527a51c34f26618.tar.gz |
Added another unit test and a test fixture associated with it.
This was specifically for testing parsing of options with quotes provided to support embedded spaces
Diffstat (limited to 'tests/test_transcript.py')
-rw-r--r-- | tests/test_transcript.py | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/test_transcript.py b/tests/test_transcript.py index aefd0068..2c717f58 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -43,6 +43,17 @@ class CmdLineApp(Cmd): do_orate = do_speak # another synonym, but this one takes multi-line input +class DemoApp(Cmd): + @options([make_option('-n', '--name', action="store", help="your name"), + ]) + def do_hello(self, arg, opts): + """Says hello.""" + if opts.name: + self.stdout.write('Hello {}\n'.format(opts.name)) + else: + self.stdout.write('Hello Nobody\n') + + @pytest.fixture def _cmdline_app(): c = CmdLineApp() @@ -52,6 +63,13 @@ def _cmdline_app(): return c +@pytest.fixture +def _demo_app(): + c = DemoApp() + c.stdout = StdOut() + return c + + def _get_transcript_blocks(transcript): cmd = None expected = '' @@ -176,16 +194,21 @@ Options: assert _normalize(str(out)) == expected -def test_comment_stripping(_cmdline_app, capsys): +def test_comment_stripping(_cmdline_app): out = run_cmd(_cmdline_app, 'speak it was /* not */ delicious! # Yuck!') expected = _normalize("""it was delicious!""") assert out == expected -def test_optarser_correct_args_with_quotes_and_midline_options(_cmdline_app, capsys): +def test_optarser_correct_args_with_quotes_and_midline_options(_cmdline_app): out = run_cmd(_cmdline_app, "speak 'This is a' -s test of the emergency broadcast system!") expected = _normalize("""THIS IS A TEST OF THE EMERGENCY BROADCAST SYSTEM!""") assert out == expected +def test_optarser_options_with_spaces_in_quotes(_demo_app): + out = run_cmd(_demo_app, "hello foo -n 'Bugs Bunny' bar baz") + expected = _normalize("""Hello Bugs Bunny""") + assert out == expected + |