@@ -1232,6 +1232,17 @@ def test_select_eof(select_app, monkeypatch):
12321232 read_input_mock .assert_has_calls (calls )
12331233 assert read_input_mock .call_count == 2
12341234
1235+ def test_select_ctrl_c (outsim_app , monkeypatch , capsys ):
1236+ # Ctrl-C during select prints ^C and raises a KeyboardInterrupt
1237+ read_input_mock = mock .MagicMock (name = 'read_input' , side_effect = KeyboardInterrupt )
1238+ monkeypatch .setattr ("cmd2.Cmd.read_input" , read_input_mock )
1239+
1240+ with pytest .raises (KeyboardInterrupt ):
1241+ outsim_app .select ([('Guitar' , 'Electric Guitar' ), ('Drums' ,)], 'Instrument? ' )
1242+
1243+ out = outsim_app .stdout .getvalue ()
1244+ assert out .rstrip ().endswith ('^C' )
1245+
12351246class HelpNoDocstringApp (cmd2 .Cmd ):
12361247 greet_parser = argparse .ArgumentParser ()
12371248 greet_parser .add_argument ('-s' , '--shout' , action = "store_true" , help = "N00B EMULATION MODE" )
@@ -1504,6 +1515,13 @@ def make_app(isatty: bool, empty_input: bool = False):
15041515 assert line == 'eof'
15051516 assert not out
15061517
1518+ def test_read_command_line_eof (base_app , monkeypatch ):
1519+ read_input_mock = mock .MagicMock (name = 'read_input' , side_effect = EOFError )
1520+ monkeypatch .setattr ("cmd2.Cmd.read_input" , read_input_mock )
1521+
1522+ line = base_app ._read_command_line ("Prompt> " )
1523+ assert line == 'eof'
1524+
15071525def test_poutput_string (outsim_app ):
15081526 msg = 'This is a test'
15091527 outsim_app .poutput (msg )
0 commit comments