|
3 | 3 | from multiprocessing import Value
|
4 | 4 | import time
|
5 | 5 |
|
| 6 | + |
6 | 7 | def test_sp001_clientside_setprops(dash_duo):
|
7 | 8 |
|
8 | 9 | call_count = Value("i", 0)
|
9 | 10 |
|
10 | 11 | app = Dash(__name__)
|
11 | 12 |
|
12 |
| - ids = [{'id': {'index': '1', 'type': 'test'}, 'children': ['rawr']}, {'id': 'two', 'children': 'this is a test'}, {'id': 'three', 'children': 'i see trees of green'}] |
| 13 | + ids = [ |
| 14 | + {"id": {"index": "1", "type": "test"}, "children": ["rawr"]}, |
| 15 | + {"id": "two", "children": "this is a test"}, |
| 16 | + {"id": "three", "children": "i see trees of green"}, |
| 17 | + ] |
13 | 18 |
|
14 |
| - app.layout = html.Div([*[html.Div(id=x['id']) for x in ids], html.Div(id='four'), html.Button(id='setup', children='test setprops')]) |
| 19 | + app.layout = html.Div( |
| 20 | + [ |
| 21 | + *[html.Div(id=x["id"]) for x in ids], |
| 22 | + html.Div(id="four"), |
| 23 | + html.Button(id="setup", children="test setprops"), |
| 24 | + ] |
| 25 | + ) |
15 | 26 |
|
16 | 27 | app.clientside_callback(
|
17 | 28 | """
|
18 | 29 | () => {
|
19 |
| - window.dash_clientside.setProps(""" + json.dumps(ids) + """) |
| 30 | + window.dash_clientside.setProps(""" |
| 31 | + + json.dumps(ids) |
| 32 | + + """) |
20 | 33 | return window.dash_clientside.no_update
|
21 | 34 | }
|
22 | 35 | """,
|
23 |
| - Output('setup', 'id'), |
24 |
| - Input('setup', 'n_clicks'), |
25 |
| - prevent_initial_call=True |
| 36 | + Output("setup", "id"), |
| 37 | + Input("setup", "n_clicks"), |
| 38 | + prevent_initial_call=True, |
26 | 39 | )
|
27 | 40 |
|
28 | 41 | for x in ids:
|
29 |
| - @app.callback(Output(x['id'],'id', allow_duplicate=True), Output('four','children', allow_duplicate=True), Input(x['id'], 'children'), |
30 |
| - State(x['id'], 'id'), prevent_initial_call=True) |
| 42 | + |
| 43 | + @app.callback( |
| 44 | + Output(x["id"], "id", allow_duplicate=True), |
| 45 | + Output("four", "children", allow_duplicate=True), |
| 46 | + Input(x["id"], "children"), |
| 47 | + State(x["id"], "id"), |
| 48 | + prevent_initial_call=True, |
| 49 | + ) |
31 | 50 | def prinout(c, id):
|
32 | 51 | call_count.value += 1
|
33 | 52 | for y in ids:
|
34 |
| - if y['id'] == id: |
35 |
| - assert y['children'] == c |
| 53 | + if y["id"] == id: |
| 54 | + assert y["children"] == c |
36 | 55 | return no_update, call_count.value
|
37 | 56 |
|
38 | 57 | dash_duo.start_server(app)
|
39 | 58 |
|
40 |
| - dash_duo.wait_for_text_to_equal("#setup", 'test setprops') |
| 59 | + dash_duo.wait_for_text_to_equal("#setup", "test setprops") |
41 | 60 | dash_duo.find_element("#setup").click()
|
42 | 61 | time.sleep(1)
|
43 |
| - dash_duo.wait_for_text_to_equal("#two", 'this is a test') |
44 |
| - dash_duo.wait_for_text_to_equal("#three", 'i see trees of green') |
45 |
| - dash_duo.wait_for_text_to_equal("#four", '3') |
| 62 | + dash_duo.wait_for_text_to_equal("#two", "this is a test") |
| 63 | + dash_duo.wait_for_text_to_equal("#three", "i see trees of green") |
| 64 | + dash_duo.wait_for_text_to_equal("#four", "3") |
0 commit comments