Skip to content

Commit 6fffb80

Browse files
committed
Fix tests.
1 parent abaf8dc commit 6fffb80

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

ipywidgets/widgets/tests/test_interaction.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ def test_list_str():
148148
d = dict(
149149
cls=widgets.Dropdown,
150150
value=first,
151+
options=tuple(values),
151152
_options_labels=tuple(values),
152153
_options_values=tuple(values),
153154
)
154-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
155155
check_widgets(c, lis=d)
156156

157157
def test_list_int():
@@ -162,10 +162,9 @@ def test_list_int():
162162
d = dict(
163163
cls=widgets.Dropdown,
164164
value=first,
165-
_options_labels=tuple(str(v) for v in values),
165+
options=tuple(values), _options_labels=tuple(str(v) for v in values),
166166
_options_values=tuple(values),
167167
)
168-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
169168
check_widgets(c, lis=d)
170169

171170
def test_list_tuple():
@@ -176,10 +175,10 @@ def test_list_tuple():
176175
d = dict(
177176
cls=widgets.Dropdown,
178177
value=first,
178+
options=tuple(values),
179179
_options_labels=("3", "1", "2"),
180180
_options_values=(300, 100, 200),
181181
)
182-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
183182
check_widgets(c, lis=d)
184183

185184
def test_list_tuple_invalid():
@@ -201,10 +200,10 @@ def test_dict():
201200
cls=widgets.Dropdown,
202201
description='d',
203202
value=next(iter(d.values())),
203+
options=d,
204204
_options_labels=tuple(d.keys()),
205205
_options_values=tuple(d.values()),
206206
)
207-
check['options'] = tuple(zip(check['_options_labels'], check['_options_values']))
208207
check_widget(w, **check)
209208

210209

@@ -222,7 +221,6 @@ def test_ordereddict():
222221
_options_labels=("3", "1", "2"),
223222
_options_values=(300, 100, 200),
224223
)
225-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
226224
check_widgets(c, lis=d)
227225

228226
def test_iterable():
@@ -236,10 +234,10 @@ def yield_values():
236234
d = dict(
237235
cls=widgets.Dropdown,
238236
value=first,
237+
options=(3, 1, 2),
239238
_options_labels=("3", "1", "2"),
240239
_options_values=(3, 1, 2),
241240
)
242-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
243241
check_widgets(c, lis=d)
244242

245243
def test_iterable_tuple():
@@ -250,10 +248,10 @@ def test_iterable_tuple():
250248
d = dict(
251249
cls=widgets.Dropdown,
252250
value=first,
251+
options=tuple(values),
253252
_options_labels=("3", "1", "2"),
254253
_options_values=(300, 100, 200),
255254
)
256-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
257255
check_widgets(c, lis=d)
258256

259257
def test_mapping():
@@ -278,10 +276,10 @@ def items(self):
278276
d = dict(
279277
cls=widgets.Dropdown,
280278
value=first,
279+
options=tuple(items),
281280
_options_labels=("3", "1", "2"),
282281
_options_values=(300, 100, 200),
283282
)
284-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
285283
check_widgets(c, lis=d)
286284

287285

@@ -327,12 +325,12 @@ def f(n, f=4.5, g=1, h=2, j='there'):
327325
),
328326
h=dict(
329327
cls=widgets.Dropdown,
330-
options=(('a', 1), ('b', 2)),
328+
options=OrderedDict([('a',1), ('b',2)]),
331329
value=2
332330
),
333331
j=dict(
334332
cls=widgets.Dropdown,
335-
options=(('hi', 'hi'), ('there', 'there')),
333+
options=('hi', 'there'),
336334
value='there'
337335
),
338336
)
@@ -350,12 +348,12 @@ def f(f='hi', h=5, j='other'):
350348
),
351349
h=dict(
352350
cls=widgets.Dropdown,
353-
options=(('a', 1),),
351+
options={'a': 1},
354352
value=1,
355353
),
356354
j=dict(
357355
cls=widgets.Dropdown,
358-
options=(('hi', 'hi'), ('there', 'there')),
356+
options=('hi', 'there'),
359357
value='hi',
360358
),
361359
)
@@ -682,7 +680,7 @@ def test_multiple_selection():
682680

683681
# basic multiple select
684682
w = smw(options=[(1, 1)], value=[1])
685-
check_widget(w, cls=smw, value=(1,), options=(('1', 1),))
683+
check_widget(w, cls=smw, value=(1,), options=((1, 1),))
686684

687685
# don't accept random other value
688686
with nt.assert_raises(TraitError):
@@ -691,20 +689,20 @@ def test_multiple_selection():
691689

692690
# change options, which resets value
693691
w.options = w.options + ((2, 2),)
694-
check_widget(w, options=(('1', 1), ('2',2)), value=())
692+
check_widget(w, options=((1, 1), (2,2)), value=())
695693

696694
# change value
697695
w.value = (1,2)
698696
check_widget(w, value=(1, 2))
699697

700698
# dict style
701699
w.options = {1: 1}
702-
check_widget(w, options=(('1', 1),))
700+
check_widget(w, options={1:1})
703701

704702
# updating
705703
with nt.assert_raises(TraitError):
706704
w.value = (2,)
707-
check_widget(w, options=(('1', 1),))
705+
check_widget(w, options={1:1})
708706

709707

710708
def test_interact_noinspect():

ipywidgets/widgets/widget_selection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class _Selection(DescriptionWidget, ValueWidget, CoreWidget):
7373
label = Unicode(None, help="Selected label", allow_none=True)
7474
index = Int(None, help="Selected index", allow_none=True).tag(sync=True)
7575

76-
options = Union([Tuple(), Dict()],
76+
options = Any((),
7777
help="""Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select.
7878
7979
The labels are the strings that will be displayed in the UI, representing the
@@ -196,7 +196,7 @@ class _MultipleSelection(DescriptionWidget, ValueWidget, CoreWidget):
196196
label = Tuple(help="Selected labels")
197197
index = Tuple(help="Selected indices").tag(sync=True)
198198

199-
options = Union([Tuple(), Dict()],
199+
options = Any((),
200200
help="""Iterable of values, (label, value) pairs, or a mapping of {label: value} pairs that the user can select.
201201
202202
The labels are the strings that will be displayed in the UI, representing the

0 commit comments

Comments
 (0)