def test_set_widgets(document, comm): class Test(param.Parameterized): a = param.Number(default=1, bounds=(0, 10), precedence=1) b = param.String(default='A', precedence=2) pane = Param(Test()) model = pane.get_root(document, comm=comm) assert len(model.children) == 3 title, slider, text = model.children assert isinstance(title, Div) assert isinstance(slider, Slider) assert isinstance(text, TextInput) pane.widgets = {'a': LiteralInput(value=1, type=(float, int))} assert len(model.children) == 3 title, number, text = model.children assert isinstance(title, Div) assert isinstance(number, TextInput) assert isinstance(text, TextInput) pane.widgets = {'a': {'height': 100}} assert len(model.children) == 3 title, number, text = model.children assert isinstance(title, Div) assert isinstance(number, Slider) assert number.height == 100 assert isinstance(text, TextInput) pane.widgets = {'a': {'type': LiteralInput, 'height': 100}} assert len(model.children) == 3 title, number, text = model.children assert isinstance(title, Div) assert isinstance(number, TextInput) assert number.height == 100 assert isinstance(text, TextInput)
def test_literal_input(document, comm): literal = LiteralInput(value={}, type=dict, name='Literal') widget = literal._get_root(document, comm=comm) assert isinstance(widget, literal._widget_type) assert widget.title == 'Literal' assert widget.value == '{}' literal._comm_change({'value': "{'key': (0, 2)}"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal' literal._comm_change({'value': "(0, 2)"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal (wrong type)' literal._comm_change({'value': "invalid"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal (invalid)' literal._comm_change({'value': "{'key': (0, 3)}"}) assert literal.value == {'key': (0, 3)} assert widget.title == 'Literal' with pytest.raises(ValueError): literal.value = []
def test_literal_input(document, comm): literal = LiteralInput(value={}, type=dict, name='Literal') box = literal._get_model(document, comm=comm) assert isinstance(box, WidgetBox) widget = box.children[0] assert isinstance(widget, literal._widget_type) assert widget.title == 'Literal' assert widget.value == '{}' literal._comm_change({'value': "{'key': (0, 2)}"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal' literal._comm_change({'value': "(0, 2)"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal (wrong type)' literal._comm_change({'value': "invalid"}) assert literal.value == {'key': (0, 2)} assert widget.title == 'Literal (invalid)' literal._comm_change({'value': "{'key': (0, 3)}"}) assert literal.value == {'key': (0, 3)} assert widget.title == 'Literal'