Skip to content

Commit

Permalink
Merge pull request #106 from Lexanius/main
Browse files Browse the repository at this point in the history
Let select_choices select a single item again
  • Loading branch information
gdubicki authored Apr 6, 2024
2 parents 311e794 + bd86193 commit 49056a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cli_ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,11 @@ def select_choices(
continue

try:
res = list(itemgetter(*index)(choices))
res = (
list(itemgetter(*index)(choices))
if len(index) > 1
else [itemgetter(*index)(choices)]
)
except Exception:
info("Please enter valid selection number(s)")
continue
Expand Down
7 changes: 7 additions & 0 deletions cli_ui/tests/test_cli_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ def func_desc(fruit: Fruit) -> str:
assert m.call_count == 3


def test_select_choices_single_select() -> None:
with mock.patch("builtins.input") as m:
m.side_effect = ["1"]
res = cli_ui.select_choices("Select a animal", choices=["cat", "dog", "cow"])
assert res == ["cat"]


def test_select_choices_empty_input() -> None:
with mock.patch("builtins.input") as m:
m.side_effect = [""]
Expand Down

0 comments on commit 49056a8

Please sign in to comment.