def test_select_groups_dict_options(document, comm): groups = dict(A=dict(a=1, b=2), B=dict(c=3)) select = Select(value=groups['A']['a'], groups=groups, name='Select') widget = select.get_root(document, comm=comm) assert isinstance(widget, select._widget_type) assert widget.title == 'Select' assert widget.value == str(groups['A']['a']) assert widget.options == {'A': [('1', 'a'), ('2', 'b')], 'B': [('3', 'c')]} select._process_events({'value': str(groups['B']['c'])}) assert select.value == groups['B']['c'] select._process_events({'value': str(groups['A']['b'])}) assert select.value == groups['A']['b'] select.value = groups['A']['a'] assert widget.value == str(groups['A']['a'])
def test_select(document, comm): opts = {'A': 'a', '1': 1} select = Select(options=opts, value=opts['1'], name='Select') widget = select.get_root(document, comm=comm) assert isinstance(widget, select._widget_type) assert widget.title == 'Select' assert widget.value == as_unicode(opts['1']) assert widget.options == [(as_unicode(v), k) for k, v in opts.items()] select._process_events({'value': as_unicode(opts['A'])}) assert select.value == opts['A'] widget.value = as_unicode(opts['1']) select.value = opts['1'] assert select.value == opts['1'] select.value = opts['A'] assert widget.value == as_unicode(opts['A'])
def test_select_mutables(document, comm): opts = OrderedDict([('A', [1, 2, 3]), ('B', [2, 4, 6]), ('C', dict(a=1, b=2))]) select = Select(options=opts, value=opts['B'], name='Select') widget = select.get_root(document, comm=comm) assert isinstance(widget, select._widget_type) assert widget.title == 'Select' assert widget.value == as_unicode(opts['B']) assert widget.options == [(as_unicode(v), k) for k, v in opts.items()] widget.value = as_unicode(opts['B']) select._process_events({'value': as_unicode(opts['A'])}) assert select.value == opts['A'] widget.value = as_unicode(opts['B']) select._process_events({'value': as_unicode(opts['B'])}) assert select.value == opts['B'] select.value = opts['A'] assert widget.value == as_unicode(opts['A'])
def test_select_groups_list_options(document, comm): groups = dict(a=[1, 2], b=[3]) select = Select(value=groups['a'][0], groups=groups, name='Select') widget = select.get_root(document, comm=comm) assert isinstance(widget, select._widget_type) assert widget.title == 'Select' assert widget.value == str(groups['a'][0]) assert widget.options == { gr: [(str(v), str(v)) for v in values] for gr, values in groups.items() } select._process_events({'value': str(groups['a'][1])}) assert select.value == groups['a'][1] select._process_events({'value': str(groups['a'][0])}) assert select.value == groups['a'][0] select.value = groups['a'][1] assert widget.value == str(groups['a'][1])