示例#1
0
def test_bokeh_pane(document, comm):
    div = Div()
    pane = Pane(div)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert row.ref['id'] in pane._callbacks
    assert get_div(model) is div
    assert pane._models[row.ref['id']] is model

    # Replace Pane.object
    div2 = Div()
    pane.object = div2
    new_model = row.children[0]
    assert get_div(new_model) is div2
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is new_model

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
示例#2
0
def test_param_method_pane_changing_type(document, comm):
    test = View()
    pane = Pane(test.mixed_view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Matplotlib)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert model.ref['id'] in inner_pane._callbacks
    assert isinstance(model, BkWidgetBox)
    div = model.children[0]
    assert isinstance(div, Div)
    text = div.text

    # Update pane
    test.a = 5
    model = row.children[0]
    new_pane = pane._pane
    assert inner_pane._callbacks == {}
    assert isinstance(new_pane, Bokeh)
    div = get_div(model)
    assert isinstance(div, Div)
    assert div.text != text
    assert len(new_pane._callbacks) == 1
    assert model.ref['id'] in new_pane._callbacks

    # Cleanup pane
    new_pane._cleanup(model)
    assert new_pane._callbacks == {}
示例#3
0
def test_markdown_pane(document, comm):
    pane = Pane("**Markdown**")

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is model
    div = get_div(model)
    assert div.text == "<p><strong>Markdown</strong></p>"

    # Replace Pane.object
    pane.object = "*Markdown*"
    model = row.children[0]
    assert div is get_div(model)
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is model
    assert div.text == "<p><em>Markdown</em></p>"

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
示例#4
0
def test_plotly_pane_single_trace(document, comm):
    trace = go.Scatter(x=[0, 1], y=[2, 3], uid='Test')
    pane = Pane(trace, layout={'width': 350})

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert isinstance(model, PlotlyPlot)
    assert model.ref['id'] in pane._callbacks
    assert len(model.data['data']) == 1
    assert model.data['data'][0]['type'] == 'scatter'
    assert model.data['data'][0]['x'] == [0, 1]
    assert model.data['data'][0]['y'] == [2, 3]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 1
    assert model.data_sources[0].data == {}

    # Replace Pane.object
    new_trace = go.Bar(x=[2, 3], y=[4, 5])
    pane.object = new_trace
    assert row.children[0] is model
    assert len(model.data['data']) == 1
    assert model.data['data'][0]['type'] == 'bar'
    assert model.data['data'][0]['x'] == [2, 3]
    assert model.data['data'][0]['y'] == [4, 5]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 1
    assert model.data_sources[0].data == {}
    assert model.ref['id'] in pane._callbacks

    # Cleanup
    pane._cleanup(model)
    assert pane._callbacks == {}
示例#5
0
def test_param_method_pane(document, comm):
    test = View()
    pane = Pane(test.view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Bokeh)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    div = get_div(model)
    assert model.ref['id'] in inner_pane._callbacks
    assert isinstance(div, Div)
    assert div.text == '0'

    # Update pane
    test.a = 5
    new_model = row.children[0]
    div = get_div(new_model)
    assert inner_pane is pane._pane
    assert div.text == '5'
    assert len(inner_pane._callbacks) == 1
    assert new_model.ref['id'] in inner_pane._callbacks

    # Cleanup pane
    pane._cleanup(new_model)
    assert inner_pane._callbacks == {}
