summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-23 20:38:17 -0400
committerTodd Leonhardt <todd.leonhardt@gmail.com>2019-06-23 20:38:17 -0400
commit181cecb217dd73056b72874d225e34528d484de8 (patch)
tree6780eac90814677ce1fe998521d524373211af7f /tests
parentf2166d89e313f6f0b24ced45f2b31109a0d11a2d (diff)
downloadcmd2-git-181cecb217dd73056b72874d225e34528d484de8.tar.gz
Restored a few attributes to be public
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py2
-rw-r--r--tests/test_autocompletion.py26
-rw-r--r--tests/test_completion.py76
3 files changed, 52 insertions, 52 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 9af82637..b049dfff 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -168,7 +168,7 @@ def complete_tester(text: str, line: str, begidx: int, endidx: int, app) -> Opti
:param endidx: the ending index of the prefix text
:param app: the cmd2 app that will run completions
:return: The first matched string or None if there are no matches
- Matches are stored in app._completion_matches
+ Matches are stored in app.completion_matches
These matches also have been sorted by complete()
"""
def get_line():
diff --git a/tests/test_autocompletion.py b/tests/test_autocompletion.py
index 72c5e72b..4e1ceff0 100644
--- a/tests/test_autocompletion.py
+++ b/tests/test_autocompletion.py
@@ -77,7 +77,7 @@ def test_autocomp_flags(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['--duration', '--help', '--type', '-d', '-h', '-t']
+ cmd2_app.completion_matches == ['--duration', '--help', '--type', '-d', '-h', '-t']
def test_autcomp_hint(cmd2_app, capsys):
text = ''
@@ -106,7 +106,7 @@ def test_autcomp_flag_comp(cmd2_app, capsys):
out, err = capsys.readouterr()
assert first_match is not None and \
- cmd2_app._completion_matches == ['--duration ']
+ cmd2_app.completion_matches == ['--duration ']
def test_autocomp_flags_choices(cmd2_app):
@@ -117,7 +117,7 @@ def test_autocomp_flags_choices(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['movie', 'show']
+ cmd2_app.completion_matches == ['movie', 'show']
def test_autcomp_hint_in_narg_range(cmd2_app, capsys):
@@ -160,7 +160,7 @@ def test_autocomp_subcmd_nested(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['add', 'delete', 'list', 'load']
+ cmd2_app.completion_matches == ['add', 'delete', 'list', 'load']
def test_autocomp_subcmd_flag_choices_append(cmd2_app):
@@ -171,7 +171,7 @@ def test_autocomp_subcmd_flag_choices_append(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['G', 'NC-17', 'PG', 'PG-13', 'R']
+ cmd2_app.completion_matches == ['G', 'NC-17', 'PG', 'PG-13', 'R']
def test_autocomp_subcmd_flag_choices_append_exclude(cmd2_app):
text = ''
@@ -181,7 +181,7 @@ def test_autocomp_subcmd_flag_choices_append_exclude(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['G', 'NC-17', 'R']
+ cmd2_app.completion_matches == ['G', 'NC-17', 'R']
def test_autocomp_subcmd_flag_comp_func(cmd2_app):
@@ -192,7 +192,7 @@ def test_autocomp_subcmd_flag_comp_func(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels']
+ cmd2_app.completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels']
def test_autocomp_subcmd_flag_comp_list(cmd2_app):
@@ -213,7 +213,7 @@ def test_autocomp_subcmd_flag_comp_func_attr(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels']
+ cmd2_app.completion_matches == ['Adam Driver', 'Alec Guinness', 'Andy Serkis', 'Anthony Daniels']
def test_autocomp_subcmd_flag_comp_list_attr(cmd2_app):
@@ -244,7 +244,7 @@ def test_autocomp_pos_after_flag(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['John Boyega" ']
+ cmd2_app.completion_matches == ['John Boyega" ']
def test_autocomp_custom_func_list_arg(cmd2_app):
@@ -255,7 +255,7 @@ def test_autocomp_custom_func_list_arg(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['SW_CW', 'SW_REB', 'SW_TCW']
+ cmd2_app.completion_matches == ['SW_CW', 'SW_REB', 'SW_TCW']
def test_autocomp_custom_func_list_and_dict_arg(cmd2_app):
@@ -266,7 +266,7 @@ def test_autocomp_custom_func_list_and_dict_arg(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03']
+ cmd2_app.completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03']
def test_autocomp_custom_func_dict_arg(cmd2_app):
@@ -277,7 +277,7 @@ def test_autocomp_custom_func_dict_arg(cmd2_app):
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
assert first_match is not None and \
- cmd2_app._completion_matches == ['/home/user/another.db', '/home/user/file space.db', '/home/user/file.db']
+ cmd2_app.completion_matches == ['/home/user/another.db', '/home/user/file space.db', '/home/user/file.db']
def test_argparse_remainder_flag_completion(cmd2_app):
@@ -333,7 +333,7 @@ def test_completion_after_double_dash(cmd2_app):
# Since -- is the last token, then it should show flag choices
first_match = complete_tester(text, line, begidx, endidx, cmd2_app)
- assert first_match is not None and '--help' in cmd2_app._completion_matches
+ assert first_match is not None and '--help' in cmd2_app.completion_matches
# Test -- to end all flag completion
text = '--'
diff --git a/tests/test_completion.py b/tests/test_completion.py
index 96c1ff79..d5d30e51 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):
@@ -382,7 +382,7 @@ def test_default_to_shell_completion(cmd2_app, request):
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):
@@ -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']