1
1
from multiprocessing import Lock
2
2
3
+ import pytest
3
4
import dash
4
5
from dash .dependencies import Input , Output
6
+ from dash .testing .wait import until
5
7
6
8
import dash_core_components as dcc
7
9
import dash_html_components as html
@@ -169,65 +171,19 @@ def find_text(spec):
169
171
find_text ({1 : 1 , 2 : 1 , 3 : 1 , 4 : 1 })
170
172
171
173
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 )
173
185
lock = Lock ()
174
186
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
-
231
187
app .layout = html .Div (
232
188
children = [
233
189
html .H3 ("Press button see document title updating" ),
@@ -242,36 +198,17 @@ def test_rdls005_update_title_empty(dash_duo):
242
198
)
243
199
def update (n ):
244
200
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
246
204
247
205
with lock :
248
206
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 )
257
209
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 )
273
212
274
213
with lock :
275
- dash_duo .start_server (app )
276
214
dash_duo .find_element ("#button" ).click ()
277
- assert dash_duo .driver .title == "Hello World"
0 commit comments