示例#6
0
def test_holoviews_pane_mpl_renderer(document, comm):
    curve = hv.Curve([1, 2, 3])
    pane = Pane(curve)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    assert len(pane._callbacks) == 1
    model = row.children[0]
    assert pane._models[row.ref['id']] is model
    div = get_div(model)
    assert '<img' in div.text

    # Replace Pane.object
    scatter = hv.Scatter([1, 2, 3])
    pane.object = scatter
    model = row.children[0]
    div2 = get_div(model)
    assert div2.text != div.text

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
示例#7
0
def test_holoviews_pane_bokeh_renderer(document, comm):
    curve = hv.Curve([1, 2, 3])
    pane = Pane(curve)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    assert len(pane._callbacks) == 1
    model = row.children[0]
    assert isinstance(model, Figure)
    assert pane._models[row.ref['id']] is model
    renderers = [r for r in model.renderers if isinstance(r, GlyphRenderer)]
    assert len(renderers) == 1
    assert isinstance(renderers[0].glyph, Line)

    # Replace Pane.object
    scatter = hv.Scatter([1, 2, 3])
    pane.object = scatter
    model = row.children[0]
    assert isinstance(model, Figure)
    renderers = [r for r in model.renderers if isinstance(r, GlyphRenderer)]
    assert len(renderers) == 1
    assert isinstance(renderers[0].glyph, Scatter)
    assert len(pane._callbacks) == 1
    assert pane._models[row.ref['id']] is model

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
示例#8
0
def test_holoviews_link_within_pane(document, comm):
    from bokeh.models.tools import RangeTool
    from holoviews.plotting.links import RangeToolLink

    c1 = hv.Curve([])
    c2 = hv.Curve([])

    RangeToolLink(c1, c2)

    pane = Pane(hv.Layout([c1, c2]))
    column = pane._get_root(document, comm=comm)

    assert len(column.children) == 1
    subcolumn = column.children[0]
    assert isinstance(subcolumn, BkColumn)
    assert len(subcolumn.children) == 2
    toolbar, subsubcolumn = subcolumn.children
    assert isinstance(subsubcolumn, BkColumn)
    assert len(subsubcolumn.children) == 1
    row = subsubcolumn.children[0]
    assert isinstance(row, BkRow)
    assert len(row.children) == 2
    p1, p2 = row.children

    assert isinstance(p1, Figure)
    assert isinstance(p2, Figure)

    range_tool = row.select_one({'type': RangeTool})
    assert isinstance(range_tool, RangeTool)
    range_tool.x_range = p2.x_range
示例#9
0
def test_vega_pane(document, comm):
    pane = Pane(vega_example)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert isinstance(model, VegaPlot)

    expected = dict(vega_example, data={})

    assert model.data == expected
    cds_data = model.data_sources['data'].data
    assert np.array_equal(cds_data['x'], np.array(['A', 'B', 'C', 'D', 'E']))
    assert np.array_equal(cds_data['y'], np.array([5, 3, 6, 7, 2]))

    point_example = dict(vega_example, mark='point')
    point_example['data']['values'][0]['x'] = 'C'
    pane.object = point_example
    point_example['data'].pop('values')
    assert model.data == point_example
    cds_data = model.data_sources['data'].data
    assert np.array_equal(cds_data['x'], np.array(['C', 'B', 'C', 'D', 'E']))
    assert np.array_equal(cds_data['y'], np.array([5, 3, 6, 7, 2]))

    pane._cleanup(row)
    assert pane._callbacks == {}
示例#10
0
def test_altair_pane(document, comm):
    pane = Pane(altair_example())

    # Create pane
    model = pane._get_root(document, comm=comm)
    assert isinstance(model, VegaPlot)

    expected = dict(vega_example, data={})

    assert model.data == expected

    cds_data = model.data_sources['data'].data
    assert np.array_equal(cds_data['x'], np.array(['A', 'B', 'C', 'D', 'E']))
    assert np.array_equal(cds_data['y'], np.array([5, 3, 6, 7, 2]))

    chart = altair_example()
    chart.mark = 'point'
    chart.data.values[0]['x'] = 'C'
    pane.object = chart
    point_example = dict(vega_example, mark='point')
    assert model.data == point_example
    cds_data = model.data_sources['data'].data
    assert np.array_equal(cds_data['x'], np.array(['C', 'B', 'C', 'D', 'E']))
    assert np.array_equal(cds_data['y'], np.array([5, 3, 6, 7, 2]))

    pane._cleanup(model)
    assert pane._models == {}
