def test_tabs_setitem_replace_all_error(document, comm): div1 = Div() div2 = Div() layout = Tabs(div1, div2) layout.get_root(document, comm=comm) div3 = Div() with pytest.raises(IndexError): layout[:] = div3
def test_tabs_setitem_out_of_bounds(document, comm): div1 = Div() div2 = Div() layout = Tabs(div1, div2) layout.get_root(document, comm=comm) div3 = Div() with pytest.raises(IndexError): layout[2] = div3
def test_tabs_setitem_replace_slice_out_of_bounds(document, comm): div1 = Div() div2 = Div() div3 = Div() layout = Tabs(div1, div2, div3) layout.get_root(document, comm=comm) div3 = Div() with pytest.raises(IndexError): layout[3:4] = [div3]
def test_plotly_tabs(document, comm): trace = go.Scatter(x=[0, 1], y=[2, 3]) pane1 = Plotly(dict(data=[trace], layout={'autosize': True})) pane2 = Plotly(dict(data=[trace], layout={'autosize': True})) tabs = Tabs(pane1, pane2) root = tabs.get_root(document, comm) model1 = pane1._models[root.id][0] model2 = pane2._models[root.id][0] cb1, cb2 = root.js_property_callbacks['change:active'] if cb1.args['model'] is model2: cb1, cb2 = cb2, cb1 assert model1.visible assert cb1.args['model'] is model1 assert cb1.args['i'] == 0 assert not model2.visible assert cb2.args['model'] is model2 assert cb2.args['i'] == 1 tabs.insert(0, 'Blah') assert cb1.args['i'] == 1 assert cb2.args['i'] == 2
def test_empty_tabs_append(document, comm): tabs = Tabs() model = tabs.get_root(document, comm=comm) div1 = Div() tabs.append(('test title', div1)) assert len(model.tabs) == 1 assert model.tabs[0].title == 'test title'
def test_tabs_clear(document, comm): div1 = Div() div2 = Div() tabs = Tabs(div1, div2) p1, p2 = tabs.objects model = tabs.get_root(document, comm=comm) tabs.clear() assert tabs._names == [] assert len(model.tabs) == 0 assert p1._models == p2._models == {}
def test_tabs_basic_constructor(document, comm): tabs = Tabs('plain', 'text') model = tabs.get_root(document, comm=comm) assert isinstance(model, BkTabs) assert len(model.tabs) == 2 assert all(isinstance(c, BkPanel) for c in model.tabs) tab1, tab2 = model.tabs assert 'plain' in tab1.child.text assert 'text' in tab2.child.text
def test_tabs_reverse(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') tabs = Tabs(p1, p2) model = tabs.get_root(document, comm=comm) tabs.reverse() tab1, tab2 = model.tabs assert tab1.child is div2 assert tab1.title == tab1.name == p2.name == 'Div2' assert tab2.child is div1 assert tab2.title == tab2.name == p1.name == 'Div1'
def test_tabs_remove(document, comm): div1 = Div() div2 = Div() tabs = Tabs(div1, div2) p1, p2 = tabs.objects model = tabs.get_root(document, comm=comm) tab1 = model.tabs[0] assert p1._models[model.ref['id']][0] is tab1.child tabs.remove(p1) assert len(model.tabs) == 1 tab1 = model.tabs[0] assert tab1.child is div2 assert p1._models == {}
def test_tabs_constructor(document, comm): div1 = Div() div2 = Div() tabs = Tabs(('Div1', div1), ('Div2', div2)) model = tabs.get_root(document, comm=comm) assert isinstance(model, BkTabs) assert len(model.tabs) == 2 assert all(isinstance(c, BkPanel) for c in model.tabs) tab1, tab2 = model.tabs assert tab1.title == 'Div1' assert tab1.child is div1 assert tab2.title == 'Div2' assert tab2.child is div2
def test_tabs_implicit_constructor(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') tabs = Tabs(p1, p2) model = tabs.get_root(document, comm=comm) assert isinstance(model, BkTabs) assert len(model.tabs) == 2 assert all(isinstance(c, BkPanel) for c in model.tabs) tab1, tab2 = model.tabs assert tab1.title == tab1.name == p1.name == 'Div1' assert tab1.child is div1 assert tab2.title == tab2.name == p2.name == 'Div2' assert tab2.child is div2
def test_tabs_setitem(document, comm): div1 = Div() div2 = Div() tabs = Tabs(div1, div2) p1, p2 = tabs.objects model = tabs.get_root(document, comm=comm) tab1, tab2 = model.tabs assert p1._models[model.ref['id']][0] is tab1.child div3 = Div() tabs[0] = ('C', div3) tab1, tab2 = model.tabs assert tab1.child is div3 assert tab1.title == 'C' assert tab2.child is div2 assert p1._models == {}
def test_tabs_constructor_with_named_objects(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') tabs = Tabs(('Tab1', p1), ('Tab2', p2)) model = tabs.get_root(document, comm=comm) assert isinstance(model, BkTabs) assert len(model.tabs) == 2 assert all(isinstance(c, BkPanel) for c in model.tabs) tab1, tab2 = model.tabs assert tab1.title == 'Tab1' assert tab1.name == p1.name == 'Div1' assert tab1.child is div1 assert tab2.title == 'Tab2' assert tab2.name == p2.name =='Div2' assert tab2.child is div2
def test_tabs_setitem_replace_all(document, comm): div1 = Div() div2 = Div() layout = Tabs(div1, div2) p1, p2 = layout.objects model = layout.get_root(document, comm=comm) assert p1._models[model.ref['id']][0] is model.tabs[0].child div3 = Div() div4 = Div() layout[:] = [('B', div3), ('C', div4)] tab1, tab2 = model.tabs assert tab1.child is div3 assert tab1.title == 'B' assert tab2.child is div4 assert tab2.title == 'C' assert p1._models == {} assert p2._models == {}
def test_tabs_setitem_replace_slice(document, comm): div1 = Div() div2 = Div() div3 = Div() layout = Tabs(('A', div1), ('B', div2), ('C', div3)) p1, p2, p3 = layout.objects model = layout.get_root(document, comm=comm) assert p1._models[model.ref['id']][0] is model.tabs[0].child div3 = Div() div4 = Div() layout[1:] = [('D', div3), ('E', div4)] tab1, tab2, tab3 = model.tabs assert tab1.child is div1 assert tab1.title == 'A' assert tab2.child is div3 assert tab2.title == 'D' assert tab3.child is div4 assert tab3.title == 'E' assert p2._models == {} assert p3._models == {}
def test_tabs_set_panes(document, comm): div1, div2 = Div(), Div() p1 = Pane(div1, name='Div1') p2 = Pane(div2, name='Div2') tabs = Tabs(p1, p2) model = tabs.get_root(document, comm=comm) div3 = Div() p3 = Pane(div3, name='Div3') tabs.objects = [p1, p2, p3] assert isinstance(model, BkTabs) assert len(model.tabs) == 3 assert all(isinstance(c, BkPanel) for c in model.tabs) tab1, tab2, tab3 = model.tabs assert tab1.title == tab1.name == p1.name =='Div1' assert tab1.child is div1 assert tab2.title == tab2.name == p2.name =='Div2' assert tab2.child is div2 assert tab3.title == tab3.name == p3.name =='Div3' assert tab3.child is div3