Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongrout committed Jul 18, 2017
1 parent abaf8dc commit d4e5549
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
31 changes: 15 additions & 16 deletions ipywidgets/widgets/tests/test_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ def test_list_str():
d = dict(
cls=widgets.Dropdown,
value=first,
options=tuple(values),
_options_labels=tuple(values),
_options_values=tuple(values),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)

def test_list_int():
Expand All @@ -162,10 +162,10 @@ def test_list_int():
d = dict(
cls=widgets.Dropdown,
value=first,
options=tuple(values),
_options_labels=tuple(str(v) for v in values),
_options_values=tuple(values),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)

def test_list_tuple():
Expand All @@ -176,10 +176,10 @@ def test_list_tuple():
d = dict(
cls=widgets.Dropdown,
value=first,
options=tuple(values),
_options_labels=("3", "1", "2"),
_options_values=(300, 100, 200),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)

def test_list_tuple_invalid():
Expand All @@ -201,10 +201,10 @@ def test_dict():
cls=widgets.Dropdown,
description='d',
value=next(iter(d.values())),
options=d,
_options_labels=tuple(d.keys()),
_options_values=tuple(d.values()),
)
check['options'] = tuple(zip(check['_options_labels'], check['_options_values']))
check_widget(w, **check)


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

def test_iterable():
Expand All @@ -236,10 +235,10 @@ def yield_values():
d = dict(
cls=widgets.Dropdown,
value=first,
options=(3, 1, 2),
_options_labels=("3", "1", "2"),
_options_values=(3, 1, 2),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)

def test_iterable_tuple():
Expand All @@ -250,10 +249,10 @@ def test_iterable_tuple():
d = dict(
cls=widgets.Dropdown,
value=first,
options=tuple(values),
_options_labels=("3", "1", "2"),
_options_values=(300, 100, 200),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)

def test_mapping():
Expand All @@ -278,10 +277,10 @@ def items(self):
d = dict(
cls=widgets.Dropdown,
value=first,
options=tuple(items),
_options_labels=("3", "1", "2"),
_options_values=(300, 100, 200),
)
d['options'] = tuple(zip(d['_options_labels'], d['_options_values']))
check_widgets(c, lis=d)


Expand Down Expand Up @@ -327,12 +326,12 @@ def f(n, f=4.5, g=1, h=2, j='there'):
),
h=dict(
cls=widgets.Dropdown,
options=(('a', 1), ('b', 2)),
options=OrderedDict([('a',1), ('b',2)]),
value=2
),
j=dict(
cls=widgets.Dropdown,
options=(('hi', 'hi'), ('there', 'there')),
options=('hi', 'there'),
value='there'
),
)
Expand All @@ -350,12 +349,12 @@ def f(f='hi', h=5, j='other'):
),
h=dict(
cls=widgets.Dropdown,
options=(('a', 1),),
options={'a': 1},
value=1,
),
j=dict(
cls=widgets.Dropdown,
options=(('hi', 'hi'), ('there', 'there')),
options=('hi', 'there'),
value='hi',
),
)
Expand Down Expand Up @@ -682,7 +681,7 @@ def test_multiple_selection():

# basic multiple select
w = smw(options=[(1, 1)], value=[1])
check_widget(w, cls=smw, value=(1,), options=(('1', 1),))
check_widget(w, cls=smw, value=(1,), options=((1, 1),))

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

# change options, which resets value
w.options = w.options + ((2, 2),)
check_widget(w, options=(('1', 1), ('2',2)), value=())
check_widget(w, options=((1, 1), (2,2)), value=())

# change value
w.value = (1,2)
check_widget(w, value=(1, 2))

# dict style
w.options = {1: 1}
check_widget(w, options=(('1', 1),))
check_widget(w, options={1:1})

# updating
with nt.assert_raises(TraitError):
w.value = (2,)
check_widget(w, options=(('1', 1),))
check_widget(w, options={1:1})


def test_interact_noinspect():
Expand Down
4 changes: 2 additions & 2 deletions ipywidgets/widgets/widget_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class _Selection(DescriptionWidget, ValueWidget, CoreWidget):
label = Unicode(None, help="Selected label", allow_none=True)
index = Int(None, help="Selected index", allow_none=True).tag(sync=True)

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

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

0 comments on commit d4e5549

Please sign in to comment.