Skip to content

Commit 78734fc

Browse files
committed
Fix tests#
This essentially does a partial reversion of 9db179b and 28877f9 (#2679)
1 parent 31fc0a9 commit 78734fc

File tree

2 files changed

+31
-14
lines changed

2 files changed

+31
-14
lines changed

python/ipywidgets/ipywidgets/widgets/tests/test_interaction.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,33 @@ def test_dict():
187187
dict(a=5),
188188
dict(a=5, b='b', c=dict),
189189
]:
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)
193201

194202
def test_ordereddict():
195203
from collections import OrderedDict
196204
items = [(3, 300), (1, 100), (2, 200)]
197205
first = items[0][1]
198206
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_widgets(c, lis=d)
201217

202218
def test_iterable():
203219
def yield_values():
@@ -566,15 +582,14 @@ def test_multiple_selection():
566582
check_widget(w, value=(1, 2))
567583

568584
# 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})
571587

572588
# updating
573589
w.options = (1,)
574590
with pytest.raises(TraitError):
575591
w.value = (2,)
576-
check_widget(w, options=(1,))
577-
592+
check_widget(w, options=(1,) )
578593

579594
def test_interact_noinspect():
580595
a = 'hello'

python/ipywidgets/ipywidgets/widgets/tests/test_widget_selection.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class TestDropdown(TestCase):
1616
def test_construction(self):
1717
Dropdown()
1818

19-
def test_raise_mapping_options(self):
20-
with pytest.raises(TypeError):
21-
Dropdown(options={'One': 1, 'Two': 2, 'Three': 3})
19+
def test_dict_mapping_options(self):
20+
d = Dropdown(options={'One': 1, 'Two': 2, 'Three': 3})
21+
assert d.get_state('_options_labels') == {'_options_labels': ('One', 'Two', 'Three')}
2222

2323
def test_setting_options_from_list(self):
2424
d = Dropdown()
@@ -37,8 +37,10 @@ def test_setting_options_from_list_tuples(self):
3737
def test_setting_options_from_dict(self):
3838
d = Dropdown()
3939
assert d.options == ()
40-
with pytest.raises(TypeError):
41-
d.options = {'One': 1}
40+
d.options = {'One': 1, 'Two': 2, 'Three': 3}
41+
assert d.get_state('_options_labels') == {'_options_labels': ('One', 'Two', 'Three')}
42+
43+
4244

4345

4446
class TestSelectionSlider(TestCase):

0 commit comments

Comments
 (0)