|
16 | 16 | from dash.dependencies import Input, Output, State
|
17 | 17 | from dash.exceptions import PreventUpdate
|
18 | 18 | from dash.testing import wait
|
| 19 | +from tests.integration.utils import json_engine |
19 | 20 |
|
20 | 21 |
|
21 | 22 | def test_cbsc001_simple_callback(dash_duo):
|
@@ -248,57 +249,61 @@ def update_out2(n_clicks, data):
|
248 | 249 | assert dash_duo.get_logs() == []
|
249 | 250 |
|
250 | 251 |
|
251 |
| -def test_cbsc005_children_types(dash_duo): |
252 |
| - app = dash.Dash() |
253 |
| - app.layout = html.Div([html.Button(id="btn"), html.Div("init", id="out")]) |
254 |
| - |
255 |
| - outputs = [ |
256 |
| - [None, ""], |
257 |
| - ["a string", "a string"], |
258 |
| - [123, "123"], |
259 |
| - [123.45, "123.45"], |
260 |
| - [[6, 7, 8], "678"], |
261 |
| - [["a", "list", "of", "strings"], "alistofstrings"], |
262 |
| - [["strings", 2, "numbers"], "strings2numbers"], |
263 |
| - [["a string", html.Div("and a div")], "a string\nand a div"], |
264 |
| - ] |
265 |
| - |
266 |
| - @app.callback(Output("out", "children"), [Input("btn", "n_clicks")]) |
267 |
| - def set_children(n): |
268 |
| - if n is None or n > len(outputs): |
269 |
| - return dash.no_update |
270 |
| - return outputs[n - 1][0] |
| 252 | +@pytest.mark.parametrize("engine", ["json", "orjson"]) |
| 253 | +def test_cbsc005_children_types(dash_duo, engine): |
| 254 | + with json_engine(engine): |
| 255 | + app = dash.Dash() |
| 256 | + app.layout = html.Div([html.Button(id="btn"), html.Div("init", id="out")]) |
| 257 | + |
| 258 | + outputs = [ |
| 259 | + [None, ""], |
| 260 | + ["a string", "a string"], |
| 261 | + [123, "123"], |
| 262 | + [123.45, "123.45"], |
| 263 | + [[6, 7, 8], "678"], |
| 264 | + [["a", "list", "of", "strings"], "alistofstrings"], |
| 265 | + [["strings", 2, "numbers"], "strings2numbers"], |
| 266 | + [["a string", html.Div("and a div")], "a string\nand a div"], |
| 267 | + ] |
271 | 268 |
|
272 |
| - dash_duo.start_server(app) |
273 |
| - dash_duo.wait_for_text_to_equal("#out", "init") |
| 269 | + @app.callback(Output("out", "children"), [Input("btn", "n_clicks")]) |
| 270 | + def set_children(n): |
| 271 | + if n is None or n > len(outputs): |
| 272 | + return dash.no_update |
| 273 | + return outputs[n - 1][0] |
274 | 274 |
|
275 |
| - for children, text in outputs: |
276 |
| - dash_duo.find_element("#btn").click() |
277 |
| - dash_duo.wait_for_text_to_equal("#out", text) |
| 275 | + dash_duo.start_server(app) |
| 276 | + dash_duo.wait_for_text_to_equal("#out", "init") |
278 | 277 |
|
| 278 | + for children, text in outputs: |
| 279 | + dash_duo.find_element("#btn").click() |
| 280 | + dash_duo.wait_for_text_to_equal("#out", text) |
279 | 281 |
|
280 |
| -def test_cbsc006_array_of_objects(dash_duo): |
281 |
| - app = dash.Dash() |
282 |
| - app.layout = html.Div( |
283 |
| - [html.Button(id="btn"), dcc.Dropdown(id="dd"), html.Div(id="out")] |
284 |
| - ) |
285 | 282 |
|
286 |
| - @app.callback(Output("dd", "options"), [Input("btn", "n_clicks")]) |
287 |
| - def set_options(n): |
288 |
| - return [{"label": "opt{}".format(i), "value": i} for i in range(n or 0)] |
| 283 | +@pytest.mark.parametrize("engine", ["json", "orjson"]) |
| 284 | +def test_cbsc006_array_of_objects(dash_duo, engine): |
| 285 | + with json_engine(engine): |
| 286 | + app = dash.Dash() |
| 287 | + app.layout = html.Div( |
| 288 | + [html.Button(id="btn"), dcc.Dropdown(id="dd"), html.Div(id="out")] |
| 289 | + ) |
289 | 290 |
|
290 |
| - @app.callback(Output("out", "children"), [Input("dd", "options")]) |
291 |
| - def set_out(opts): |
292 |
| - print(repr(opts)) |
293 |
| - return len(opts) |
| 291 | + @app.callback(Output("dd", "options"), [Input("btn", "n_clicks")]) |
| 292 | + def set_options(n): |
| 293 | + return [{"label": "opt{}".format(i), "value": i} for i in range(n or 0)] |
294 | 294 |
|
295 |
| - dash_duo.start_server(app) |
| 295 | + @app.callback(Output("out", "children"), [Input("dd", "options")]) |
| 296 | + def set_out(opts): |
| 297 | + print(repr(opts)) |
| 298 | + return len(opts) |
296 | 299 |
|
297 |
| - dash_duo.wait_for_text_to_equal("#out", "0") |
298 |
| - for i in range(5): |
299 |
| - dash_duo.find_element("#btn").click() |
300 |
| - dash_duo.wait_for_text_to_equal("#out", str(i + 1)) |
301 |
| - dash_duo.select_dcc_dropdown("#dd", "opt{}".format(i)) |
| 300 | + dash_duo.start_server(app) |
| 301 | + |
| 302 | + dash_duo.wait_for_text_to_equal("#out", "0") |
| 303 | + for i in range(5): |
| 304 | + dash_duo.find_element("#btn").click() |
| 305 | + dash_duo.wait_for_text_to_equal("#out", str(i + 1)) |
| 306 | + dash_duo.select_dcc_dropdown("#dd", "opt{}".format(i)) |
302 | 307 |
|
303 | 308 |
|
304 | 309 | @pytest.mark.parametrize("refresh", [False, True])
|
|
0 commit comments