示例#11
0
def test_matplotlib_pane(document, comm):
    pane = Pane(mpl_figure())

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    assert row.ref['id'] in pane._callbacks
    model = row.children[0]
    div = get_div(model)
    assert '<img' in div.text
    text = div.text
    assert pane._models[row.ref['id']] is model

    # Replace Pane.object
    pane.object = mpl_figure()
    model = row.children[0]
    div2 = get_div(model)
    assert div is div2
    assert div.text != text
    assert row.ref['id'] in pane._callbacks
    assert pane._models[row.ref['id']] is model

    # Cleanup
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
示例#12
0
def test_plotly_pane_single_trace(document, comm):
    trace = go.Scatter(x=[0, 1], y=[2, 3], uid='Test')
    pane = Pane({'data': [trace], 'layout': {'width': 350}})

    # Create pane
    model = pane._get_root(document, comm=comm)
    assert isinstance(model, PlotlyPlot)
    assert pane._models[model.ref['id']][0] is model
    assert len(model.data['data']) == 1
    assert model.data['data'][0]['type'] == 'scatter'
    assert model.data['data'][0]['x'] == [0, 1]
    assert model.data['data'][0]['y'] == [2, 3]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 1
    assert model.data_sources[0].data == {}

    # Replace Pane.object
    new_trace = go.Bar(x=[2, 3], y=[4, 5])
    pane.object = {'data': new_trace, 'layout': {'width': 350}}
    assert len(model.data['data']) == 1
    assert model.data['data'][0]['type'] == 'bar'
    assert model.data['data'][0]['x'] == [2, 3]
    assert model.data['data'][0]['y'] == [4, 5]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 1
    assert model.data_sources[0].data == {}
    assert pane._models[model.ref['id']][0] is model

    # Cleanup
    pane._cleanup(model)
    assert pane._models == {}
示例#13
0
def test_matplotlib_pane(document, comm):
    pane = Pane(mpl_figure())

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    assert len(pane._callbacks) == 1
    model = row.children[0]
    assert isinstance(model, BkWidgetBox)
    div = model.children[0]
    assert isinstance(div, Div)
    assert '<img' in div.text
    text = div.text

    # Replace Pane.object
    pane.object = mpl_figure()
    model = row.children[0]
    assert isinstance(model, BkWidgetBox)
    div2 = model.children[0]
    assert div is div2
    assert div.text != text

    # Cleanup
    pane._cleanup(model)
    assert pane._callbacks == {}
示例#14
0
def test_param_method_pane(document, comm):
    test = View()
    pane = Pane(test.view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Bokeh)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    inner_row = row.children[0]
    model = inner_row.children[0]
    assert pane._models[row.ref['id']][0] is inner_row
    assert isinstance(model, Div)
    assert model.text == '0'

    # Update pane
    test.a = 5
    new_model = inner_row.children[0]
    assert inner_pane is pane._pane
    assert new_model.text == '5'
    assert pane._models[row.ref['id']][0] is inner_row

    # Cleanup pane
    pane._cleanup(row)
    assert pane._models == {}
    assert inner_pane._models == {}
示例#15
0
def test_param_method_pane_subobject(document, comm):
    subobject = View(name='Nested', a=42)
    test = View(b=subobject)
    pane = Pane(test.subobject_view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Bokeh)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    inner_row = row.children[0]
    model = inner_row.children[0]
    assert isinstance(model, Div)
    assert model.text == '42'

    # Ensure that subobject is being watched
    watchers = pane._callbacks
    assert any(w.inst is subobject for w in watchers)
    assert pane._models[row.ref['id']][0] is inner_row

    # Ensure that switching the subobject triggers update in watchers
    new_subobject = View(name='Nested', a=42)
    test.b = new_subobject
    assert pane._models[row.ref['id']][0] is inner_row
    watchers = pane._callbacks
    assert not any(w.inst is subobject for w in watchers)
    assert any(w.inst is new_subobject for w in watchers)

    # Cleanup pane
    pane._cleanup(row)
    assert pane._models == {}
    assert inner_pane._models == {}
