Skip to content

Commit 571d6ce

Browse files
committed
Elaborate test sequence
1 parent bb2a6f7 commit 571d6ce

File tree

1 file changed

+20
-83
lines changed

1 file changed

+20
-83
lines changed

tests/integration/renderer/test_loading_states.py

Lines changed: 20 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from multiprocessing import Lock
22

3+
import pytest
34
import dash
45
from dash.dependencies import Input, Output
6+
from dash.testing.wait import until
57

68
import dash_core_components as dcc
79
import dash_html_components as html
@@ -169,65 +171,19 @@ def find_text(spec):
169171
find_text({1: 1, 2: 1, 3: 1, 4: 1})
170172

171173

172-
def test_rdls003_update_title_default(dash_duo):
174+
@pytest.mark.parametrize(
175+
"kwargs, expected_update_title",
176+
[
177+
({}, "Updating..."),
178+
({"update_title": None}, "Dash"),
179+
({"update_title": ""}, "Dash"),
180+
({"update_title": "Hello World"}, "Hello World"),
181+
]
182+
)
183+
def test_rdls003_update_title(dash_duo, kwargs, expected_update_title):
184+
app = dash.Dash("Dash", **kwargs)
173185
lock = Lock()
174186

175-
app = dash.Dash(__name__)
176-
177-
app.layout = html.Div(
178-
children=[
179-
html.H3("Press button see document title updating"),
180-
html.Div(id="output"),
181-
html.Button("Update", id="button", n_clicks=0),
182-
]
183-
)
184-
185-
@app.callback(
186-
Output("output", "children"),
187-
[Input("button", "n_clicks")]
188-
)
189-
def update(n):
190-
with lock:
191-
return n
192-
193-
with lock:
194-
dash_duo.start_server(app)
195-
dash_duo.find_element("#button").click()
196-
assert dash_duo.driver.title == "Updating..."
197-
198-
199-
def test_rdls004_update_title_None(dash_duo):
200-
lock = Lock()
201-
202-
app = dash.Dash(__name__, update_title=None)
203-
204-
app.layout = html.Div(
205-
children=[
206-
html.H3("Press button see document title updating"),
207-
html.Div(id="output"),
208-
html.Button("Update", id="button", n_clicks=0),
209-
]
210-
)
211-
212-
@app.callback(
213-
Output("output", "children"),
214-
[Input("button", "n_clicks")]
215-
)
216-
def update(n):
217-
with lock:
218-
return n
219-
220-
with lock:
221-
dash_duo.start_server(app)
222-
dash_duo.find_element("#button").click()
223-
assert dash_duo.driver.title == "Dash"
224-
225-
226-
def test_rdls005_update_title_empty(dash_duo):
227-
lock = Lock()
228-
229-
app = dash.Dash(__name__, update_title="")
230-
231187
app.layout = html.Div(
232188
children=[
233189
html.H3("Press button see document title updating"),
@@ -242,36 +198,17 @@ def test_rdls005_update_title_empty(dash_duo):
242198
)
243199
def update(n):
244200
with lock:
245-
return n
201+
# check for update-title while processing callback
202+
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)
203+
return n
246204

247205
with lock:
248206
dash_duo.start_server(app)
249-
dash_duo.find_element("#button").click()
250-
assert dash_duo.driver.title == "Dash"
251-
252-
253-
def test_rdls006_update_title_custom(dash_duo):
254-
lock = Lock()
255-
256-
app = dash.Dash(__name__, update_title="Hello World")
207+
# check for update-title on load
208+
until(lambda: dash_duo.driver.title == expected_update_title, timeout=1)
257209

258-
app.layout = html.Div(
259-
children=[
260-
html.H3("Press button see document title updating"),
261-
html.Div(id="output"),
262-
html.Button("Update", id="button", n_clicks=0),
263-
]
264-
)
265-
266-
@app.callback(
267-
Output("output", "children"),
268-
[Input("button", "n_clicks")]
269-
)
270-
def update(n):
271-
with lock:
272-
return n
210+
# check for original title after loading
211+
until(lambda: dash_duo.driver.title == "Dash", timeout=1)
273212

274213
with lock:
275-
dash_duo.start_server(app)
276214
dash_duo.find_element("#button").click()
277-
assert dash_duo.driver.title == "Hello World"

0 commit comments

Comments
 (0)