diff options
author | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 17:21:33 -0800 |
---|---|---|
committer | xNinjaKittyx <xNinjaKittyx@users.noreply.github.com> | 2020-12-15 18:20:13 -0800 |
commit | 9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch) | |
tree | 567693115cc101efb9254a96d96d80e9f9ccd557 /tests/test_completion.py | |
parent | 03c65c60b39e369958b056c5c844d36d515c8a63 (diff) | |
download | cmd2-git-ci_improvements.tar.gz |
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml
There are also some small changes to travis.yml and tasks.py to reduce
some repeated configurations that should be consolidated into
setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'tests/test_completion.py')
-rwxr-xr-x | tests/test_completion.py | 236 |
1 files changed, 149 insertions, 87 deletions
diff --git a/tests/test_completion.py b/tests/test_completion.py index db243f48..785bb49d 100755 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -28,44 +28,42 @@ from .conftest import complete_tester, normalize, run_cmd # List of strings used with completion functions food_item_strs = ['Pizza', 'Ham', 'Ham Sandwich', 'Potato', 'Cheese "Pizza"'] sport_item_strs = ['Bat', 'Basket', 'Basketball', 'Football', 'Space Ball'] -delimited_strs = \ - [ - '/home/user/file.txt', - '/home/user/file space.txt', - '/home/user/prog.c', - '/home/other user/maps', - '/home/other user/tests' - ] +delimited_strs = [ + '/home/user/file.txt', + '/home/user/file space.txt', + '/home/user/prog.c', + '/home/other user/maps', + '/home/other user/tests', +] # Dictionary used with flag based completion functions -flag_dict = \ - { - # Tab complete food items after -f and --food flag in command line - '-f': food_item_strs, - '--food': food_item_strs, - - # Tab complete sport items after -s and --sport flag in command line - '-s': sport_item_strs, - '--sport': sport_item_strs, - } +flag_dict = { + # Tab complete food items after -f and --food flag in command line + '-f': food_item_strs, + '--food': food_item_strs, + # Tab complete sport items after -s and --sport flag in command line + '-s': sport_item_strs, + '--sport': sport_item_strs, +} # Dictionary used with index based completion functions -index_dict = \ - { - 1: food_item_strs, # Tab complete food items at index 1 in command line - 2: sport_item_strs, # Tab complete sport items at index 2 in command line - } +index_dict = { + 1: food_item_strs, # Tab complete food items at index 1 in command line + 2: sport_item_strs, # Tab complete sport items at index 2 in command line +} class CompletionsExample(cmd2.Cmd): """ Example cmd2 application used to exercise tab completion tests """ + def __init__(self): cmd2.Cmd.__init__(self, multiline_commands=['test_multiline']) self.foo = 'bar' - self.add_settable(utils.Settable('foo', str, description="a settable param", - completer_method=CompletionsExample.complete_foo_val)) + self.add_settable( + utils.Settable('foo', str, description="a settable param", completer_method=CompletionsExample.complete_foo_val) + ) def do_test_basic(self, args): pass @@ -130,6 +128,7 @@ def test_cmd2_command_completion_single(cmd2_app): begidx = endidx - len(text) assert cmd2_app.completenames(text, line, begidx, endidx) == ['help'] + def test_complete_command_single(cmd2_app): text = 'he' line = text @@ -139,6 +138,7 @@ def test_complete_command_single(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is not None and cmd2_app.completion_matches == ['help '] + def test_complete_empty_arg(cmd2_app): text = '' line = 'help {}'.format(text) @@ -150,6 +150,7 @@ def test_complete_empty_arg(cmd2_app): assert first_match is not None and cmd2_app.completion_matches == expected + def test_complete_bogus_command(cmd2_app): text = '' line = 'fizbuzz {}'.format(text) @@ -160,6 +161,7 @@ def test_complete_bogus_command(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_complete_exception(cmd2_app, capsys): text = '' line = 'test_raise_exception {}'.format(text) @@ -172,6 +174,7 @@ def test_complete_exception(cmd2_app, capsys): assert first_match is None assert "IndexError" in err + def test_complete_macro(base_app, request): # Create the macro out, err = run_cmd(base_app, 'macro create fake run_pyscript {1}') @@ -217,6 +220,7 @@ def test_cmd2_command_completion_multiple(cmd2_app): begidx = endidx - len(text) assert cmd2_app.completenames(text, line, begidx, endidx) == ['help', 'history'] + def test_cmd2_command_completion_nomatch(cmd2_app): text = 'fakecommand' line = text @@ -236,6 +240,7 @@ def test_cmd2_help_completion_single(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 '] + def test_cmd2_help_completion_multiple(cmd2_app): text = 'h' line = 'help {}'.format(text) @@ -274,9 +279,8 @@ def test_shell_command_completion_shortcut(cmd2_app): begidx = 0 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.display_matches == expected_display + assert first_match is not None and cmd2_app.completion_matches == expected and cmd2_app.display_matches == expected_display + def test_shell_command_completion_doesnt_match_wildcards(cmd2_app): if sys.platform == "win32": @@ -291,6 +295,7 @@ def test_shell_command_completion_doesnt_match_wildcards(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None + def test_shell_command_completion_multiple(cmd2_app): if sys.platform == "win32": text = 'c' @@ -306,6 +311,7 @@ def test_shell_command_completion_multiple(cmd2_app): 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_shell_command_completion_nomatch(cmd2_app): text = 'zzzz' line = 'shell {}'.format(text) @@ -315,6 +321,7 @@ def test_shell_command_completion_nomatch(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None + def test_shell_command_completion_doesnt_complete_when_just_shell(cmd2_app): text = '' line = 'shell {}'.format(text) @@ -324,6 +331,7 @@ def test_shell_command_completion_doesnt_complete_when_just_shell(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None + def test_shell_command_completion_does_path_completion_when_after_command(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -336,6 +344,7 @@ 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__) @@ -363,6 +372,7 @@ def test_path_completion_single_end(cmd2_app, request): assert cmd2_app.path_complete(text, line, begidx, endidx) == [text + '.py'] + def test_path_completion_multiple(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -376,6 +386,7 @@ def test_path_completion_multiple(cmd2_app, request): expected = [text + 'cript.py', text + 'cript.txt', text + 'cripts' + os.path.sep] assert matches == expected + def test_path_completion_nomatch(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -431,6 +442,7 @@ def test_path_completion_no_text(cmd2_app): 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' @@ -471,6 +483,7 @@ def test_path_completion_cwd_is_root_dir(cmd2_app): # Restore CWD os.chdir(cwd) + def test_path_completion_doesnt_match_wildcards(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -483,10 +496,14 @@ def test_path_completion_doesnt_match_wildcards(cmd2_app, request): # Currently path completion doesn't accept wildcards, so will always return empty results assert cmd2_app.path_complete(text, line, begidx, endidx) == [] -@pytest.mark.skipif(sys.platform == 'win32', reason="getpass.getuser() does not work on Windows in AppVeyor because " - "no user name environment variables are set") + +@pytest.mark.skipif( + sys.platform == 'win32', + reason="getpass.getuser() does not work on Windows in AppVeyor because " "no user name environment variables are set", +) def test_path_completion_complete_user(cmd2_app): import getpass + user = getpass.getuser() text = '~{}'.format(user) @@ -498,6 +515,7 @@ def test_path_completion_complete_user(cmd2_app): expected = text + os.path.sep assert expected in completions + def test_path_completion_user_path_expansion(cmd2_app): # Run path with a tilde and a slash if sys.platform.startswith('win'): @@ -510,8 +528,7 @@ def test_path_completion_user_path_expansion(cmd2_app): line = 'shell {} {}'.format(cmd, text) endidx = len(line) begidx = endidx - len(text) - completions_tilde_slash = [match.replace(text, '', 1) for match in cmd2_app.path_complete(text, line, - begidx, endidx)] + completions_tilde_slash = [match.replace(text, '', 1) for match in cmd2_app.path_complete(text, line, begidx, endidx)] # Run path complete on the user's home directory text = os.path.expanduser('~') + os.path.sep @@ -522,6 +539,7 @@ def test_path_completion_user_path_expansion(cmd2_app): assert completions_tilde_slash == completions_home + def test_path_completion_directories_only(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -535,6 +553,7 @@ def test_path_completion_directories_only(cmd2_app, request): assert cmd2_app.path_complete(text, line, begidx, endidx, path_filter=os.path.isdir) == expected + def test_basic_completion_single(cmd2_app): text = 'Pi' line = 'list_food -f {}'.format(text) @@ -543,6 +562,7 @@ def test_basic_completion_single(cmd2_app): assert utils.basic_complete(text, line, begidx, endidx, food_item_strs) == ['Pizza'] + def test_basic_completion_multiple(cmd2_app): text = '' line = 'list_food -f {}'.format(text) @@ -552,6 +572,7 @@ def test_basic_completion_multiple(cmd2_app): matches = sorted(utils.basic_complete(text, line, begidx, endidx, food_item_strs)) assert matches == sorted(food_item_strs) + def test_basic_completion_nomatch(cmd2_app): text = 'q' line = 'list_food -f {}'.format(text) @@ -560,6 +581,7 @@ def test_basic_completion_nomatch(cmd2_app): assert utils.basic_complete(text, line, begidx, endidx, food_item_strs) == [] + def test_delimiter_completion(cmd2_app): text = '/home/' line = 'run_script {}'.format(text) @@ -574,6 +596,7 @@ def test_delimiter_completion(cmd2_app): assert display_list == ['other user', 'user'] + def test_flag_based_completion_single(cmd2_app): text = 'Pi' line = 'list_food -f {}'.format(text) @@ -582,6 +605,7 @@ def test_flag_based_completion_single(cmd2_app): assert cmd2_app.flag_based_complete(text, line, begidx, endidx, flag_dict) == ['Pizza'] + def test_flag_based_completion_multiple(cmd2_app): text = '' line = 'list_food -f {}'.format(text) @@ -591,6 +615,7 @@ def test_flag_based_completion_multiple(cmd2_app): matches = sorted(cmd2_app.flag_based_complete(text, line, begidx, endidx, flag_dict)) assert matches == sorted(food_item_strs) + def test_flag_based_completion_nomatch(cmd2_app): text = 'q' line = 'list_food -f {}'.format(text) @@ -599,6 +624,7 @@ def test_flag_based_completion_nomatch(cmd2_app): assert cmd2_app.flag_based_complete(text, line, begidx, endidx, flag_dict) == [] + def test_flag_based_default_completer(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -608,8 +634,10 @@ def test_flag_based_default_completer(cmd2_app, request): endidx = len(line) begidx = endidx - len(text) - assert cmd2_app.flag_based_complete(text, line, begidx, endidx, - flag_dict, all_else=cmd2_app.path_complete) == [text + 'onftest.py'] + assert cmd2_app.flag_based_complete(text, line, begidx, endidx, flag_dict, all_else=cmd2_app.path_complete) == [ + text + 'onftest.py' + ] + def test_flag_based_callable_completer(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -621,8 +649,7 @@ def test_flag_based_callable_completer(cmd2_app, request): begidx = endidx - len(text) flag_dict['-o'] = cmd2_app.path_complete - assert cmd2_app.flag_based_complete(text, line, begidx, endidx, - flag_dict) == [text + 'onftest.py'] + assert cmd2_app.flag_based_complete(text, line, begidx, endidx, flag_dict) == [text + 'onftest.py'] def test_index_based_completion_single(cmd2_app): @@ -633,6 +660,7 @@ def test_index_based_completion_single(cmd2_app): assert cmd2_app.index_based_complete(text, line, begidx, endidx, index_dict) == ['Football'] + def test_index_based_completion_multiple(cmd2_app): text = '' line = 'command Pizza {}'.format(text) @@ -642,6 +670,7 @@ def test_index_based_completion_multiple(cmd2_app): matches = sorted(cmd2_app.index_based_complete(text, line, begidx, endidx, index_dict)) assert matches == sorted(sport_item_strs) + def test_index_based_completion_nomatch(cmd2_app): text = 'q' line = 'command {}'.format(text) @@ -649,6 +678,7 @@ def test_index_based_completion_nomatch(cmd2_app): begidx = endidx - len(text) assert cmd2_app.index_based_complete(text, line, begidx, endidx, index_dict) == [] + def test_index_based_default_completer(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -658,8 +688,10 @@ def test_index_based_default_completer(cmd2_app, request): endidx = len(line) begidx = endidx - len(text) - assert cmd2_app.index_based_complete(text, line, begidx, endidx, - index_dict, all_else=cmd2_app.path_complete) == [text + 'onftest.py'] + assert cmd2_app.index_based_complete(text, line, begidx, endidx, index_dict, all_else=cmd2_app.path_complete) == [ + text + 'onftest.py' + ] + def test_index_based_callable_completer(cmd2_app, request): test_dir = os.path.dirname(request.module.__file__) @@ -687,6 +719,7 @@ def test_tokens_for_completion_quoted(cmd2_app): assert expected_tokens == tokens assert expected_raw_tokens == raw_tokens + def test_tokens_for_completion_unclosed_quote(cmd2_app): text = 'Pi' line = 'list_food "{}'.format(text) @@ -700,6 +733,7 @@ def test_tokens_for_completion_unclosed_quote(cmd2_app): assert expected_tokens == tokens assert expected_raw_tokens == raw_tokens + def test_tokens_for_completion_punctuation(cmd2_app): """Test that redirectors and terminators are word delimiters""" text = 'file' @@ -714,6 +748,7 @@ def test_tokens_for_completion_punctuation(cmd2_app): assert expected_tokens == tokens assert expected_raw_tokens == raw_tokens + def test_tokens_for_completion_quoted_punctuation(cmd2_app): """Test that quoted punctuation characters are not word delimiters""" text = '>file' @@ -728,6 +763,7 @@ def test_tokens_for_completion_quoted_punctuation(cmd2_app): assert expected_tokens == tokens assert expected_raw_tokens == raw_tokens + def test_add_opening_quote_basic_no_text(cmd2_app): text = '' line = 'test_basic {}'.format(text) @@ -736,8 +772,8 @@ 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, - key=cmd2_app.default_sort_key) + assert first_match is not None and cmd2_app.completion_matches == sorted(food_item_strs, key=cmd2_app.default_sort_key) + def test_add_opening_quote_basic_nothing_added(cmd2_app): text = 'P' @@ -748,6 +784,7 @@ def test_add_opening_quote_basic_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 == ['Pizza', 'Potato'] + def test_add_opening_quote_basic_quote_added(cmd2_app): text = 'Ha' line = 'test_basic {}'.format(text) @@ -758,6 +795,7 @@ def test_add_opening_quote_basic_quote_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 + def test_add_opening_quote_basic_single_quote_added(cmd2_app): text = 'Ch' line = 'test_basic {}'.format(text) @@ -768,6 +806,7 @@ def test_add_opening_quote_basic_single_quote_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 + 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 text = 'Ham' @@ -779,6 +818,7 @@ def test_add_opening_quote_basic_text_is_common_prefix(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_add_opening_quote_delimited_no_text(cmd2_app): text = '' line = 'test_delimited {}'.format(text) @@ -787,8 +827,8 @@ 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, - key=cmd2_app.default_sort_key) + assert first_match is not None and cmd2_app.completion_matches == sorted(delimited_strs, key=cmd2_app.default_sort_key) + def test_add_opening_quote_delimited_nothing_added(cmd2_app): text = '/ho' @@ -800,9 +840,12 @@ def test_add_opening_quote_delimited_nothing_added(cmd2_app): expected_display = sorted(['other user', 'user'], key=cmd2_app.default_sort_key) 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.display_matches == expected_display + assert ( + first_match is not None + and cmd2_app.completion_matches == expected_matches + and cmd2_app.display_matches == expected_display + ) + def test_add_opening_quote_delimited_quote_added(cmd2_app): text = '/home/user/fi' @@ -814,9 +857,12 @@ def test_add_opening_quote_delimited_quote_added(cmd2_app): expected_display = sorted(['file.txt', 'file space.txt'], key=cmd2_app.default_sort_key) 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 \ - cmd2_app.display_matches == expected_display + assert ( + first_match is not None + 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): # This tests when the text entered is the same as the common prefix of the matches @@ -829,9 +875,12 @@ def test_add_opening_quote_delimited_text_is_common_prefix(cmd2_app): expected_display = sorted(['file.txt', 'file space.txt'], key=cmd2_app.default_sort_key) 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 \ - cmd2_app.display_matches == expected_display + assert ( + first_match is not None + 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): # This test when a space appears before the part of the string that is the display match @@ -844,9 +893,12 @@ def test_add_opening_quote_delimited_space_in_prefix(cmd2_app): expected_display = ['maps', 'tests'] 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 \ - cmd2_app.display_matches == expected_display + assert ( + first_match is not None + and os.path.commonprefix(cmd2_app.completion_matches) == expected_common_prefix + and cmd2_app.display_matches == expected_display + ) + def test_no_completer(cmd2_app): text = '' @@ -858,6 +910,7 @@ 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): text = '' line = '" {}'.format(text) @@ -898,36 +951,39 @@ def test_complete_multiline_on_multiple_lines(cmd2_app): # Used by redirect_complete tests class RedirCompType(enum.Enum): - SHELL_CMD = 1, - PATH = 2, - DEFAULT = 3, + SHELL_CMD = (1,) + PATH = (2,) + DEFAULT = (3,) NONE = 4 -@pytest.mark.parametrize('line, comp_type', [ - ('fake', RedirCompType.DEFAULT), - ('fake arg', RedirCompType.DEFAULT), - ('fake |', RedirCompType.SHELL_CMD), - ('fake | grep', RedirCompType.PATH), - ('fake | grep arg', RedirCompType.PATH), - ('fake | grep >', RedirCompType.PATH), - ('fake | grep > >', RedirCompType.NONE), - ('fake | grep > file', RedirCompType.NONE), - ('fake | grep > file >', RedirCompType.NONE), - ('fake | grep > file |', RedirCompType.SHELL_CMD), - ('fake | grep > file | grep', RedirCompType.PATH), - ('fake | |', RedirCompType.NONE), - ('fake | >', RedirCompType.NONE), - ('fake >', RedirCompType.PATH), - ('fake >>', RedirCompType.PATH), - ('fake > >', RedirCompType.NONE), - ('fake > |', RedirCompType.SHELL_CMD), - ('fake >> file |', RedirCompType.SHELL_CMD), - ('fake >> file | grep', RedirCompType.PATH), - ('fake > file', RedirCompType.NONE), - ('fake > file >', RedirCompType.NONE), - ('fake > file >>', RedirCompType.NONE), -]) +@pytest.mark.parametrize( + 'line, comp_type', + [ + ('fake', RedirCompType.DEFAULT), + ('fake arg', RedirCompType.DEFAULT), + ('fake |', RedirCompType.SHELL_CMD), + ('fake | grep', RedirCompType.PATH), + ('fake | grep arg', RedirCompType.PATH), + ('fake | grep >', RedirCompType.PATH), + ('fake | grep > >', RedirCompType.NONE), + ('fake | grep > file', RedirCompType.NONE), + ('fake | grep > file >', RedirCompType.NONE), + ('fake | grep > file |', RedirCompType.SHELL_CMD), + ('fake | grep > file | grep', RedirCompType.PATH), + ('fake | |', RedirCompType.NONE), + ('fake | >', RedirCompType.NONE), + ('fake >', RedirCompType.PATH), + ('fake >>', RedirCompType.PATH), + ('fake > >', RedirCompType.NONE), + ('fake > |', RedirCompType.SHELL_CMD), + ('fake >> file |', RedirCompType.SHELL_CMD), + ('fake >> file | grep', RedirCompType.PATH), + ('fake > file', RedirCompType.NONE), + ('fake > file >', RedirCompType.NONE), + ('fake > file >>', RedirCompType.NONE), + ], +) def test_redirect_complete(cmd2_app, monkeypatch, line, comp_type): # Test both cases of allow_redirection cmd2_app.allow_redirection = True @@ -974,6 +1030,7 @@ def test_complete_set_value(cmd2_app): assert first_match == "SUCCESS " assert cmd2_app.completion_hint == "Hint:\n value a settable param\n" + def test_complete_set_value_invalid_settable(cmd2_app, capsys): text = '' line = 'set fake {}'.format(text) @@ -986,12 +1043,14 @@ def test_complete_set_value_invalid_settable(cmd2_app, capsys): out, err = capsys.readouterr() assert "fake is not a settable parameter" in out + @pytest.fixture def sc_app(): c = SubcommandsExample() c.stdout = utils.StdSim(c.stdout) return c + def test_cmd2_subcommand_completion_single_end(sc_app): text = 'f' line = 'base {}'.format(text) @@ -1003,6 +1062,7 @@ def test_cmd2_subcommand_completion_single_end(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 '] + def test_cmd2_subcommand_completion_multiple(sc_app): text = '' line = 'base {}'.format(text) @@ -1012,6 +1072,7 @@ def test_cmd2_subcommand_completion_multiple(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) assert first_match is not None and sc_app.completion_matches == ['bar', 'foo', 'sport'] + def test_cmd2_subcommand_completion_nomatch(sc_app): text = 'z' line = 'base {}'.format(text) @@ -1033,6 +1094,7 @@ def test_help_subcommand_completion_single(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 '] + def test_help_subcommand_completion_multiple(sc_app): text = '' line = 'help base {}'.format(text) @@ -1052,6 +1114,7 @@ def test_help_subcommand_completion_nomatch(sc_app): first_match = complete_tester(text, line, begidx, endidx, sc_app) assert first_match is None + def test_subcommand_tab_completion(sc_app): # This makes sure the correct completer for the sport subcommand is called text = 'Foot' @@ -1085,9 +1148,8 @@ 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.display_matches == ['Space Ball'] + assert first_match is not None and sc_app.completion_matches == ['Ball" '] and sc_app.display_matches == ['Space Ball'] + #################################################### @@ -1207,6 +1269,7 @@ def test_help_subcommand_completion_multiple_scu(scu_app): first_match = complete_tester(text, line, begidx, endidx, scu_app) assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport'] + def test_help_subcommand_completion_with_flags_before_command(scu_app): text = '' line = 'help -h -v base {}'.format(text) @@ -1216,6 +1279,7 @@ def test_help_subcommand_completion_with_flags_before_command(scu_app): first_match = complete_tester(text, line, begidx, endidx, scu_app) assert first_match is not None and scu_app.completion_matches == ['bar', 'foo', 'sport'] + def test_complete_help_subcommands_with_blank_command(scu_app): text = '' line = 'help "" {}'.format(text) @@ -1269,6 +1333,4 @@ 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.display_matches == ['Space Ball'] + assert first_match is not None and scu_app.completion_matches == ['Ball" '] and scu_app.display_matches == ['Space Ball'] |