Skip to content

Commit 160b755

Browse files
committed
Add test to cover some uncovered exception handling code in cmd2.Cmd._complete_statement
1 parent 2052697 commit 160b755

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/test_cmd2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,3 +3378,18 @@ def test_bottom_toolbar(base_app):
33783378
base_app.completion_hint = 'hint '
33793379
base_app._bottom_toolbar()
33803380
mock_ansi.assert_called_with('hint')
3381+
3382+
3383+
def test_multiline_complete_statement_keyboard_interrupt(multiline_app, monkeypatch):
3384+
# Mock read_input to raise KeyboardInterrupt
3385+
read_input_mock = mock.MagicMock(name='read_input', side_effect=KeyboardInterrupt)
3386+
monkeypatch.setattr("cmd2.Cmd.read_input", read_input_mock)
3387+
3388+
# Mock poutput to verify ^C is printed
3389+
poutput_mock = mock.MagicMock(name='poutput')
3390+
monkeypatch.setattr(multiline_app, 'poutput', poutput_mock)
3391+
3392+
with pytest.raises(exceptions.EmptyStatement):
3393+
multiline_app._complete_statement('orate incomplete')
3394+
3395+
poutput_mock.assert_called_with('^C')

0 commit comments

Comments
 (0)