@@ -52,7 +52,7 @@ def check_widget(w, **d):
52
52
te = type (expected )
53
53
assert tv is te , "type({}.{}) = {!r} != {!r}" .format (w .__class__ .__name__ , attr , tv , te )
54
54
55
- def check_widgets (container , ** to_check ):
55
+ def check_widget_children (container , ** to_check ):
56
56
"""Check that widgets are created as expected"""
57
57
# build a widget dictionary, so it matches
58
58
widgets = {}
@@ -144,7 +144,7 @@ def test_list_str():
144
144
_options_labels = tuple (values ),
145
145
_options_values = tuple (values ),
146
146
)
147
- check_widgets (c , lis = d )
147
+ check_widget_children (c , lis = d )
148
148
149
149
def test_list_int ():
150
150
values = [3 , 1 , 2 ]
@@ -158,7 +158,7 @@ def test_list_int():
158
158
_options_labels = tuple (str (v ) for v in values ),
159
159
_options_values = tuple (values ),
160
160
)
161
- check_widgets (c , lis = d )
161
+ check_widget_children (c , lis = d )
162
162
163
163
def test_list_tuple ():
164
164
values = [(3 , 300 ), (1 , 100 ), (2 , 200 )]
@@ -172,7 +172,7 @@ def test_list_tuple():
172
172
_options_labels = ("3" , "1" , "2" ),
173
173
_options_values = (300 , 100 , 200 ),
174
174
)
175
- check_widgets (c , lis = d )
175
+ check_widget_children (c , lis = d )
176
176
177
177
def test_list_tuple_invalid ():
178
178
for bad in [
@@ -187,17 +187,33 @@ def test_dict():
187
187
dict (a = 5 ),
188
188
dict (a = 5 , b = 'b' , c = dict ),
189
189
]:
190
- with pytest .raises (TypeError ):
191
- c = interactive (f , d = d )
192
-
190
+ c = interactive (f , d = d )
191
+ w = c .children [0 ]
192
+ check = dict (
193
+ cls = widgets .Dropdown ,
194
+ description = 'd' ,
195
+ value = next (iter (d .values ())),
196
+ options = d ,
197
+ _options_labels = tuple (d .keys ()),
198
+ _options_values = tuple (d .values ()),
199
+ )
200
+ check_widget (w , ** check )
193
201
194
202
def test_ordereddict ():
195
203
from collections import OrderedDict
196
204
items = [(3 , 300 ), (1 , 100 ), (2 , 200 )]
197
205
first = items [0 ][1 ]
198
206
values = OrderedDict (items )
199
- with pytest .raises (TypeError ):
200
- c = interactive (f , lis = values )
207
+ c = interactive (f , lis = values )
208
+ assert len (c .children ) == 2
209
+ d = dict (
210
+ cls = widgets .Dropdown ,
211
+ value = first ,
212
+ options = values ,
213
+ _options_labels = ("3" , "1" , "2" ),
214
+ _options_values = (300 , 100 , 200 ),
215
+ )
216
+ check_widget_children (c , lis = d )
201
217
202
218
def test_iterable ():
203
219
def yield_values ():
@@ -214,7 +230,7 @@ def yield_values():
214
230
_options_labels = ("3" , "1" , "2" ),
215
231
_options_values = (3 , 1 , 2 ),
216
232
)
217
- check_widgets (c , lis = d )
233
+ check_widget_children (c , lis = d )
218
234
219
235
def test_iterable_tuple ():
220
236
values = [(3 , 300 ), (1 , 100 ), (2 , 200 )]
@@ -228,7 +244,7 @@ def test_iterable_tuple():
228
244
_options_labels = ("3" , "1" , "2" ),
229
245
_options_values = (300 , 100 , 200 ),
230
246
)
231
- check_widgets (c , lis = d )
247
+ check_widget_children (c , lis = d )
232
248
233
249
def test_mapping ():
234
250
from collections .abc import Mapping
@@ -257,7 +273,7 @@ def items(self):
257
273
_options_labels = ("3" , "1" , "2" ),
258
274
_options_values = (300 , 100 , 200 ),
259
275
)
260
- check_widgets (c , lis = d )
276
+ check_widget_children (c , lis = d )
261
277
262
278
def test_decorator_kwarg (clear_display ):
263
279
with patch .object (interaction , 'display' , record_display ):
@@ -566,15 +582,14 @@ def test_multiple_selection():
566
582
check_widget (w , value = (1 , 2 ))
567
583
568
584
# dict style
569
- with pytest . raises ( TypeError ):
570
- w = smw ( options = {1 : 1 })
585
+ w . options = { 1 : 1 }
586
+ check_widget ( w , options = {1 :1 })
571
587
572
588
# updating
573
589
w .options = (1 ,)
574
590
with pytest .raises (TraitError ):
575
591
w .value = (2 ,)
576
- check_widget (w , options = (1 ,))
577
-
592
+ check_widget (w , options = (1 ,) )
578
593
579
594
def test_interact_noinspect ():
580
595
a = 'hello'
0 commit comments