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.py92
1 files changed, 46 insertions, 46 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 91519b0a..96c1ff79 100644
--- a/tests/test_completion.py
+++ b/tests/test_completion.py
@@ -112,7 +112,7 @@ def test_complete_command_single(cmd2_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == ['help ']
+ assert first_match is not None and cmd2_app._completion_matches == ['help ']
def test_complete_empty_arg(cmd2_app):
text = ''
@@ -123,7 +123,7 @@ def test_complete_empty_arg(cmd2_app):
expected = sorted(cmd2_app.get_visible_commands())
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 = ''
@@ -133,7 +133,7 @@ def test_complete_bogus_command(cmd2_app):
expected = ['default ']
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_exception(cmd2_app, capsys):
text = ''
@@ -163,7 +163,7 @@ def test_complete_macro(base_app, request):
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 is not None and base_app.completion_matches == expected
+ assert first_match is not None and base_app._completion_matches == expected
def test_matches_sort_key(cmd2_app):
@@ -176,13 +176,13 @@ def test_matches_sort_key(cmd2_app):
cmd2_app.matches_sort_key = cmd2.cmd2.ALPHABETICAL_SORT_KEY
expected = ['1', '11', '2']
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
# Now switch to natural sorting
cmd2_app.matches_sort_key = cmd2.cmd2.NATURAL_SORT_KEY
expected = ['1', '2', '11']
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_cmd2_command_completion_multiple(cmd2_app):
@@ -209,7 +209,7 @@ def test_cmd2_help_completion_single(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
# It is at end of line, so extra space is present
- assert first_match is not None and cmd2_app.completion_matches == ['help ']
+ assert first_match is not None and cmd2_app._completion_matches == ['help ']
def test_cmd2_help_completion_multiple(cmd2_app):
text = 'h'
@@ -218,7 +218,7 @@ def test_cmd2_help_completion_multiple(cmd2_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == ['help', 'history']
+ assert first_match is not None and cmd2_app._completion_matches == ['help', 'history']
def test_cmd2_help_completion_nomatch(cmd2_app):
@@ -250,7 +250,7 @@ def test_shell_command_completion_shortcut(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app.completion_matches == expected and \
+ cmd2_app._completion_matches == expected and \
cmd2_app.display_matches == expected_display
def test_shell_command_completion_doesnt_match_wildcards(cmd2_app):
@@ -279,7 +279,7 @@ def test_shell_command_completion_multiple(cmd2_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and expected in cmd2_app.completion_matches
+ assert first_match is not None and expected in cmd2_app._completion_matches
def test_shell_command_completion_nomatch(cmd2_app):
text = 'zzzz'
@@ -309,7 +309,7 @@ def test_shell_command_completion_does_path_completion_when_after_command(cmd2_a
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == [text + '.py ']
+ 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__)
@@ -324,7 +324,7 @@ def test_shell_commmand_complete_in_path(cmd2_app, request):
# 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
+ assert first_match is not None and expected in cmd2_app._completion_matches
def test_path_completion_single_end(cmd2_app, request):
@@ -375,14 +375,14 @@ def test_default_to_shell_completion(cmd2_app, request):
command = 'egrep'
# Make sure the command is on the testing system
- assert command in cmd2_app.get_exes_in_path(command)
+ assert command in utils.get_exes_in_path(command)
line = '{} {}'.format(command, text)
endidx = len(line)
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == [text + '.py ']
+ assert first_match is not None and cmd2_app._completion_matches == [text + '.py ']
def test_path_completion_no_text(cmd2_app):
@@ -658,7 +658,7 @@ def test_tokens_for_completion_quoted(cmd2_app):
expected_tokens = ['list_food', 'Pi', '']
expected_raw_tokens = ['list_food', '"Pi"', '']
- tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -671,7 +671,7 @@ def test_tokens_for_completion_unclosed_quote(cmd2_app):
expected_tokens = ['list_food', 'Pi']
expected_raw_tokens = ['list_food', '"Pi']
- tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -685,7 +685,7 @@ def test_tokens_for_completion_redirect(cmd2_app):
expected_tokens = ['command', '|', '<', '>>', 'file']
expected_raw_tokens = ['command', '|', '<', '>>', 'file']
- tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -695,11 +695,11 @@ def test_tokens_for_completion_quoted_redirect(cmd2_app):
endidx = len(line)
begidx = endidx - len(text)
- cmd2_app.statement_parser.redirection = True
+ cmd2_app._statement_parser.redirection = True
expected_tokens = ['command', '>file']
expected_raw_tokens = ['command', '">file']
- tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -709,11 +709,11 @@ def test_tokens_for_completion_redirect_off(cmd2_app):
endidx = len(line)
begidx = endidx - len(text)
- cmd2_app.statement_parser.allow_redirection = False
+ cmd2_app._statement_parser.allow_redirection = False
expected_tokens = ['command', '>file']
expected_raw_tokens = ['command', '>file']
- tokens, raw_tokens = cmd2_app.tokens_for_completion(line, begidx, endidx)
+ tokens, raw_tokens = cmd2_app._tokens_for_completion(line, begidx, endidx)
assert expected_tokens == tokens
assert expected_raw_tokens == raw_tokens
@@ -725,7 +725,7 @@ def test_add_opening_quote_basic_no_text(cmd2_app):
# The whole list will be returned with no opening quotes added
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == sorted(food_item_strs)
+ assert first_match is not None and cmd2_app._completion_matches == sorted(food_item_strs)
def test_add_opening_quote_basic_nothing_added(cmd2_app):
text = 'P'
@@ -734,7 +734,7 @@ def test_add_opening_quote_basic_nothing_added(cmd2_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == ['Pizza', 'Potato']
+ assert first_match is not None and cmd2_app._completion_matches == ['Pizza', 'Potato']
def test_add_opening_quote_basic_quote_added(cmd2_app):
text = 'Ha'
@@ -744,7 +744,7 @@ def test_add_opening_quote_basic_quote_added(cmd2_app):
expected = sorted(['"Ham', '"Ham Sandwich'])
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_add_opening_quote_basic_single_quote_added(cmd2_app):
text = 'Ch'
@@ -754,7 +754,7 @@ def test_add_opening_quote_basic_single_quote_added(cmd2_app):
expected = ["'Cheese \"Pizza\"' "]
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_add_opening_quote_basic_text_is_common_prefix(cmd2_app):
# This tests when the text entered is the same as the common prefix of the matches
@@ -765,7 +765,7 @@ def test_add_opening_quote_basic_text_is_common_prefix(cmd2_app):
expected = sorted(['"Ham', '"Ham Sandwich'])
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_add_opening_quote_delimited_no_text(cmd2_app):
text = ''
@@ -775,7 +775,7 @@ def test_add_opening_quote_delimited_no_text(cmd2_app):
# The whole list will be returned with no opening quotes added
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and cmd2_app.completion_matches == sorted(delimited_strs)
+ assert first_match is not None and cmd2_app._completion_matches == sorted(delimited_strs)
def test_add_opening_quote_delimited_nothing_added(cmd2_app):
text = '/ho'
@@ -788,7 +788,7 @@ def test_add_opening_quote_delimited_nothing_added(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app.completion_matches == expected_matches and \
+ cmd2_app._completion_matches == expected_matches and \
cmd2_app.display_matches == expected_display
def test_add_opening_quote_delimited_quote_added(cmd2_app):
@@ -802,7 +802,7 @@ def test_add_opening_quote_delimited_quote_added(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \
+ os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \
cmd2_app.display_matches == expected_display
def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app):
@@ -817,7 +817,7 @@ def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \
+ os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \
cmd2_app.display_matches == expected_display
def test_add_opening_quote_delimited_space_in_prefix(cmd2_app):
@@ -832,7 +832,7 @@ def test_add_opening_quote_delimited_space_in_prefix(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix and \
+ os.path.commonprefix(cmd2_app._completion_matches) == expected_common_prefix and \
cmd2_app.display_matches == expected_display
def test_no_completer(cmd2_app):
@@ -843,7 +843,7 @@ def test_no_completer(cmd2_app):
expected = ['default ']
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_quote_as_command(cmd2_app):
text = ''
@@ -852,7 +852,7 @@ def test_quote_as_command(cmd2_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is None and not cmd2_app.completion_matches
+ assert first_match is None and not cmd2_app._completion_matches
@pytest.fixture
def sc_app():
@@ -869,7 +869,7 @@ def test_cmd2_subcommand_completion_single_end(sc_app):
first_match = complete_tester(text, line, begidx, endidx, sc_app)
# It is at end of line, so extra space is present
- assert first_match is not None and sc_app.completion_matches == ['foo ']
+ assert first_match is not None and sc_app._completion_matches == ['foo ']
def test_cmd2_subcommand_completion_multiple(sc_app):
text = ''
@@ -878,7 +878,7 @@ def test_cmd2_subcommand_completion_multiple(sc_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, sc_app)
- assert first_match is not None and sc_app.completion_matches == ['bar', 'foo', 'sport']
+ assert first_match is not None and sc_app._completion_matches == ['bar', 'foo', 'sport']
def test_cmd2_subcommand_completion_nomatch(sc_app):
text = 'z'
@@ -899,7 +899,7 @@ def test_cmd2_help_subcommand_completion_single(sc_app):
first_match = complete_tester(text, line, begidx, endidx, sc_app)
# It is at end of line, so extra space is present
- assert first_match is not None and sc_app.completion_matches == ['base ']
+ assert first_match is not None and sc_app._completion_matches == ['base ']
def test_cmd2_help_subcommand_completion_multiple(sc_app):
text = ''
@@ -908,7 +908,7 @@ def test_cmd2_help_subcommand_completion_multiple(sc_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, sc_app)
- assert first_match is not None and sc_app.completion_matches == ['bar', 'foo', 'sport']
+ assert first_match is not None and sc_app._completion_matches == ['bar', 'foo', 'sport']
def test_cmd2_help_subcommand_completion_nomatch(sc_app):
@@ -930,7 +930,7 @@ def test_subcommand_tab_completion(sc_app):
first_match = complete_tester(text, line, begidx, endidx, sc_app)
# It is at end of line, so extra space is present
- assert first_match is not None and sc_app.completion_matches == ['Football ']
+ assert first_match is not None and sc_app._completion_matches == ['Football ']
def test_subcommand_tab_completion_with_no_completer(sc_app):
@@ -954,7 +954,7 @@ def test_subcommand_tab_completion_space_in_text(sc_app):
first_match = complete_tester(text, line, begidx, endidx, sc_app)
assert first_match is not None and \
- sc_app.completion_matches == ['Ball" '] and \
+ sc_app._completion_matches == ['Ball" '] and \
sc_app.display_matches == ['Space Ball']
####################################################
@@ -1032,7 +1032,7 @@ def test_cmd2_subcmd_with_unknown_completion_single_end(scu_app):
print('first_match: {}'.format(first_match))
# It is at end of line, so extra space is present
- assert first_match is not None and scu_app.completion_matches == ['foo ']
+ assert first_match is not None and scu_app._completion_matches == ['foo ']
def test_cmd2_subcmd_with_unknown_completion_multiple(scu_app):
@@ -1042,7 +1042,7 @@ def test_cmd2_subcmd_with_unknown_completion_multiple(scu_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, scu_app)
- assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport']
+ assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport']
def test_cmd2_subcmd_with_unknown_completion_nomatch(scu_app):
@@ -1064,7 +1064,7 @@ def test_cmd2_help_subcommand_completion_single_scu(scu_app):
first_match = complete_tester(text, line, begidx, endidx, scu_app)
# It is at end of line, so extra space is present
- assert first_match is not None and scu_app.completion_matches == ['base ']
+ assert first_match is not None and scu_app._completion_matches == ['base ']
def test_cmd2_help_subcommand_completion_multiple_scu(scu_app):
@@ -1074,7 +1074,7 @@ def test_cmd2_help_subcommand_completion_multiple_scu(scu_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, scu_app)
- assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport']
+ assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport']
def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app):
text = ''
@@ -1083,7 +1083,7 @@ def test_cmd2_help_subcommand_completion_with_flags_before_command(scu_app):
begidx = endidx - len(text)
first_match = complete_tester(text, line, begidx, endidx, scu_app)
- assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport']
+ assert first_match is not None and scu_app._completion_matches == ['bar', 'foo', 'sport']
def test_complete_help_subcommand_with_no_command(scu_app):
# No command because not enough tokens
@@ -1123,7 +1123,7 @@ def test_subcommand_tab_completion_scu(scu_app):
first_match = complete_tester(text, line, begidx, endidx, scu_app)
# It is at end of line, so extra space is present
- assert first_match is not None and scu_app.completion_matches == ['Football ']
+ assert first_match is not None and scu_app._completion_matches == ['Football ']
def test_subcommand_tab_completion_with_no_completer_scu(scu_app):
@@ -1147,5 +1147,5 @@ def test_subcommand_tab_completion_space_in_text_scu(scu_app):
first_match = complete_tester(text, line, begidx, endidx, scu_app)
assert first_match is not None and \
- scu_app.completion_matches == ['Ball" '] and \
+ scu_app._completion_matches == ['Ball" '] and \
scu_app.display_matches == ['Space Ball']