Skip to content

Commit 73c8e6d

Browse files
committed
Updating unit tests
1 parent 697ff1a commit 73c8e6d

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/test_cmd2.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
12351246
class 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+
15071525
def test_poutput_string(outsim_app):
15081526
msg = 'This is a test'
15091527
outsim_app.poutput(msg)

0 commit comments

Comments
 (0)