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

Function test_precmd_hook_emptystatement_first

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

Source from the content-addressed store, hash-verified

624
625
626def test_precmd_hook_emptystatement_first(capsys) -> None:
627 app = PluggedApp()
628 app.register_precmd_hook(app.precmd_hook_emptystatement)
629 stop = app.onecmd_plus_hooks("say hello")
630 out, err = capsys.readouterr()
631 assert not stop
632 assert not out
633 assert not err
634 # since the registered hooks are called before precmd(), if a registered
635 # hook throws an exception, precmd() is never called
636 assert app.called_precmd == 1
637
638 # register another function but it shouldn't be called
639 app.reset_counters()
640 stop = app.register_precmd_hook(app.precmd_hook)
641 app.onecmd_plus_hooks("say hello")
642 out, err = capsys.readouterr()
643 assert not stop
644 assert not out
645 assert not err
646 # the exception raised by the first hook should prevent the second
647 # hook from being called, and it also prevents precmd() from being
648 # called
649 assert app.called_precmd == 1
650
651
652def test_precmd_hook_emptystatement_second(capsys) -> None:

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…