def test_select_change_options(document, comm): opts = {'A': 'a', '1': 1} select = Select(options=opts, value=opts['1'], name='Select') widget = select.get_root(document, comm=comm) select.options = {'A': 'a'} assert select.value == opts['A'] assert widget.value == as_unicode(opts['A']) select.options = {} assert select.value == None assert widget.value == ''
def test_select_non_hashable_options(document, comm): opts = {'A': np.array([1, 2, 3]), '1': np.array([3, 4, 5])} select = Select(options=opts, value=opts['1'], name='Select') widget = select.get_root(document, comm=comm) select.value = opts['A'] assert select.value is opts['A'] assert widget.value == as_unicode(opts['A']) opts.pop('A') select.options = opts assert select.value is opts['1'] assert widget.value == as_unicode(opts['1'])
def test_select_groups_error_with_options(): # Instantiate with groups and options with pytest.raises(ValueError): Select(options=[1, 2], groups=dict(a=[1], b=[2]), name='Select') opts = [1, 2, 3] groups = dict(a=[1, 2], b=[3]) # Instamtiate with options and then update groups select = Select(options=opts, name='Select') with pytest.raises(ValueError): select.groups = groups # Instantiate with groups and then update options select = Select(groups=groups, name='Select') with pytest.raises(ValueError): select.options = opts