示例#16
0
def test_param_method_pane_changing_type(document, comm):
    test = View()
    pane = Pane(test.mixed_view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Matplotlib)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    inner_row = row.children[0]
    model = inner_row.children[0]
    text = model.text
    assert text.startswith('<img src')

    # Update pane
    test.a = 5
    new_model = inner_row.children[0]
    new_pane = pane._pane
    assert isinstance(new_pane, Bokeh)
    assert isinstance(new_model, Div)
    assert new_model.text != text

    # Cleanup pane
    new_pane._cleanup(row)
    assert new_pane._models == {}
示例#17
0
def test_expand_param_subobject_tabs(document, comm):
    class Test(param.Parameterized):
        abc = param.Parameter()

    test = Test(abc=Test(name='Nested'), name='A')
    test_pane = Pane(test, expand_layout=Tabs)
    model = test_pane._get_root(document, comm=comm)

    toggle = model.tabs[0].child.children[1]
    assert isinstance(toggle, Toggle)

    # Expand subpanel
    test_pane._widgets['abc'][1].value = True
    assert len(model.tabs) == 2
    _, subpanel = test_pane.layout.objects
    subtabs = model.tabs[1].child
    assert model.tabs[1].title == 'Abc'
    assert isinstance(subtabs, BkTabs)
    assert len(subtabs.tabs) == 1
    assert subtabs.tabs[0].title == 'Nested'

    box = subtabs.tabs[0].child
    assert isinstance(box, BkColumn)
    assert len(box.children) == 1
    widget = box.children[0]
    assert isinstance(widget, BkTextInput)

    # Collapse subpanel
    test_pane._widgets['abc'][1].value = False
    assert len(model.tabs) == 1
示例#18
0
def test_list_selector_param(document, comm):
    class Test(param.Parameterized):
        a = param.ListSelector(default=['b', 1], objects=[1, 'b', 'c'])

    test = Test()
    test_pane = Pane(test)
    model = test_pane._get_root(document, comm=comm)

    slider = model.children[1]
    assert isinstance(slider, MultiSelect)
    assert slider.options == ['1', 'b', 'c']
    assert slider.value == ['b', '1']
    assert slider.disabled == False

    # Check changing param value updates widget
    test.a = ['c', 1]
    assert slider.value == ['c', '1']

    # Check changing param attribute updates widget
    a_param = test.param['a']
    a_param.objects = ['c', 'd', 1]
    assert slider.options == ['c', 'd', '1']

    a_param.constant = True
    assert slider.disabled == True

    # Ensure cleanup works
    test_pane._cleanup(model)
    a_param.constant = False
    a_param.objects = [1, 'c', 'd']
    test.a = ['d']
    assert slider.value == ['c', '1']
    assert slider.options == ['c', 'd', '1']
    assert slider.disabled == True
示例#19
0
def test_range_param(document, comm):
    class Test(param.Parameterized):
        a = param.Range(default=(0.1, 0.5), bounds=(0, 1.1))

    test = Test()
    test_pane = Pane(test)
    model = test_pane._get_root(document, comm=comm)

    widget = model.children[1]
    assert isinstance(widget, RangeSlider)
    assert widget.start == 0
    assert widget.end == 1.1
    assert widget.value == (0.1, 0.5)

    # Check changing param value updates widget
    test.a = (0.2, 0.4)
    assert widget.value == (0.2, 0.4)

    # Check changing param attribute updates widget
    a_param = test.param['a']
    a_param.bounds = (0.1, 0.6)
    assert widget.start == 0.1
    assert widget.end == 0.6
    a_param.constant = True
    assert widget.disabled == True

    # Ensure cleanup works
    test_pane._cleanup(model)
    a_param.constant = False
    a_param.bounds = (-1, 1)
    test.a = (0.05, 0.2)
    assert widget.value == (0.2, 0.4)
    assert widget.start == 0.1
    assert widget.end == 0.6
    assert widget.disabled == True
