summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-23 11:30:38 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-23 11:30:54 -0400
commit3a4893ec32c6d38cad344667fead93e2eed8dc88 (patch)
tree65d6073d92769ff3f4e3fe023d47cafad6bacf73 /tests
parentfabe4cd01b339d628ffd0b8d9b202a4a41555b8b (diff)
downloadcmd2-git-3a4893ec32c6d38cad344667fead93e2eed8dc88.tar.gz
onecmd_plus_hooks() now sets self.exit_code when a SystemExit handled
Diffstat (limited to 'tests')
-rwxr-xr-xtests/test_cmd2.py5
-rw-r--r--tests/test_plugin.py3
2 files changed, 6 insertions, 2 deletions
diff --git a/tests/test_cmd2.py b/tests/test_cmd2.py
index 91815d50..e369a9cf 100755
--- a/tests/test_cmd2.py
+++ b/tests/test_cmd2.py
@@ -537,13 +537,16 @@ def test_system_exit_in_command(base_app, capsys):
"""Test raising SystemExit in a command"""
import types
+ exit_code = 5
+
def do_system_exit(self, _):
- raise SystemExit
+ raise SystemExit(exit_code)
setattr(base_app, 'do_system_exit', types.MethodType(do_system_exit, base_app))
stop = base_app.onecmd_plus_hooks('system_exit')
assert stop
+ assert base_app.exit_code == exit_code
def test_passthrough_exception_in_command(base_app):
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 1e12d655..61b140ab 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -229,7 +229,7 @@ class Plugin:
) -> cmd2.plugin.CommandFinalizationData:
"""A command finalization hook which raises a SystemExit"""
self.called_cmdfinalization += 1
- raise SystemExit
+ raise SystemExit(5)
def cmdfinalization_hook_keyboard_interrupt(
self, data: cmd2.plugin.CommandFinalizationData
@@ -930,6 +930,7 @@ def test_cmdfinalization_hook_system_exit():
stop = app.onecmd_plus_hooks('say hello')
assert stop
assert app.called_cmdfinalization == 1
+ assert app.exit_code == 5
def test_cmdfinalization_hook_keyboard_interrupt():