diff options
author | Mark Lalor <markwlalor@gmail.com> | 2018-03-12 21:18:47 -0400 |
---|---|---|
committer | Mark Lalor <markwlalor@gmail.com> | 2018-03-12 23:58:07 -0400 |
commit | 58346cd89497d459655306d19b331d93fc159711 (patch) | |
tree | 4346a0225420b703fe2e56e52e6a8423a1fab0f4 /tests/test_cmd2.py | |
parent | ece4ab4e8c02421efd467eebaa6b36d8b7dead00 (diff) | |
download | cmd2-git-58346cd89497d459655306d19b331d93fc159711.tar.gz |
Added option to cancel the current line on keyboard interrupt.
Diffstat (limited to 'tests/test_cmd2.py')
-rw-r--r-- | tests/test_cmd2.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 92f21757..e22212d4 100644 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -900,6 +900,47 @@ def test_precmd_hook_failure(hook_failure): assert out == True +class SayApp(cmd2.Cmd): + def __init__(self, *args, **kwargs): + # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x + cmd2.Cmd.__init__(self, *args, **kwargs) + + def do_say(self, arg): + self.poutput(arg) + +@pytest.fixture +def say_app(): + app = SayApp() + app.stdout = StdOut() + return app + +def test_interrupt_quit(say_app): + # Mock out the input call so we don't actually wait for a user's response on stdin + m = mock.MagicMock(name='input') + m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof'] + sm.input = m + + say_app.cmdloop() + + # And verify the expected output to stdout + out = say_app.stdout.buffer + assert out == 'hello\n' + +def test_interrupt_noquit(say_app): + say_app.quit_on_sigint = False + + # Mock out the input call so we don't actually wait for a user's response on stdin + m = mock.MagicMock(name='input') + m.side_effect = ['say hello', KeyboardInterrupt(), 'say goodbye', 'eof'] + sm.input = m + + say_app.cmdloop() + + # And verify the expected output to stdout + out = say_app.stdout.buffer + assert out == 'hello\n^C\ngoodbye\n' + + class ShellApp(cmd2.Cmd): def __init__(self, *args, **kwargs): # Need to use this older form of invoking super class constructor to support Python 2.x and Python 3.x |