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

Function test_precmd_hook_emptystatement_second

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

Source from the content-addressed store, hash-verified

650
651
652def test_precmd_hook_emptystatement_second(capsys) -> None:
653 app = PluggedApp()
654 app.register_precmd_hook(app.precmd_hook)
655 stop = app.onecmd_plus_hooks("say hello")
656 out, err = capsys.readouterr()
657 assert not stop
658 assert out == "hello\n"
659 assert not err
660 # with one hook registered, we should get precmd() and the hook
661 assert app.called_precmd == 2
662
663 # register another function and make sure it gets called
664 app.reset_counters()
665 app.register_precmd_hook(app.precmd_hook_emptystatement)
666 stop = app.onecmd_plus_hooks("say hello")
667 out, err = capsys.readouterr()
668 assert not stop
669 assert not out
670 assert not err
671 # since the registered hooks are called before precmd(), if a registered
672 # hook throws an exception, precmd() is never called
673 assert app.called_precmd == 2
674
675 # register a third function which shouldn't be called
676 app.reset_counters()
677 app.register_precmd_hook(app.precmd_hook)
678 stop = app.onecmd_plus_hooks("say hello")
679 out, err = capsys.readouterr()
680 assert not stop
681 assert not out
682 assert not err
683 # the exception raised by the second hook should prevent the third
684 # hook from being called. since the registered hooks are called before precmd(),
685 # if a registered hook throws an exception, precmd() is never called
686 assert app.called_precmd == 2
687
688
689###

Callers

nothing calls this directly

Calls 4

PluggedAppClass · 0.85
register_precmd_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…