Exemplo n.º 1
0
def test_int_slider(document, comm):

    slider = IntSlider(start=0, end=3, value=1, name='Slider')

    widget = slider.get_root(document, comm=comm)

    assert isinstance(widget, slider._widget_type)
    assert widget.title == 'Slider'
    assert widget.step == 1
    assert widget.start == 0
    assert widget.end == 3
    assert widget.value == 1

    slider._process_events({'value': 2})
    assert slider.value == 2
    slider._process_events({'value_throttled': 2})
    assert slider.value_throttled == 2

    slider.value = 0
    assert widget.value == 0

    # Testing that value matches start value if value not set.
    slider_2 = IntSlider(start=1, end=3, name='Slider_2')
    widget_2 = slider_2.get_root(document, comm=comm)
    assert widget_2.value == widget_2.start

    # Testing throttled mode
    with config.set(throttled=True):
        slider._process_events({'value': 1})
        assert slider.value == 0  # no change
        slider._process_events({'value_throttled': 1})
        assert slider.value == 1

        slider.value = 2
        assert widget.value == 2
Exemplo n.º 2
0
def test_bind_two_widgets_as_kwargs():
    widget = IntSlider(value=0)
    widget2 = IntSlider(value=1)

    def add(value, value2):
        return value + value2

    bound_function = bind(add, value=widget, value2=widget2)

    assert bound_function() == 1

    widget.value = 1

    assert bound_function() == 2

    widget2.value = 2

    assert bound_function() == 3

    with pytest.raises(TypeError):
        bound_function(1, 2)

    assert bound_function(value2=5) == 6
Exemplo n.º 3
0
def test_bind_two_widget_arg_with_remaining_arg():
    widget = IntSlider(value=0)

    def add(value, value2):
        return value + value2

    bound_function = bind(add, widget)

    assert bound_function(1) == 1

    widget.value = 1

    assert bound_function(2) == 3
    assert bound_function(value2=3) == 4
Exemplo n.º 4
0
def test_bind_widget_to_kwarg():
    widget = IntSlider(value=0)

    def add1(value):
        return value + 1

    bound_function = bind(add1, value=widget)

    assert bound_function() == 1

    widget.value = 1

    assert bound_function() == 2

    with pytest.raises(TypeError):
        bound_function(1)
Exemplo n.º 5
0
def test_bind_bound_function_to_kwarg():
    widget = IntSlider(value=1)

    def add1(value):
        return value + 1

    def divide(divisor=2, value=0):
        return value / divisor

    bound_function = bind(divide, value=bind(add1, widget.param.value))

    assert bound_function() == 1

    widget.value = 3

    assert bound_function() == 2
Exemplo n.º 6
0
def test_int_slider(document, comm):

    slider = IntSlider(start=0, end=3, value=1, name='Slider')

    widget = slider.get_root(document, comm=comm)

    assert isinstance(widget, slider._widget_type)
    assert widget.title == 'Slider'
    assert widget.step == 1
    assert widget.start == 0
    assert widget.end == 3
    assert widget.value == 1

    slider._comm_change({'value': 2})
    assert slider.value == 2

    slider.value = 0
    assert widget.value == 0
Exemplo n.º 7
0
def test_int_slider(document, comm):

    slider = IntSlider(start=0, end=3, value=1, name='Slider')

    box = slider._get_model(document, comm=comm)

    assert isinstance(box, WidgetBox)

    widget = box.children[0]
    assert isinstance(widget, slider._widget_type)
    assert widget.title == 'Slider'
    assert widget.step == 1
    assert widget.start == 0
    assert widget.end == 3
    assert widget.value == 1

    slider._comm_change({'value': 2})
    assert slider.value == 2

    slider.value = 0
    assert widget.value == 0
Exemplo n.º 8
0
def test_int_slider(document, comm):

    slider = IntSlider(start=0, end=3, value=1, name='Slider')

    widget = slider.get_root(document, comm=comm)

    assert isinstance(widget, slider._widget_type)
    assert widget.title == 'Slider'
    assert widget.step == 1
    assert widget.start == 0
    assert widget.end == 3
    assert widget.value == 1

    slider._comm_change({'value': 2})
    assert slider.value == 2

    slider.value = 0
    assert widget.value == 0

    # Testing that value matches start value if value not set.
    slider_2 = IntSlider(start=1, end=3, name='Slider_2')
    widget_2 = slider_2.get_root(document, comm=comm)
    assert widget_2.value == widget_2.start
Exemplo n.º 9
0
def test_gridspec_stretch_with_replacement_pane(document, comm):
    slider = IntSlider(start=0, end=2)

    @depends(slider)
    def div(value):
        return Div(text=str(value))

    gspec = GridSpec(sizing_mode='stretch_width')

    gspec[0, 0:2] = Div()
    gspec[1, 2] = div

    model = gspec.get_root(document, comm=comm)
    ((div1, _, _, _, _), (row, _, _, _, _)) = model.children
    div2 = row.children[0]
    assert div1.sizing_mode == 'stretch_width'
    assert div1.height == 300
    assert div2.sizing_mode == 'stretch_width'
    assert div2.height == 300

    slider.value = 1
    assert row.children[0] is not div2
    assert row.children[0].sizing_mode == 'stretch_width'
    assert row.children[0].height == 300