summaryrefslogtreecommitdiff
path: root/tests/test_completion.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_completion.py')
-rw-r--r--tests/test_completion.py44
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 0df06423..dffb03ec 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -257,6 +257,21 @@ def test_shell_command_completion_does_path_completion_when_after_command(cmd2_a
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and cmd2_app.completion_matches == [text + '.py ']
+def test_shell_commmand_complete_in_path(cmd2_app, request):
+ test_dir = os.path.dirname(request.module.__file__)
+
+ text = os.path.join(test_dir, 's')
+ line = 'shell {}'.format(text)
+
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ # Since this will look for directories and executables in the given path,
+ # we expect to see the scripts dir among the results
+ expected = os.path.join(test_dir, 'scripts' + os.path.sep)
+ first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
+ assert first_match is not None and expected in cmd2_app.completion_matches
+
def test_path_completion_single_end(cmd2_app, request):
test_dir = os.path.dirname(request.module.__file__)
@@ -316,8 +331,8 @@ def test_default_to_shell_completion(cmd2_app, request):
assert first_match is not None and cmd2_app.completion_matches == [text + '.py ']
-def test_path_completion_cwd(cmd2_app):
- # Run path complete with no search text
+def test_path_completion_no_text(cmd2_app):
+ # Run path complete with no search text which should show what's in cwd
text = ''
line = 'shell ls {}'.format(text)
endidx = len(line)
@@ -330,13 +345,34 @@ def test_path_completion_cwd(cmd2_app):
endidx = len(line)
begidx = endidx - len(text)
- # We have to strip off the text from the beginning since the matches are entire paths
+ # We have to strip off the path from the beginning since the matches are entire paths
completions_cwd = [match.replace(text, '', 1) for match in cmd2_app.path_complete(text, line, begidx, endidx)]
# Verify that the first test gave results for entries in the cwd
assert completions_no_text == completions_cwd
assert completions_cwd
+def test_path_completion_no_path(cmd2_app):
+ # Run path complete with search text that isn't preceded by a path. This should use CWD as the path.
+ text = 's'
+ line = 'shell ls {}'.format(text)
+ endidx = len(line)
+ begidx = endidx - len(text)
+ completions_no_text = cmd2_app.path_complete(text, line, begidx, endidx)
+
+ # Run path complete with path set to the CWD
+ text = os.getcwd() + os.path.sep + 's'
+ line = 'shell ls {}'.format(text)
+ endidx = len(line)
+ begidx = endidx - len(text)
+
+ # We have to strip off the path from the beginning since the matches are entire paths (Leave the 's')
+ completions_cwd = [match.replace(text[:-1], '', 1) for match in cmd2_app.path_complete(text, line, begidx, endidx)]
+
+ # Verify that the first test gave results for entries in the cwd
+ assert completions_no_text == completions_cwd
+ assert completions_cwd
+
def test_path_completion_doesnt_match_wildcards(cmd2_app, request):
test_dir = os.path.dirname(request.module.__file__)
@@ -399,7 +435,7 @@ def test_path_completion_directories_only(cmd2_app, request):
expected = [text + 'cripts' + os.path.sep]
- assert cmd2_app.path_complete(text, line, begidx, endidx, dir_only=True) == expected
+ assert cmd2_app.path_complete(text, line, begidx, endidx, os.path.isdir) == expected
def test_basic_completion_single(cmd2_app):
text = 'Pi'