diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_autocompletion.py | 19 | ||||
-rw-r--r-- | tests/test_completion.py | 18 |
2 files changed, 33 insertions, 4 deletions
diff --git a/tests/test_autocompletion.py b/tests/test_autocompletion.py index a5dafd2d..005eee81 100644 --- a/tests/test_autocompletion.py +++ b/tests/test_autocompletion.py @@ -229,7 +229,7 @@ def test_autocomp_subcmd_flag_comp_list_attr(cmd2_app): assert first_match is not None and first_match == '"Gareth Edwards' -def test_autcomp_pos_consumed(cmd2_app): +def test_autocomp_pos_consumed(cmd2_app): text = '' line = 'library movie add SW_EP01 {}'.format(text) endidx = len(line) @@ -239,7 +239,7 @@ def test_autcomp_pos_consumed(cmd2_app): assert first_match is None -def test_autcomp_pos_after_flag(cmd2_app): +def test_autocomp_pos_after_flag(cmd2_app): text = 'Joh' line = 'video movies add -d "George Lucas" -- "Han Solo" PG "Emilia Clarke" "{}'.format(text) endidx = len(line) @@ -250,7 +250,7 @@ def test_autcomp_pos_after_flag(cmd2_app): cmd2_app.completion_matches == ['John Boyega" '] -def test_autcomp_custom_func_list_arg(cmd2_app): +def test_autocomp_custom_func_list_arg(cmd2_app): text = 'SW_' line = 'library show add {}'.format(text) endidx = len(line) @@ -261,7 +261,7 @@ def test_autcomp_custom_func_list_arg(cmd2_app): cmd2_app.completion_matches == ['SW_CW', 'SW_REB', 'SW_TCW'] -def test_autcomp_custom_func_list_and_dict_arg(cmd2_app): +def test_autocomp_custom_func_list_and_dict_arg(cmd2_app): text = '' line = 'library show add SW_REB {}'.format(text) endidx = len(line) @@ -272,6 +272,17 @@ def test_autcomp_custom_func_list_and_dict_arg(cmd2_app): cmd2_app.completion_matches == ['S01E02', 'S01E03', 'S02E01', 'S02E03'] +def test_autocomp_custom_func_dict_arg(cmd2_app): + text = '/home/user/' + line = 'video movies load {}'.format(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 == ['/home/user/another.db', '/home/user/file space.db', '/home/user/file.db'] + + def test_argparse_remainder_flag_completion(cmd2_app): import cmd2 import argparse diff --git a/tests/test_completion.py b/tests/test_completion.py index 23843012..158856ec 100644 --- a/tests/test_completion.py +++ b/tests/test_completion.py @@ -77,6 +77,12 @@ class CompletionsExample(cmd2.Cmd): num_strs = ['2', '11', '1'] return self.basic_complete(text, line, begidx, endidx, num_strs) + def do_test_raise_exception(self, args): + pass + + def complete_test_raise_exception(self, text, line, begidx, endidx): + raise IndexError("You are out of bounds!!") + @pytest.fixture def cmd2_app(): @@ -120,6 +126,18 @@ def test_complete_bogus_command(cmd2_app): first_match = complete_tester(text, line, begidx, endidx, cmd2_app) assert first_match is None +def test_complete_exception(cmd2_app, capsys): + text = '' + line = 'test_raise_exception {}'.format(text) + endidx = len(line) + begidx = endidx - len(text) + + first_match = complete_tester(text, line, begidx, endidx, cmd2_app) + out, err = capsys.readouterr() + + 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 pyscript {1}') |