Skip to content

Commit 9edd091

Browse files
committed
Added Ctrl-d test.
1 parent 484930c commit 9edd091

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/test_cmd2.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,6 +1191,18 @@ def test_ctrl_c_at_prompt(say_app, monkeypatch) -> None:
11911191
assert out == 'hello\n^C\ngoodbye\n'
11921192

11931193

1194+
def test_ctrl_d_at_prompt(say_app, monkeypatch) -> None:
1195+
read_command_mock = mock.MagicMock(name='_read_command_line')
1196+
read_command_mock.side_effect = ['say hello', EOFError()]
1197+
monkeypatch.setattr("cmd2.Cmd._read_command_line", read_command_mock)
1198+
1199+
say_app.cmdloop()
1200+
1201+
# And verify the expected output to stdout
1202+
out = say_app.stdout.getvalue()
1203+
assert out == 'hello\n\n'
1204+
1205+
11941206
class ShellApp(cmd2.Cmd):
11951207
def __init__(self, *args, **kwargs) -> None:
11961208
super().__init__(*args, **kwargs)

0 commit comments

Comments
 (0)