MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_postcmd_exception_second

Function test_postcmd_exception_second

tests/test_plugin.py:782–805  ·  view source on GitHub ↗
(capsys)

Source from the content-addressed store, hash-verified

780
781
782def test_postcmd_exception_second(capsys) -> None:
783 app = PluggedApp()
784 app.register_postcmd_hook(app.postcmd_hook)
785 stop = app.onecmd_plus_hooks("say hello")
786 out, err = capsys.readouterr()
787 assert not stop
788 assert out == "hello\n"
789 assert not err
790 # with one hook registered, we should get the hook and postcmd()
791 assert app.called_postcmd == 2
792
793 # register another function which should be called
794 app.reset_counters()
795 stop = app.register_postcmd_hook(app.postcmd_hook_exception)
796 app.onecmd_plus_hooks("say hello")
797 out, err = capsys.readouterr()
798 assert not stop
799 assert out == "hello\n"
800 assert err
801 # the exception raised by the first hook should prevent the second
802 # hook from being called, and it also prevents postcmd() from being
803 # called. So we have the first hook, and the second hook, which raised
804 # the exception
805 assert app.called_postcmd == 2
806
807
808##

Callers

nothing calls this directly

Calls 4

PluggedAppClass · 0.85
register_postcmd_hookMethod · 0.80
onecmd_plus_hooksMethod · 0.80
reset_countersMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…