| 1765 | |
| 1766 | |
| 1767 | def test_select_choice_tty_ctrl_c(outsim_app, monkeypatch) -> None: |
| 1768 | # Mock choice to raise KeyboardInterrupt |
| 1769 | choice_mock = mock.MagicMock(name="choice", side_effect=KeyboardInterrupt) |
| 1770 | monkeypatch.setattr("cmd2.cmd2.choice", choice_mock) |
| 1771 | |
| 1772 | prompt = "Sauce? " |
| 1773 | options = ["sweet", "salty"] |
| 1774 | |
| 1775 | # Mock isatty to be True for both stdin and stdout |
| 1776 | with create_pipe_input() as pipe_input: |
| 1777 | outsim_app.main_session = PromptSession( |
| 1778 | input=pipe_input, |
| 1779 | output=DummyOutput(), |
| 1780 | ) |
| 1781 | |
| 1782 | with pytest.raises(KeyboardInterrupt): |
| 1783 | outsim_app.select(options, prompt) |
| 1784 | |
| 1785 | out = outsim_app.stdout.getvalue() |
| 1786 | assert out.rstrip().endswith("^C") |
| 1787 | |
| 1788 | |
| 1789 | def test_select_uneven_tuples_labels(outsim_app, monkeypatch) -> None: |