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

Function test_postcmd_exception_first

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

Source from the content-addressed store, hash-verified

753
754
755def test_postcmd_exception_first(capsys) -> None:
756 app = PluggedApp()
757 app.register_postcmd_hook(app.postcmd_hook_exception)
758 stop = app.onecmd_plus_hooks("say hello")
759 out, err = capsys.readouterr()
760 assert not stop
761 assert out == "hello\n"
762 assert err
763 # since the registered hooks are called before postcmd(), if a registered
764 # hook throws an exception, postcmd() is never called. So we should have
765 # a count of one because we called the hook that raised the exception
766 assert app.called_postcmd == 1
767
768 # register another function but it shouldn't be called
769 app.reset_counters()
770 stop = app.register_postcmd_hook(app.postcmd_hook)
771 app.onecmd_plus_hooks("say hello")
772 out, err = capsys.readouterr()
773 assert not stop
774 assert out == "hello\n"
775 assert err
776 # the exception raised by the first hook should prevent the second
777 # hook from being called, and it also prevents postcmd() from being
778 # called
779 assert app.called_postcmd == 1
780
781
782def test_postcmd_exception_second(capsys) -> None:

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…