summaryrefslogtreecommitdiff
path: root/tests/test_plugin.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 13:54:34 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2021-03-02 13:54:34 -0500
commit3f0f277c412fb4adf27710c1dcb10ce82dacd604 (patch)
tree3589fda03daebcc5aed0dbc07841563b37ba3ad2 /tests/test_plugin.py
parent6b00402e82d09b4d8e0ed42662555b78edb47585 (diff)
parent4da77c4cb0756191ee13f3c0003a2b04863b73ae (diff)
downloadcmd2-git-3f0f277c412fb4adf27710c1dcb10ce82dacd604.tar.gz
Merge branch 'master' into history_fix
Diffstat (limited to 'tests/test_plugin.py')
-rw-r--r--tests/test_plugin.py22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 97c046a2..1e12d655 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -238,6 +238,14 @@ class Plugin:
self.called_cmdfinalization += 1
raise KeyboardInterrupt
+ def cmdfinalization_hook_passthrough_exception(
+ self, data: cmd2.plugin.CommandFinalizationData
+ ) -> cmd2.plugin.CommandFinalizationData:
+ """A command finalization hook which raises a PassThroughException"""
+ self.called_cmdfinalization += 1
+ wrapped_ex = OSError("Pass me up")
+ raise exceptions.PassThroughException(wrapped_ex=wrapped_ex)
+
def cmdfinalization_hook_not_enough_parameters(self) -> plugin.CommandFinalizationData:
"""A command finalization hook with no parameters."""
pass
@@ -916,7 +924,7 @@ def test_cmdfinalization_hook_exception(capsys):
assert app.called_cmdfinalization == 1
-def test_cmdfinalization_hook_system_exit(capsys):
+def test_cmdfinalization_hook_system_exit():
app = PluggedApp()
app.register_cmdfinalization_hook(app.cmdfinalization_hook_system_exit)
stop = app.onecmd_plus_hooks('say hello')
@@ -924,7 +932,7 @@ def test_cmdfinalization_hook_system_exit(capsys):
assert app.called_cmdfinalization == 1
-def test_cmdfinalization_hook_keyboard_interrupt(capsys):
+def test_cmdfinalization_hook_keyboard_interrupt():
app = PluggedApp()
app.register_cmdfinalization_hook(app.cmdfinalization_hook_keyboard_interrupt)
@@ -947,6 +955,16 @@ def test_cmdfinalization_hook_keyboard_interrupt(capsys):
assert app.called_cmdfinalization == 1
+def test_cmdfinalization_hook_passthrough_exception():
+ app = PluggedApp()
+ app.register_cmdfinalization_hook(app.cmdfinalization_hook_passthrough_exception)
+
+ with pytest.raises(OSError) as excinfo:
+ app.onecmd_plus_hooks('say hello')
+ assert 'Pass me up' in str(excinfo.value)
+ assert app.called_cmdfinalization == 1
+
+
def test_skip_postcmd_hooks(capsys):
app = PluggedApp()
app.register_postcmd_hook(app.postcmd_hook)