diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-05-07 14:32:29 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-05-07 14:32:29 -0400 |
commit | c50db52da00f4e544a6b3a19ee5b0f54e8503914 (patch) | |
tree | f0557888a6bd3afe9915ce51f6eeb9da3e9a15ba /tests | |
parent | d4653e6fccf0bc15d04075110769c11befb22819 (diff) | |
download | cmd2-git-c50db52da00f4e544a6b3a19ee5b0f54e8503914.tar.gz |
Added SkipPostcommandHooks exception and made Cmd2ArgparseError inherit from it.
Both exception classes have been added to the public API.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_plugin.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 132361a6..f7eb7e39 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -256,6 +256,10 @@ class PluggedApp(Plugin, cmd2.Cmd): """Repeat back the arguments""" self.poutput(statement) + def do_skip_postcmd_hooks(self, _): + self.poutput("In do_skip_postcmd_hooks") + raise exceptions.SkipPostcommandHooks + parser = Cmd2ArgumentParser(description="Test parser") parser.add_argument("my_arg", help="some help text") @@ -847,6 +851,17 @@ def test_cmdfinalization_hook_exception(capsys): assert err assert app.called_cmdfinalization == 1 +def test_skip_postcmd_hooks(capsys): + app = PluggedApp() + app.register_postcmd_hook(app.postcmd_hook) + app.register_cmdfinalization_hook(app.cmdfinalization_hook) + + # Cause a SkipPostcommandHooks exception and verify no postcmd stuff runs but cmdfinalization_hook still does + app.onecmd_plus_hooks('skip_postcmd_hooks') + out, err = capsys.readouterr() + assert "In do_skip_postcmd_hooks" in out + assert app.called_postcmd == 0 + assert app.called_cmdfinalization == 1 def test_cmd2_argparse_exception(capsys): """ |