(capsys)
| 753 | |
| 754 | |
| 755 | def test_postcmd_exception_first(capsys) -> None: |
| 756 | app = PluggedApp() |
| 757 | app.register_postcmd_hook(app.postcmd_hook_exception) |
| 758 | stop = app.onecmd_plus_hooks("say hello") |
| 759 | out, err = capsys.readouterr() |
| 760 | assert not stop |
| 761 | assert out == "hello\n" |
| 762 | assert err |
| 763 | # since the registered hooks are called before postcmd(), if a registered |
| 764 | # hook throws an exception, postcmd() is never called. So we should have |
| 765 | # a count of one because we called the hook that raised the exception |
| 766 | assert app.called_postcmd == 1 |
| 767 | |
| 768 | # register another function but it shouldn't be called |
| 769 | app.reset_counters() |
| 770 | stop = app.register_postcmd_hook(app.postcmd_hook) |
| 771 | app.onecmd_plus_hooks("say hello") |
| 772 | out, err = capsys.readouterr() |
| 773 | assert not stop |
| 774 | assert out == "hello\n" |
| 775 | assert err |
| 776 | # the exception raised by the first hook should prevent the second |
| 777 | # hook from being called, and it also prevents postcmd() from being |
| 778 | # called |
| 779 | assert app.called_postcmd == 1 |
| 780 | |
| 781 | |
| 782 | def test_postcmd_exception_second(capsys) -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…