summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-09 03:06:21 -0400
committerGitHub <noreply@github.com>2020-09-09 03:06:21 -0400
commitc50def1eff00f7f44adcb911d215ace65d16aa8a (patch)
tree62575c664a651027cea415cea574454d1e4637ca /tests
parenta975432ea87b8bde7d879f6e0974dcaffedc5f78 (diff)
parent1a2095e5c373430e5aa4bda2ee24f65f4527a002 (diff)
downloadcmd2-git-c50def1eff00f7f44adcb911d215ace65d16aa8a.tar.gz
Merge pull request #991 from python-cmd2/read_input
Read input enhancements
Diffstat (limited to 'tests')
-rw-r--r--tests/test_argparse_completer.py12
-rwxr-xr-xtests/test_cmd2.py36
-rwxr-xr-xtests/test_completion.py5
-rwxr-xr-xtests/test_history.py1
4 files changed, 45 insertions, 9 deletions
diff --git a/tests/test_argparse_completer.py b/tests/test_argparse_completer.py
index 4ae3e339..5c579b5c 100644
--- a/tests/test_argparse_completer.py
+++ b/tests/test_argparse_completer.py
@@ -576,8 +576,8 @@ def test_autocomp_blank_token(ac_app):
begidx = endidx - len(text)
completer = ArgparseCompleter(ac_app.completer_parser, ac_app)
- tokens = ['completer', '-c', blank, text]
- completions = completer.complete_command(tokens, text, line, begidx, endidx)
+ tokens = ['-c', blank, text]
+ completions = completer.complete(text, line, begidx, endidx, tokens)
assert sorted(completions) == sorted(ArgparseCompleterTester.completions_for_pos_1)
# Blank arg for first positional will be consumed. Therefore we expect to be completing the second positional.
@@ -587,8 +587,8 @@ def test_autocomp_blank_token(ac_app):
begidx = endidx - len(text)
completer = ArgparseCompleter(ac_app.completer_parser, ac_app)
- tokens = ['completer', blank, text]
- completions = completer.complete_command(tokens, text, line, begidx, endidx)
+ tokens = [blank, text]
+ completions = completer.complete(text, line, begidx, endidx, tokens)
assert sorted(completions) == sorted(ArgparseCompleterTester.completions_for_pos_2)
@@ -1001,7 +1001,7 @@ def test_complete_command_no_tokens(ac_app):
parser = Cmd2ArgumentParser()
ac = ArgparseCompleter(parser, ac_app)
- completions = ac.complete_command(tokens=[], text='', line='', begidx=0, endidx=0)
+ completions = ac.complete(text='', line='', begidx=0, endidx=0, tokens=[])
assert not completions
@@ -1011,7 +1011,7 @@ def test_complete_command_help_no_tokens(ac_app):
parser = Cmd2ArgumentParser()
ac = ArgparseCompleter(parser, ac_app)
- completions = ac.complete_subcommand_help(tokens=[], text='', line='', begidx=0, endidx=0)
+ completions = ac.complete_subcommand_help(text='', line='', begidx=0, endidx=0, tokens=[])
assert not completions
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_completion.py b/tests/test_completion.py
index ac4216bb..48f93a5a 100755
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -22,7 +22,6 @@ import pytest
import cmd2
from cmd2 import utils
from examples.subcommands import SubcommandsExample
-
from .conftest import complete_tester, normalize, run_cmd
# List of strings used with completion functions
@@ -858,9 +857,9 @@ def test_no_completer(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and cmd2_app.completion_matches == expected
-def test_quote_as_command(cmd2_app):
+def test_wordbreak_in_command(cmd2_app):
text = ''
- line = '" {}'.format(text)
+ line = '"{}'.format(text)
endidx = len(line)
begidx = endidx - len(text)
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