diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-04-28 15:07:26 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2021-04-30 11:24:32 -0400 |
commit | b54f7116eeed7926f54ed50592ec5fdeb01a4c25 (patch) | |
tree | eaa0baa52e2756af740c2b2ce995708df54817c7 /tests/test_cmd2.py | |
parent | 9dc01864df378ae128d0292e7f18e6b5e81765c4 (diff) | |
download | cmd2-git-ctrl-c.tar.gz |
Stopping a shell command with Ctrl-C now raises a KeyboardInterrupt to support stopping a text script which ran the shell command.ctrl-c
On POSIX systems, shell commands and processes being piped to are now run in the user's preferred shell instead of /bin/sh.
Diffstat (limited to 'tests/test_cmd2.py')
-rwxr-xr-x | tests/test_cmd2.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py index 2ff70055..64237f09 100755 --- a/tests/test_cmd2.py +++ b/tests/test_cmd2.py @@ -7,6 +7,7 @@ import argparse import builtins import io import os +import signal import sys import tempfile from code import ( @@ -902,6 +903,22 @@ def test_stty_sane(base_app, monkeypatch): m.assert_called_once_with(['stty', 'sane']) +def test_sigint_handler(base_app): + # No KeyboardInterrupt should be raised when using sigint_protection + with base_app.sigint_protection: + base_app.sigint_handler(signal.SIGINT, 1) + + # Without sigint_protection, a KeyboardInterrupt is raised + with pytest.raises(KeyboardInterrupt): + base_app.sigint_handler(signal.SIGINT, 1) + + +def test_raise_keyboard_interrupt(base_app): + with pytest.raises(KeyboardInterrupt) as excinfo: + base_app._raise_keyboard_interrupt() + assert 'Got a keyboard interrupt' in str(excinfo.value) + + class HookFailureApp(cmd2.Cmd): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) |