MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / test_select_indexable_no_len

Function test_select_indexable_no_len

tests/test_cmd2.py:1809–1827  ·  view source on GitHub ↗
(outsim_app, monkeypatch)

Source from the content-addressed store, hash-verified

1807
1808
1809def 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
1830class HelpNoDocstringApp(cmd2.Cmd):

Callers

nothing calls this directly

Calls 3

IndexableNoLenClass · 0.85
selectMethod · 0.80
getvalueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…