Skip to content

Commit 587b1b6

Browse files
authored
Merge pull request #1513 from jasongrout/selectoptions
Preserve the value assigned to a selection .options attribute
2 parents c77da41 + d4e5549 commit 587b1b6

File tree

2 files changed

+96
-62
lines changed

2 files changed

+96
-62
lines changed

ipywidgets/widgets/tests/test_interaction.py

+15-16
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,10 @@ def test_list_int():
162162
d = dict(
163163
cls=widgets.Dropdown,
164164
value=first,
165+
options=tuple(values),
165166
_options_labels=tuple(str(v) for v in values),
166167
_options_values=tuple(values),
167168
)
168-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
169169
check_widgets(c, lis=d)
170170

171171
def test_list_tuple():
@@ -176,10 +176,10 @@ def test_list_tuple():
176176
d = dict(
177177
cls=widgets.Dropdown,
178178
value=first,
179+
options=tuple(values),
179180
_options_labels=("3", "1", "2"),
180181
_options_values=(300, 100, 200),
181182
)
182-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
183183
check_widgets(c, lis=d)
184184

185185
def test_list_tuple_invalid():
@@ -201,10 +201,10 @@ def test_dict():
201201
cls=widgets.Dropdown,
202202
description='d',
203203
value=next(iter(d.values())),
204+
options=d,
204205
_options_labels=tuple(d.keys()),
205206
_options_values=tuple(d.values()),
206207
)
207-
check['options'] = tuple(zip(check['_options_labels'], check['_options_values']))
208208
check_widget(w, **check)
209209

210210

@@ -222,7 +222,6 @@ def test_ordereddict():
222222
_options_labels=("3", "1", "2"),
223223
_options_values=(300, 100, 200),
224224
)
225-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
226225
check_widgets(c, lis=d)
227226

228227
def test_iterable():
@@ -236,10 +235,10 @@ def yield_values():
236235
d = dict(
237236
cls=widgets.Dropdown,
238237
value=first,
238+
options=(3, 1, 2),
239239
_options_labels=("3", "1", "2"),
240240
_options_values=(3, 1, 2),
241241
)
242-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
243242
check_widgets(c, lis=d)
244243

245244
def test_iterable_tuple():
@@ -250,10 +249,10 @@ def test_iterable_tuple():
250249
d = dict(
251250
cls=widgets.Dropdown,
252251
value=first,
252+
options=tuple(values),
253253
_options_labels=("3", "1", "2"),
254254
_options_values=(300, 100, 200),
255255
)
256-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
257256
check_widgets(c, lis=d)
258257

259258
def test_mapping():
@@ -278,10 +277,10 @@ def items(self):
278277
d = dict(
279278
cls=widgets.Dropdown,
280279
value=first,
280+
options=tuple(items),
281281
_options_labels=("3", "1", "2"),
282282
_options_values=(300, 100, 200),
283283
)
284-
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
285284
check_widgets(c, lis=d)
286285

287286

@@ -327,12 +326,12 @@ def f(n, f=4.5, g=1, h=2, j='there'):
327326
),
328327
h=dict(
329328
cls=widgets.Dropdown,
330-
options=(('a', 1), ('b', 2)),
329+
options=OrderedDict([('a',1), ('b',2)]),
331330
value=2
332331
),
333332
j=dict(
334333
cls=widgets.Dropdown,
335-
options=(('hi', 'hi'), ('there', 'there')),
334+
options=('hi', 'there'),
336335
value='there'
337336
),
338337
)
@@ -350,12 +349,12 @@ def f(f='hi', h=5, j='other'):
350349
),
351350
h=dict(
352351
cls=widgets.Dropdown,
353-
options=(('a', 1),),
352+
options={'a': 1},
354353
value=1,
355354
),
356355
j=dict(
357356
cls=widgets.Dropdown,
358-
options=(('hi', 'hi'), ('there', 'there')),
357+
options=('hi', 'there'),
359358
value='hi',
360359
),
361360
)
@@ -682,7 +681,7 @@ def test_multiple_selection():
682681

683682
# basic multiple select
684683
w = smw(options=[(1, 1)], value=[1])
685-
check_widget(w, cls=smw, value=(1,), options=(('1', 1),))
684+
check_widget(w, cls=smw, value=(1,), options=((1, 1),))
686685

687686
# don't accept random other value
688687
with nt.assert_raises(TraitError):
@@ -691,20 +690,20 @@ def test_multiple_selection():
691690

692691
# change options, which resets value
693692
w.options = w.options + ((2, 2),)
694-
check_widget(w, options=(('1', 1), ('2',2)), value=())
693+
check_widget(w, options=((1, 1), (2,2)), value=())
695694

696695
# change value
697696
w.value = (1,2)
698697
check_widget(w, value=(1, 2))
699698

700699
# dict style
701700
w.options = {1: 1}
702-
check_widget(w, options=(('1', 1),))
701+
check_widget(w, options={1:1})
703702

704703
# updating
705704
with nt.assert_raises(TraitError):
706705
w.value = (2,)
707-
check_widget(w, options=(('1', 1),))
706+
check_widget(w, options={1:1})
708707

709708

710709
def test_interact_noinspect():

0 commit comments

Comments
 (0)