Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let select_choices select a single item again #106

Merged
merged 1 commit into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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