diff options
| author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-09-05 11:26:07 -0400 |
|---|---|---|
| committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-09-05 11:26:07 -0400 |
| commit | f1e4fc3a90bad1c0d245af4c30fe4ec41a474ec9 (patch) | |
| tree | 8b6c25a8ab4418fa526b4b1ca69e8ea42ccf226f /tests | |
| parent | 3e0c9ba1ad4a415e0aba81daf2e7f9f57281b1bc (diff) | |
| download | cmd2-git-f1e4fc3a90bad1c0d245af4c30fe4ec41a474ec9.tar.gz | |
Updated unit tests for read_input()
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/test_cmd2.py | 36 | ||||
| -rwxr-xr-x | tests/test_history.py | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index be6f52d1..f5c8dbc6 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -1437,6 +1437,42 @@ def test_read_input_rawinput_true(capsys, monkeypatch): line = app.read_input(prompt_str) assert line == input_str + # Run custom history code + import readline + readline.add_history('old_history') + custom_history = ['cmd1', 'cmd2'] + line = app.read_input(prompt_str, history=custom_history, completion_mode=cmd2.CompletionMode.NONE) + assert line == input_str + readline.clear_history() + + # Run all completion modes + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.NONE) + assert line == input_str + + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.COMMANDS) + assert line == input_str + + # custom choices + custom_choices = ['choice1', 'choice2'] + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.CUSTOM, + choices=custom_choices) + assert line == input_str + + # custom choices_provider + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.CUSTOM, + choices_provider=cmd2.Cmd.get_all_commands) + assert line == input_str + + # custom completer + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.CUSTOM, + completer=cmd2.Cmd.path_complete) + assert line == input_str + + # custom parser + line = app.read_input(prompt_str, completion_mode=cmd2.CompletionMode.CUSTOM, + parser=cmd2.Cmd2ArgumentParser()) + assert line == input_str + # isatty is False with mock.patch('sys.stdin.isatty', mock.MagicMock(name='isatty', return_value=False)): # echo True diff --git a/tests/test_history.py b/tests/test_history.py index 6fa16ad8..86c52592 100755 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -27,6 +27,7 @@ except ImportError: # def test_readline_remove_history_item(base_app): from cmd2.rl_utils import readline + readline.clear_history() assert readline.get_current_history_length() == 0 readline.add_history('this is a test') assert readline.get_current_history_length() == 1 |
