Skip to content

Commit bd86193

Browse files
committed
Update __init__.py
- Add check to select single values from choices - Add test for single value selection
1 parent e1d7e6c commit bd86193

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

cli_ui/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,11 @@ def select_choices(
591591
continue
592592

593593
try:
594-
res = list(itemgetter(*index)(choices))
594+
res = (
595+
list(itemgetter(*index)(choices))
596+
if len(index) > 1
597+
else [itemgetter(*index)(choices)]
598+
)
595599
except Exception:
596600
info("Please enter valid selection number(s)")
597601
continue

cli_ui/tests/test_cli_ui.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,13 @@ def func_desc(fruit: Fruit) -> str:
345345
assert m.call_count == 3
346346

347347

348+
def test_select_choices_single_select() -> None:
349+
with mock.patch("builtins.input") as m:
350+
m.side_effect = ["1"]
351+
res = cli_ui.select_choices("Select a animal", choices=["cat", "dog", "cow"])
352+
assert res == ["cat"]
353+
354+
348355
def test_select_choices_empty_input() -> None:
349356
with mock.patch("builtins.input") as m:
350357
m.side_effect = [""]

0 commit comments

Comments
 (0)