diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-06 00:36:39 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-05-06 00:36:39 -0400 |
commit | fc41d86b275ba4bbd2dbd76c766dbc2abc138021 (patch) | |
tree | 70db8b01eb2a113ab28468d6de29a4ed3c99c744 /tests | |
parent | 4ebcf42f7fe51216019699b1a9edf2af4f3cb7b6 (diff) | |
download | cmd2-git-fc41d86b275ba4bbd2dbd76c766dbc2abc138021.tar.gz |
Exceptions occurring in tab completion functions are now printed to stderr before returning control back to readline
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_completion.py | 18 |
1 files changed, 18 insertions, 0 deletions
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}') |