-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathtest_integration.py
66 lines (54 loc) · 1.97 KB
/
test_integration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from multiprocessing import Value
import dash_html_components as html
import dash_core_components as dcc
from dash import Dash
from dash.dependencies import Input, Output
from .IntegrationTests import IntegrationTests
from .utils import assert_clean_console, invincible, wait_for
class Tests(IntegrationTests):
def setUp(self):
def wait_for_element_by_id(id):
wait_for(lambda: None is not invincible(
lambda: self.driver.find_element_by_id(id)
))
return self.driver.find_element_by_id(id)
self.wait_for_element_by_id = wait_for_element_by_id
def test_simple_callback(self):
app = Dash(__name__)
app.layout = html.Div([
dcc.Input(
id='input',
value='initial value'
),
html.Div(
html.Div([
1.5,
None,
'string',
html.Div(id='output-1')
])
)
])
call_count = Value('i', 0)
@app.callback(Output('output-1', 'children'), [Input('input', 'value')])
def update_output(value):
call_count.value = call_count.value + 1
return value
self.startServer(app)
output1 = self.wait_for_element_by_id('output-1')
wait_for(lambda: output1.text == 'initial value')
self.percy_snapshot(name='simple-callback-1')
input1 = self.wait_for_element_by_id('input')
input1.clear()
input1.send_keys('hello world')
output1 = lambda: self.wait_for_element_by_id('output-1')
wait_for(lambda: output1().text == 'hello world')
self.percy_snapshot(name='simple-callback-2')
self.assertEqual(
call_count.value,
# an initial call to retrieve the first value
1 +
# one for each hello world character
len('hello world')
)
assert_clean_console(self)