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

Function test_cmdfinalization_hook_keyboard_interrupt

tests/test_plugin.py:924–944  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

922
923
924def test_cmdfinalization_hook_keyboard_interrupt() -> None:
925 app = PluggedApp()
926 app.register_cmdfinalization_hook(app.cmdfinalization_hook_keyboard_interrupt)
927
928 # First make sure KeyboardInterrupt isn't raised unless told to
929 stop = app.onecmd_plus_hooks("say hello", raise_keyboard_interrupt=False)
930 assert not stop
931 assert app.called_cmdfinalization == 1
932
933 # Now enable raising the KeyboardInterrupt
934 app.reset_counters()
935 with pytest.raises(KeyboardInterrupt):
936 stop = app.onecmd_plus_hooks("say hello", raise_keyboard_interrupt=True)
937 assert not stop
938 assert app.called_cmdfinalization == 1
939
940 # Now make sure KeyboardInterrupt isn't raised if stop is already True
941 app.reset_counters()
942 stop = app.onecmd_plus_hooks("quit", raise_keyboard_interrupt=True)
943 assert stop
944 assert app.called_cmdfinalization == 1
945
946
947def test_cmdfinalization_hook_passthrough_exception() -> None:

Callers

nothing calls this directly

Calls 4

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