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

Function test_postcmd

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

Source from the content-addressed store, hash-verified

724
725
726def test_postcmd(capsys) -> None:
727 app = PluggedApp()
728 app.onecmd_plus_hooks("say hello")
729 out, err = capsys.readouterr()
730 assert out == "hello\n"
731 assert not err
732 # without registering any hooks, postcmd() should be called
733 assert app.called_postcmd == 1
734
735 app.reset_counters()
736 app.register_postcmd_hook(app.postcmd_hook)
737 app.onecmd_plus_hooks("say hello")
738 out, err = capsys.readouterr()
739 assert out == "hello\n"
740 assert not err
741 # with one hook registered, we should get precmd() and the hook
742 assert app.called_postcmd == 2
743
744 # register the function again, so it should be called twice
745 app.reset_counters()
746 app.register_postcmd_hook(app.postcmd_hook)
747 app.onecmd_plus_hooks("say hello")
748 out, err = capsys.readouterr()
749 assert out == "hello\n"
750 assert not err
751 # with two hooks registered, we should get precmd() and both hooks
752 assert app.called_postcmd == 3
753
754
755def test_postcmd_exception_first(capsys) -> None:

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…