(capsys)
| 595 | |
| 596 | |
| 597 | def 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 | |
| 626 | def test_precmd_hook_emptystatement_first(capsys) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…