summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-04-28 15:07:26 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-04-30 13:12:23 -0400
commit37d415b4bbfd6efd383a20062df68f627451ccf7 (patch)
treef3b12ec9739e276fec87f3224c6f0aafbbc291df /tests
parent329a2e23bcc65e214e9775bbe995946c407c9629 (diff)
downloadcmd2-git-37d415b4bbfd6efd383a20062df68f627451ccf7.tar.gz
Stopping a shell command with Ctrl-C now raises a KeyboardInterrupt to support stopping a text script which ran the shell command.
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')
-rwxr-xr-xtests/test_cmd2.py17
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)