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

Function test_runcmds_plus_hooks_ctrl_c

tests/test_cmd2.py:525–546  ·  view source on GitHub ↗

Test Ctrl-C while in runcmds_plus_hooks

(base_app, capsys)

Source from the content-addressed store, hash-verified

523
524
525def test_runcmds_plus_hooks_ctrl_c(base_app, capsys) -> None:
526 """Test Ctrl-C while in runcmds_plus_hooks"""
527 import types
528
529 def do_keyboard_interrupt(self, _) -> NoReturn:
530 raise KeyboardInterrupt("Interrupting this command")
531
532 base_app.do_keyboard_interrupt = types.MethodType(do_keyboard_interrupt, base_app)
533
534 # Default behavior is to not stop runcmds_plus_hooks() on Ctrl-C
535 base_app.history.clear()
536 base_app.runcmds_plus_hooks(["help", "keyboard_interrupt", "shortcuts"])
537 _out, err = capsys.readouterr()
538 assert not err
539 assert len(base_app.history) == 3
540
541 # Ctrl-C should stop runcmds_plus_hooks() in this case
542 base_app.history.clear()
543 base_app.runcmds_plus_hooks(["help", "keyboard_interrupt", "shortcuts"], stop_on_keyboard_interrupt=True)
544 _out, err = capsys.readouterr()
545 assert err.startswith("Interrupting this command")
546 assert len(base_app.history) == 2
547
548
549def test_relative_run_script(base_app, request) -> None:

Callers

nothing calls this directly

Calls 2

runcmds_plus_hooksMethod · 0.80
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…