def test_select_change_groups(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) new_groups = dict(C=dict(d=4), D=dict(e=5, f=6)) select.groups = new_groups assert select.value == new_groups['C']['d'] assert widget.value == str(new_groups['C']['d']) assert widget.options == {'C': [('4', 'd')], 'D': [('5', 'e'), ('6', 'f')]} select.groups = {} assert select.value == None assert widget.value == ''
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