summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-03-13 17:39:37 -0400
committerGitHub <noreply@github.com>2018-03-13 17:39:37 -0400
commitfe15d07eaaf6501a1acf9e53a1b41dff3810caf8 (patch)
tree9d78a9b4ae804e38c2cdf05269996cda54310f66 /tests
parent60f27ef374135e7175a811838f47ab880a05c390 (diff)
parent082154fd0aa9c4d931da303c6ef57a98790b10fe (diff)
downloadcmd2-git-fe15d07eaaf6501a1acf9e53a1b41dff3810caf8.tar.gz
Merge branch 'master' into fix/submenu-require-shares
Diffstat (limited to 'tests')
-rw-r--r--tests/test_cmd2.py41
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