def test_discrete_slider(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.value_throttled == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value_throttled == 10 discrete_slider.value = 100 assert widget.value == 3 with param.edit_constant(discrete_slider): discrete_slider.value_throttled = 100 assert widget.value_throttled == 3
def test_discrete_date_slider(document, comm): dates = OrderedDict([('2016-01-0%d' % i, datetime(2016, 1, i)) for i in range(1, 4)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=dates['2016-01-02'], options=dates) box = discrete_slider._get_root(document, comm=comm) assert isinstance(box, Column) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 2 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>2016-01-02</b>' widget.value = 2 discrete_slider._slider._comm_change({'value': 2}) assert discrete_slider.value == dates['2016-01-03'] discrete_slider.value = dates['2016-01-01'] assert widget.value == 0
def test_discrete_slider_options_dict(document, comm): options = OrderedDict([('0.1', 0.1), ('1', 1), ('10', 10), ('100', 100)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=options) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' # widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value_throttled == 10 discrete_slider.value = 100 assert widget.value == 3 # Testing throttled mode with config.set(throttled=True): discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == options['100'] # no change discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value == options['10'] discrete_slider.value = options['1'] assert widget.value == 1
def test_discrete_slider(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' # widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value_throttled == 10 discrete_slider.value = 100 assert widget.value == 3 # Testing throttled mode with config.set(throttled=True): discrete_slider._slider._process_events({'value': 0.1}) assert discrete_slider.value == 100 # no change discrete_slider._slider._process_events({'value_throttled': 0.1}) assert discrete_slider.value == 0.1 discrete_slider.value = 1 assert widget.value == 1
def test_discrete_slider_label_update(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) discrete_slider.value = 100 box = discrete_slider.get_root(document, comm=comm) assert box.children[0].text == 'DiscreteSlider: <b>100</b>'
def test_discrete_slider_name_update(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) box = discrete_slider.get_root(document, comm=comm) discrete_slider.name = 'Blah' assert box.children[0].text == 'Blah: <b>1</b>'
def test_discrete_slider_single_option(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', options=[0]) box = discrete_slider.get_root(document, comm=comm) assert box.children[0].text == 'DiscreteSlider: <b>0</b>' assert box.children[1].disabled assert box.children[1].start == 0 assert box.children[1].end == 1 discrete_slider.options = [0, 1] assert box.children[0].text == 'DiscreteSlider: <b>0</b>' assert not box.children[1].disabled assert box.children[1].start == 0 assert box.children[1].end == 1
def test_discrete_slider_options_dict(document, comm): options = OrderedDict([('0.1', 0.1), ('1', 1), ('10', 10), ('100', 100)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=options) box = discrete_slider._get_model(document, comm=comm) assert isinstance(box, WidgetBox) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == '<b>DiscreteSlider</b>: 1' widget.value = 2 discrete_slider._comm_change({'value': 2}) assert discrete_slider.value == 10 assert label.text == '<b>DiscreteSlider</b>: 10' discrete_slider.value = 100 assert widget.value == 3 assert label.text == '<b>DiscreteSlider</b>: 100'
def test_discrete_date_slider(document, comm): dates = OrderedDict([('2016-01-0%d' % i, datetime(2016, 1, i)) for i in range(1, 4)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=dates['2016-01-02'], options=dates) box = discrete_slider.get_root(document, comm=comm) assert isinstance(box, BkColumn) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 2 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>2016-01-02</b>' # widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == dates['2016-01-03'] discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value_throttled == dates['2016-01-03'] discrete_slider.value = dates['2016-01-01'] assert widget.value == 0 # Testing throttled mode with config.set(throttled=True): discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == dates['2016-01-01'] # no change discrete_slider._slider._process_events({'value_throttled': 2}) assert discrete_slider.value == dates['2016-01-03'] discrete_slider.value = dates['2016-01-02'] assert widget.value == 1
def test_discrete_slider(document, comm): discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=[0.1, 1, 10, 100]) box = discrete_slider._get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' widget.value = 2 discrete_slider._slider._comm_change({'value': 2}) assert discrete_slider.value == 10 discrete_slider.value = 100 assert widget.value == 3
def test_discrete_slider_options_dict(document, comm): options = OrderedDict([('0.1', 0.1), ('1', 1), ('10', 10), ('100', 100)]) discrete_slider = DiscreteSlider(name='DiscreteSlider', value=1, options=options) box = discrete_slider.get_root(document, comm=comm) label = box.children[0] widget = box.children[1] assert isinstance(label, BkDiv) assert isinstance(widget, BkSlider) assert widget.value == 1 assert widget.start == 0 assert widget.end == 3 assert widget.step == 1 assert label.text == 'DiscreteSlider: <b>1</b>' widget.value = 2 discrete_slider._slider._process_events({'value': 2}) assert discrete_slider.value == 10 discrete_slider.value = 100 assert widget.value == 3