(outsim_app, monkeypatch)
| 1807 | |
| 1808 | |
| 1809 | def test_select_indexable_no_len(outsim_app, monkeypatch) -> None: |
| 1810 | # Test that an object with __getitem__ but no __len__ works. |
| 1811 | # This covers the except (IndexError, TypeError) block in select() |
| 1812 | class IndexableNoLen: |
| 1813 | def __getitem__(self, item: int) -> str: |
| 1814 | if item == 0: |
| 1815 | return "value" |
| 1816 | raise IndexError |
| 1817 | |
| 1818 | # Mock read_input to return '1' |
| 1819 | read_input_mock = mock.MagicMock(name="read_input", return_value="1") |
| 1820 | monkeypatch.setattr("cmd2.Cmd.read_input", read_input_mock) |
| 1821 | |
| 1822 | options = [IndexableNoLen()] |
| 1823 | result = outsim_app.select(options, "Choice? ") |
| 1824 | assert result == "value" |
| 1825 | |
| 1826 | out = outsim_app.stdout.getvalue() |
| 1827 | assert "1. value" in out |
| 1828 | |
| 1829 | |
| 1830 | class HelpNoDocstringApp(cmd2.Cmd): |
nothing calls this directly
no test coverage detected
searching dependent graphs…