summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd2/parsing.py5
-rwxr-xr-xexamples/arg_print.py2
-rw-r--r--tests/conftest.py5
-rw-r--r--tests/test_completion.py8
4 files changed, 10 insertions, 10 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index 27d17d21..6c687439 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -315,10 +315,11 @@ class StatementParser:
if not word:
return False, 'cannot be an empty string'
- for (shortcut, expansion) in self.shortcuts:
+ for (shortcut, _) in self.shortcuts:
if word.startswith(shortcut):
+ # Build an error string with all shortcuts listed
errmsg = 'cannot start with a shortcut: '
- errmsg += ', '.join(shortcut for (shortcut, expansion) in self.shortcuts)
+ errmsg += ', '.join(shortcut for (shortcut, _) in self.shortcuts)
return False, errmsg
errmsg = 'cannot contain: whitespace, quotes, '
diff --git a/examples/arg_print.py b/examples/arg_print.py
index 6b7d030e..f2168126 100755
--- a/examples/arg_print.py
+++ b/examples/arg_print.py
@@ -2,7 +2,7 @@
# coding=utf-8
"""A simple example demonstrating the following:
1) How arguments and options get parsed and passed to commands
- 2) How to change what syntax get parsed as a comment and stripped from the arguments
+ 2) How to change what syntax gets parsed as a comment and stripped from the arguments
This is intended to serve as a live demonstration so that developers can
experiment with and understand how command and argument parsing work.
diff --git a/tests/conftest.py b/tests/conftest.py
index 949d5419..2c7a2600 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -160,9 +160,8 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti
def get_endidx():
return endidx
+ # Run the readline tab-completion function with readline mocks in place
with mock.patch.object(readline, 'get_line_buffer', get_line):
with mock.patch.object(readline, 'get_begidx', get_begidx):
with mock.patch.object(readline, 'get_endidx', get_endidx):
- # Run the readline tab-completion function with readline mocks in place
- first_match = app.complete(text, 0)
- return first_match
+ return app.complete(text, 0)
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 8741fbd5..f02989bf 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -101,8 +101,7 @@ def test_complete_empty_arg(cmd2_app):
expected = sorted(cmd2_app.complete_help(text, line, begidx, endidx))
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and \
- cmd2_app.completion_matches == expected
+ assert first_match is not None and cmd2_app.completion_matches == expected
def test_complete_bogus_command(cmd2_app):
text = ''
@@ -121,14 +120,15 @@ def test_complete_macro(base_app, request):
# Macros do path completion
test_dir = os.path.dirname(request.module.__file__)
- text = os.path.join(test_dir, 'script.py')
+ text = os.path.join(test_dir, 's')
line = 'fake {}'.format(text)
endidx = len(line)
begidx = endidx - len(text)
+ expected = [text + 'cript.py', text + 'cript.txt', text + 'cripts' + os.path.sep]
first_match = complete_tester(text, line, begidx, endidx, base_app)
- assert first_match == text + ' '
+ assert first_match is not None and base_app.completion_matches
def test_cmd2_command_completion_multiple(cmd2_app):