示例#20
0
def test_boolean_param(document, comm):
    class Test(param.Parameterized):
        a = param.Boolean(default=False)

    test = Test()
    test_pane = Pane(test)
    model = test_pane._get_root(document, comm=comm)

    checkbox = model.children[1]
    assert isinstance(checkbox, CheckboxGroup)
    assert checkbox.labels == ['A']
    assert checkbox.active == []
    assert checkbox.disabled == False

    # Check changing param value updates widget
    test.a = True
    assert checkbox.active == [0]

    # Check changing param attribute updates widget
    a_param = test.param['a']
    a_param.constant = True
    assert checkbox.disabled == True

    # Ensure cleanup works
    test_pane._cleanup(model)
    a_param.constant = False
    test.a = False
    assert checkbox.active == [0]
    assert checkbox.disabled == True
示例#21
0
def test_param_method_pane_mpl(document, comm):
    test = View()
    pane = Pane(test.mpl_view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Matplotlib)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    inner_row = row.children[0]
    model = inner_row.children[0]
    assert row.ref['id'] in inner_pane._callbacks
    assert pane._models[row.ref['id']] is inner_row
    div = get_div(model)
    text = div.text

    # Update pane
    test.a = 5
    model = inner_row.children[0]
    assert inner_pane is pane._pane
    assert div is get_div(model)
    assert div.text != text
    assert len(inner_pane._callbacks) == 1
    assert row.ref['id'] in inner_pane._callbacks
    assert pane._models[row.ref['id']] is inner_row

    # Cleanup pane
    pane._cleanup(row)
    assert pane._callbacks == {}
    assert pane._models == {}
    assert inner_pane._callbacks == {}
    assert inner_pane._models == {}
示例#22
0
def test_param_method_pane_mpl(document, comm):
    test = View()
    pane = Pane(test.mpl_view)
    inner_pane = pane._pane
    assert isinstance(inner_pane, Matplotlib)

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    inner_row = row.children[0]
    model = inner_row.children[0]
    assert pane._models[row.ref['id']][0] is inner_row
    text = model.text

    # Update pane
    test.a = 5
    new_model = inner_row.children[0]
    assert inner_pane is pane._pane
    assert new_model is model
    assert new_model.text != text
    assert pane._models[row.ref['id']][0] is inner_row

    # Cleanup pane
    pane._cleanup(row)
    assert pane._models == {}
    assert inner_pane._models == {}
示例#23
0
def test_expand_param_subobject_expand(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test, expand=True, expand_button=True)
    model = test_pane._get_root(document, comm=comm)

    toggle = model.children[2]
    assert isinstance(toggle, Toggle)

    # Expand subpane
    assert len(model.children) == 4
    _, _, _, subpanel = test_pane.layout.objects
    col = model.children[3]
    assert isinstance(col, BkColumn)
    assert len(col.children) == 2
    div, widget = col.children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput)

    # Collapse subpanel
    test_pane._widgets['a'][1].value = False
    assert len(model.children) == 3
    assert subpanel._models == {}
示例#24
0
def test_explicit_params(document, comm):
    class Test(param.Parameterized):
        a = param.Boolean(default=False)
        b = param.Integer(default=1)

    test = Test()
    test_pane = Pane(test, parameters=['a'])
    model = test_pane._get_root(document, comm=comm)

    assert len(model.children) == 2
    assert isinstance(model.children[1], CheckboxGroup)
