Skip to content

Commit

Permalink
Add Separator: ipynb compatibility
Browse files Browse the repository at this point in the history
Revert the behaviour change of ipynb duplicate items
  • Loading branch information
qin-yu committed Mar 18, 2024
1 parent 2e7b7b3 commit a3b306e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/magicgui/backends/_ipynb/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ def _mgui_get_choices(self) -> tuple[tuple[str, Any]]:
def _mgui_set_choices(self, choices: Iterable[tuple[str, Any]]) -> None:
"""Set available choices."""
options = [item for item in choices if item[1] is not Separator]
options = list(dict(options).items()) # remove duplicate names, last data used
self._ipywidget.options = options

def _mgui_del_choice(self, choice_name: str) -> None:
Expand Down
12 changes: 8 additions & 4 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,14 +1098,18 @@ def get_all_itemdata(combo_box):
assert get_all_itemdata(widget_with_separator.a.native) == a
assert get_all_itemdata(widget_with_separator.b.native) == b2

# Choices only returns unique, non-separator items
assert widget_with_separator.a.choices == (1, 2, 4, 6, 7, 9, 11, 12, 14)
assert widget_with_separator.b.choices == (1, 2, 4, 6, 7, 9)

if backend == "ipynb":
# Separator singletons themselves are used as separator item data
assert widget_with_separator.a.options['choices'] == a
assert widget_with_separator.b.options['choices'] == b # non-separators are not unique
assert widget_with_separator.b.options['choices'] == b # items are not unique

# Choices only returns unique, non-separator items
assert widget_with_separator.a.choices == (1, 2, 4, 6, 7, 9, 11, 12, 14)
assert widget_with_separator.b.choices == (1, 2, 4, 6, 7, 9)
# Choices only returns duplicated, non-separator items
assert widget_with_separator.a.choices == (1, 2, 4, 6, 7, 9, 11, 12, 14)
assert widget_with_separator.b.choices == (1, 2, 4, 6, 7, 9, 6, 7, 9)


def test_float_slider_readout():
Expand Down

0 comments on commit a3b306e

Please sign in to comment.