Test Ctrl-C while in runcmds_plus_hooks
(base_app, capsys)
| 523 | |
| 524 | |
| 525 | def 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 | |
| 549 | def test_relative_run_script(base_app, request) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…