1 2
from __future__ import absolute_import, division, unicode_literals
2

3 2
from panel.widgets import Button, Toggle
4

5

6 2
def test_button(document, comm):
7 2
    button = Button(name='Button')
8

9 2
    widget = button.get_root(document, comm=comm)
10

11 2
    assert isinstance(widget, button._widget_type)
12 2
    assert widget.label == 'Button'
13

14 2
    button._process_events({'clicks': 1})
15 2
    assert button.clicks == 1
16

17

18 2
def test_button_jscallback_clicks(document, comm):
19 2
    button = Button(name='Button')
20 2
    code = 'console.log("Clicked!")'
21 2
    button.jscallback(clicks=code)
22

23 2
    widget = button.get_root(document, comm=comm)
24 2
    assert len(widget.js_event_callbacks) == 1
25 2
    callbacks = widget.js_event_callbacks
26 2
    assert 'button_click' in callbacks
27 2
    assert len(callbacks['button_click']) == 1
28 2
    assert code in callbacks['button_click'][0].code
29

30

31 2
def test_toggle(document, comm):
32 2
    toggle = Toggle(name='Toggle', value=True)
33

34 2
    widget = toggle.get_root(document, comm=comm)
35

36 2
    assert isinstance(widget, toggle._widget_type)
37 2
    assert widget.active == True
38 2
    assert widget.label == 'Toggle'
39

40 2
    widget.active = False
41 2
    toggle._process_events({'active': widget.active})
42 2
    assert toggle.value == False
43

44 2
    toggle.value = True
45 2
    assert widget.active == True

Read our documentation on viewing source code .

Loading