示例#25
0
def test_action_param(document, comm):
    class Test(param.Parameterized):
        a = param.Action(lambda x: x.b.append(1))
        b = param.List(default=[])

    test = Test()
    test_pane = Pane(test)
    model = test_pane._get_root(document, comm=comm)

    slider = model.children[1]
    assert isinstance(slider, Button)
示例#26
0
def test_single_param(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter(default=0)

    test = Test()
    test_pane = Pane(test.param.a)
    model = test_pane._get_root(document, comm=comm)

    assert isinstance(model, BkColumn)
    assert len(model.children) == 1

    widget = model.children[0]
    assert isinstance(widget, TextInput)
    assert widget.value == '0'
示例#27
0
def test_get_root_tabs(document, comm):
    class Test(param.Parameterized):
        pass

    test = Test()
    test_pane = Pane(test, expand_layout=Tabs)
    model = test_pane._get_root(document, comm=comm)

    assert isinstance(model, BkTabs)
    assert len(model.tabs) == 1

    box = model.tabs[0].child
    assert isinstance(box, BkColumn)
    assert len(box.children) == 0
示例#28
0
def test_get_root(document, comm):
    class Test(param.Parameterized):
        pass

    test = Test()
    test_pane = Pane(test)
    model = test_pane._get_root(document, comm=comm)

    assert isinstance(model, BkColumn)
    assert len(model.children) == 1

    div = model.children[0]
    assert isinstance(div, Div)
    assert div.text == '<b>' + test.name[:-5] + '</b>'
示例#29
0
def test_plotly_pane_numpy_to_cds_traces(document, comm):
    trace = go.Scatter(x=np.array([1, 2]), y=np.array([2, 3]))
    pane = Pane(trace, layout={'width': 350})

    # Create pane
    row = pane._get_root(document, comm=comm)
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    model = row.children[0]
    assert isinstance(model, PlotlyPlot)
    assert row.ref['id'] in pane._callbacks
    assert len(model.data['data']) == 1
    assert model.data['data'][0]['type'] == 'scatter'
    assert 'x' not in model.data['data'][0]
    assert 'y' not in model.data['data'][0]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 1
    cds = model.data_sources[0]
    assert np.array_equal(cds.data['x'], np.array([1, 2]))
    assert np.array_equal(cds.data['y'], np.array([2, 3]))

    # Replace Pane.object
    new_trace = [
        go.Scatter(x=np.array([5, 6]), y=np.array([6, 7])),
        go.Bar(x=np.array([2, 3]), y=np.array([4, 5]))
    ]
    pane.object = new_trace
    assert row.children[0] is model
    assert len(model.data['data']) == 2
    assert model.data['data'][0]['type'] == 'scatter'
    assert 'x' not in model.data['data'][0]
    assert 'y' not in model.data['data'][0]
    assert model.data['data'][1]['type'] == 'bar'
    assert 'x' not in model.data['data'][1]
    assert 'y' not in model.data['data'][1]
    assert model.data['layout'] == {'width': 350}
    assert len(model.data_sources) == 2
    cds = model.data_sources[0]
    assert np.array_equal(cds.data['x'], np.array([5, 6]))
    assert np.array_equal(cds.data['y'], np.array([6, 7]))
    cds2 = model.data_sources[1]
    assert np.array_equal(cds2.data['x'], np.array([2, 3]))
    assert np.array_equal(cds2.data['y'], np.array([4, 5]))
    assert row.ref['id'] in pane._callbacks

    # Cleanup
    pane._cleanup(row, True)
    assert pane._callbacks == {}
示例#30
0
def test_param_subobject_expand_no_toggle(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test, expand=True, expand_button=False)
    model = test_pane._get_root(document, comm=comm)

    # Assert no toggle was added
    assert len(model.children) == 3

    # Expand subpane
    _, _, subpanel = test_pane.layout.objects
    div, widget = model.children[2].children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput)