This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathtest_interval.py
71 lines (54 loc) · 1.95 KB
/
test_interval.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
67
68
69
70
71
import dash
from dash.testing import wait
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
import time
def test_intv001_interval(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
html.Div(id="output"),
dcc.Interval(id="interval", interval=1, max_intervals=2),
]
)
@app.callback(Output("output", "children"), [Input("interval", "n_intervals")])
def update_text(n):
return "{}".format(n)
dash_dcc.start_server(app)
time.sleep(5)
dash_dcc.wait_for_text_to_equal("#output", "2")
assert dash_dcc.get_logs() == []
def test_intv002_restart(dash_dcc):
app = dash.Dash(__name__)
app.layout = html.Div(
[
dcc.Interval(id="interval", interval=100, n_intervals=0, max_intervals=-1,),
html.Button("Start", id="start", n_clicks_timestamp=-1),
html.Button("Stop", id="stop", n_clicks_timestamp=-1),
html.Div(id="output"),
]
)
@app.callback(
Output("interval", "max_intervals"),
[Input("start", "n_clicks_timestamp"), Input("stop", "n_clicks_timestamp"),],
)
def start_stop(start, stop):
if start < stop:
return 0
else:
return -1
@app.callback(Output("output", "children"), [Input("interval", "n_intervals")])
def display_data(n_intervals):
return "Updated {}".format(n_intervals)
dash_dcc.start_server(app)
wait.until(lambda: dash_dcc.find_element("#output").text != "Updated 0", 3)
dash_dcc.find_element("#stop").click()
time.sleep(2)
text_now = dash_dcc.find_element("#output").text
time.sleep(2)
text_later = dash_dcc.find_element("#output").text
assert text_now == text_later
dash_dcc.find_element("#start").click()
wait.until(lambda: dash_dcc.find_element("#output").text != text_later, 3)
assert dash_dcc.get_logs() == []