diff options
| author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-25 13:46:08 -0400 |
|---|---|---|
| committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-06-25 13:46:08 -0400 |
| commit | 972b4f4a3bc2fea3ad318a72e4e6f7d2c0d3a0b9 (patch) | |
| tree | 8f2de2d22f6074a83889679b46f5e0ecd5bba84b /tests | |
| parent | b73117be943403cb000efd9f97bc72586261630d (diff) | |
| download | cmd2-git-972b4f4a3bc2fea3ad318a72e4e6f7d2c0d3a0b9.tar.gz | |
Various fixes and improvements
- Removed some dead code in cmd2.py which was never used
- Added a number of unit tests
- Fixed how get_paste_buffer() and write_paste_buffer() work on macOS so that they work correctly on both Python 2.7 and Python 3.3+
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_cmd2.py | 21 | ||||
| -rw-r--r-- | tests/test_transcript.py | 9 |
2 files changed, 26 insertions, 4 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index c1d406f4..02157316 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -36,6 +36,21 @@ def test_base_help_history(base_app): expected = normalize(HELP_HISTORY) assert out == expected +def test_base_options_help(base_app, capsys): + run_cmd(base_app, 'show -h') + out, err = capsys.readouterr() + expected = run_cmd(base_app, 'help show') + # 'show -h' is the same as 'help show', other than whitespace differences of an extra newline present in 'help show' + assert normalize(str(out)) == expected + +def test_base_invalid_option(base_app, capsys): + run_cmd(base_app, 'show -z') + out, err = capsys.readouterr() + show_help = run_cmd(base_app, 'help show') + expected = ['no such option: -z'] + expected.extend(show_help) + # 'show -h' is the same as 'help show', other than whitespace differences of an extra newline present in 'help show' + assert normalize(str(out)) == expected def test_base_shortcuts(base_app): out = run_cmd(base_app, 'shortcuts') @@ -632,4 +647,8 @@ def test_cmdloop_without_rawinput(): assert out == expected - +def test_pastebuffer_read_and_write(): + text_to_pb = 'This is a test ...' + cmd2.write_to_paste_buffer(text_to_pb) + text_from_pb = cmd2.get_paste_buffer() + assert text_from_pb == text_to_pb diff --git a/tests/test_transcript.py b/tests/test_transcript.py index 4a7d57a6..4b6f4c99 100644 --- a/tests/test_transcript.py +++ b/tests/test_transcript.py @@ -15,7 +15,7 @@ import six # Used for sm.input: raw_input() for Python 2 or input() for Python 3 import six.moves as sm -from cmd2 import Cmd, make_option, options, Cmd2TestCase, set_use_arg_list +from cmd2 import Cmd, make_option, options, Cmd2TestCase, set_use_arg_list, set_posix_shlex, set_strip_quotes from conftest import run_cmd, StdOut, normalize @@ -28,6 +28,10 @@ class CmdLineApp(Cmd): # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x Cmd.__init__(self, *args, **kwargs) self.settable.append('maxrepeats Max number of `--repeat`s allowed') + + # Configure how arguments are parsed for @options commands + set_posix_shlex(False) + set_strip_quotes(True) set_use_arg_list(False) opts = [make_option('-p', '--piglatin', action="store_true", help="atinLay"), @@ -54,8 +58,7 @@ class CmdLineApp(Cmd): class DemoApp(Cmd): - @options([make_option('-n', '--name', action="store", help="your name"), - ]) + @options(make_option('-n', '--name', action="store", help="your name")) def do_hello(self, arg, opts): """Says hello.""" if opts.name: |
