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

Function test_precmd_hook

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

Source from the content-addressed store, hash-verified

595
596
597def test_precmd_hook(capsys) -> None:
598 app = PluggedApp()
599 app.onecmd_plus_hooks("say hello")
600 out, err = capsys.readouterr()
601 assert out == "hello\n"
602 assert not err
603 # without registering any hooks, precmd() should be called
604 assert app.called_precmd == 1
605
606 app.reset_counters()
607 app.register_precmd_hook(app.precmd_hook)
608 app.onecmd_plus_hooks("say hello")
609 out, err = capsys.readouterr()
610 assert out == "hello\n"
611 assert not err
612 # with one hook registered, we should get precmd() and the hook
613 assert app.called_precmd == 2
614
615 # register the function again, so it should be called twice
616 app.reset_counters()
617 app.register_precmd_hook(app.precmd_hook)
618 app.onecmd_plus_hooks("say hello")
619 out, err = capsys.readouterr()
620 assert out == "hello\n"
621 assert not err
622 # with two hooks registered, we should get precmd() and both hooks
623 assert app.called_precmd == 3
624
625
626def test_precmd_hook_emptystatement_first(capsys) -> None:

Callers

nothing calls this directly

Calls 4

PluggedAppClass · 0.85
onecmd_plus_hooksMethod · 0.80
reset_countersMethod · 0.80
register_precmd_hookMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…