Example #1
0
def test_param_subobject_expand_by_default_no_toggle(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test,
                     _temporary=True,
                     expand_by_default=True,
                     toggleable_subobjects=False)
    model = test_pane._get_model(document, comm=comm)

    # Assert no toggle was added
    assert len(model.children[0].children) == 2

    # Expand subpane
    assert len(model.children) == 2
    _, subpanel = test_pane._layout.objects
    row = model.children[1]
    assert 'instance' in subpanel._callbacks
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    box = row.children[0]
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 2
    div, widget = box.children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput)
Example #2
0
def test_expand_param_subobject_tabs(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test, subobject_layout=Tabs, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

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

    # Expand subpanel
    test_pane._widgets['a'][1].active = True
    assert len(model.tabs) == 2
    _, subpanel = test_pane._layout.objects
    subtabs = model.tabs[1].child
    assert model.tabs[1].title == 'Nested'
    assert 'instance' in subpanel._callbacks
    assert isinstance(subtabs, BkTabs)
    assert len(subtabs.tabs) == 1
    assert subtabs.tabs[0].title == 'Nested'

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

    # Collapse subpanel
    test_pane._widgets['a'][1].active = False
    assert len(model.tabs) == 1
    assert subpanel._callbacks == {}
Example #3
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, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    slider = model.children[0].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.params('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
Example #4
0
def test_expand_param_subobject_expand_by_default(document, comm):
    class Test(param.Parameterized):
        a = param.Parameter()

    test = Test(a=Test(name='Nested'))
    test_pane = Pane(test, _temporary=True, expand_by_default=True)
    model = test_pane._get_model(document, comm=comm)

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

    # Expand subpane
    assert len(model.children) == 2
    _, subpanel = test_pane._layout.objects
    row = model.children[1]
    assert 'instance' in subpanel._callbacks
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    box = row.children[0]
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 2
    div, widget = box.children
    assert div.text == '<b>Nested</b>'
    assert isinstance(widget, BkTextInput)

    # Collapse subpanel
    test_pane._widgets['a'][1].active = False
    assert len(model.children) == 1
    assert subpanel._callbacks == {}
Example #5
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, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    widget = model.children[0].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.params('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
Example #6
0
def test_boolean_param(document, comm):
    class Test(param.Parameterized):
        a = param.Boolean(default=False)

    test = Test()
    test_pane = Pane(test, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    checkbox = model.children[0].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.params('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
Example #7
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'], _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    assert len(model.children[0].children) == 2
    assert isinstance(model.children[0].children[1], CheckboxGroup)
Example #8
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, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    slider = model.children[0].children[1]
    assert isinstance(slider, Button)
Example #9
0
def test_get_model_tabs(document, comm):
    class Test(param.Parameterized):
        pass

    test = Test()
    test_pane = Pane(test, subobject_layout=Tabs, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

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

    box = model.tabs[0].child
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 0
Example #10
0
def test_switch_param_subobject(document, comm):
    class Test(param.Parameterized):
        a = param.ObjectSelector()

    o1 = Test(name='Subobject 1')
    o2 = Test(name='Subobject 2')
    Test.params('a').objects = [o1, o2, 3]
    test = Test(a=o1, name='Nested')
    test_pane = Pane(test, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

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

    # Expand subpane
    test_pane._widgets['a'][1].active = True
    assert len(model.children) == 2
    _, subpanel = test_pane._layout.objects
    row = model.children[1]
    assert 'instance' in subpanel._callbacks
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    box = row.children[0]
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 3
    div, select, widget = box.children
    assert div.text == '<b>Subobject 1</b>'
    assert isinstance(select, Select)

    # Switch subobject
    test_pane._widgets['a'][0].value = o2
    _, subpanel = test_pane._layout.objects
    row = model.children[1]
    assert 'instance' in subpanel._callbacks
    assert isinstance(row, BkRow)
    assert len(row.children) == 1
    box = row.children[0]
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 3
    div, select, widget = box.children
    assert div.text == '<b>Subobject 2</b>'
    assert isinstance(select, Select)

    # Collapse subpanel
    test_pane._widgets['a'][1].active = False
    assert len(model.children) == 1
    assert subpanel._callbacks == {}
Example #11
0
def test_get_model(document, comm):
    class Test(param.Parameterized):
        pass

    test = Test()
    test_pane = Pane(test, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

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

    box = model.children[0]
    assert isinstance(box, BkWidgetBox)
    assert len(box.children) == 1

    div = box.children[0]
    assert isinstance(div, Div)
    assert div.text == '<b>' + test.name + '</b>'
Example #12
0
def test_number_param(document, comm):
    class Test(param.Parameterized):
        a = param.Number(default=1.2, bounds=(0, 5))

    test = Test()
    test_pane = Pane(test, _temporary=True)
    model = test_pane._get_model(document, comm=comm)

    slider = model.children[0].children[1]
    assert isinstance(slider, Slider)
    assert slider.value == 1.2
    assert slider.start == 0
    assert slider.end == 5
    assert slider.step == 0.1
    assert slider.disabled == False

    # Check changing param value updates widget
    test.a = 3.3
    assert slider.value == 3.3

    # Check changing param attribute updates widget
    a_param = test.params('a')
    a_param.bounds = (0.1, 5.5)
    assert slider.start == 0.1
    assert slider.end == 5.5

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

    # Ensure cleanup works
    test_pane._cleanup(model)
    a_param.constant = False
    a_param.bounds = (-0.1, 3.8)
    test.a = 0.5
    assert slider.value == 3.3
    assert slider.start == 0.1
    assert slider.end == 5.5
    assert slider.disabled == True