diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-14 23:08:28 -0400 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-14 23:08:28 -0400 |
commit | 37c67e598095382469dd0b3982a667bc9401a038 (patch) | |
tree | b4f6bd25881f92f47f835ee9c31b087eabcd6108 /tests | |
parent | 2311acf725e46257808a653319ccac73003d4a49 (diff) | |
parent | 57ac00c5001dd39dff0fb7800bb8d530c320d7be (diff) | |
download | cmd2-git-37c67e598095382469dd0b3982a667bc9401a038.tar.gz |
Merge branch 'master' into deprecate_34
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_cmd2.py | 14 | ||||
-rw-r--r-- | tests/test_history.py | 43 | ||||
-rw-r--r-- | tests/test_parsing.py | 12 |
3 files changed, 69 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 0dc8c7c2..72643308 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1317,6 +1317,20 @@ def test_multiline_complete_statement_with_unclosed_quotes(multiline_app): assert statement.multiline_command == 'orate' assert statement.terminator == ';' +def test_multiline_input_line_to_statement(multiline_app): + # Verify _input_line_to_statement saves the fully entered input line for multiline commands + + # Mock out the input call so we don't actually wait for a user's response + # on stdin when it looks for more input + m = mock.MagicMock(name='input', side_effect=['person', '\n']) + builtins.input = m + + line = 'orate hi' + statement = multiline_app._input_line_to_statement(line) + assert statement.raw == 'orate hi\nperson\n' + assert statement == 'hi person' + assert statement.command == 'orate' + assert statement.multiline_command == 'orate' def test_clipboard_failure(base_app, capsys): # Force cmd2 clipboard to be disabled diff --git a/tests/test_history.py b/tests/test_history.py index 5e01688c..a06bce87 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -10,6 +10,8 @@ import pytest # Python 3.5 had some regressions in the unitest.mock module, so use # 3rd party mock if available +from cmd2.parsing import StatementParser + try: import mock except ImportError: @@ -262,6 +264,47 @@ def histitem(): histitem = HistoryItem(statement, 1) return histitem +@pytest.fixture +def parser(): + from cmd2.parsing import StatementParser + parser = StatementParser( + allow_redirection=True, + terminators=[';', '&'], + multiline_commands=['multiline'], + aliases={'helpalias': 'help', + '42': 'theanswer', + 'l': '!ls -al', + 'anothermultiline': 'multiline', + 'fake': 'pyscript'}, + shortcuts=[('?', 'help'), ('!', 'shell')] + ) + return parser + +def test_multiline_histitem(parser): + from cmd2.history import History + line = 'multiline foo\nbar\n\n' + statement = parser.parse(line) + history = History() + history.append(statement) + assert len(history) == 1 + hist_item = history[0] + assert hist_item.raw == line + pr_lines = hist_item.pr().splitlines() + assert pr_lines[0].endswith('multiline foo bar') + +def test_multiline_histitem_verbose(parser): + from cmd2.history import History + line = 'multiline foo\nbar\n\n' + statement = parser.parse(line) + history = History() + history.append(statement) + assert len(history) == 1 + hist_item = history[0] + assert hist_item.raw == line + pr_lines = hist_item.pr(verbose=True).splitlines() + assert pr_lines[0].endswith('multiline foo') + assert pr_lines[1] == 'bar' + def test_history_item_instantiate(): from cmd2.parsing import Statement from cmd2.history import HistoryItem diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 5ba02a95..3bd635a1 100644 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -486,6 +486,18 @@ def test_parse_unfinished_multiliine_command(parser): assert statement.arg_list == statement.argv[1:] assert statement.terminator == '' +def test_parse_basic_multiline_command(parser): + line = 'multiline foo\nbar\n\n' + statement = parser.parse(line) + assert statement.multiline_command == 'multiline' + assert statement.command == 'multiline' + assert statement == 'foo bar' + assert statement.args == statement + assert statement.argv == ['multiline', 'foo', 'bar'] + assert statement.arg_list == ['foo', 'bar'] + assert statement.raw == line + assert statement.terminator == '\n' + @pytest.mark.parametrize('line,terminator',[ ('multiline has > inside;', ';'), ('multiline has > inside;;;', ';'), |