|
1 | 1 | import json
|
2 | 2 | import hashlib
|
3 | 3 | import itertools
|
| 4 | +import pytest |
4 | 5 | import dash
|
5 | 6 | from dash.dependencies import Input, Output, State
|
6 | 7 | from dash.exceptions import PreventUpdate
|
@@ -117,64 +118,39 @@ def on_ts(ts, data):
|
117 | 118 | dash_duo.wait_for_text_to_equal("#output", json.dumps(nested_list))
|
118 | 119 |
|
119 | 120 |
|
120 |
| -def test_stda003_data_size_limit(fake_data, dash_duo): |
| 121 | +@pytest.mark.parametrize("storage_type", ("memory", "local", "session")) |
| 122 | +def test_stda003_large_data_size(storage_type, csv_5mb, dash_duo): |
121 | 123 | def fingerprint(data):
|
122 | 124 | return hashlib.sha1(data.encode("utf-8")).hexdigest()
|
123 | 125 |
|
124 | 126 | app = dash.Dash(__name__)
|
125 | 127 | app.layout = html.Div(
|
126 | 128 | [
|
127 |
| - dcc.Store(id="memory", storage_type="memory"), |
128 |
| - dcc.Store(id="local", storage_type="local"), |
129 |
| - dcc.Store(id="session", storage_type="session"), |
| 129 | + dcc.Store(id=storage_type, storage_type=storage_type), |
130 | 130 | html.Button("big data", id="btn"),
|
131 |
| - html.Div(id="mout"), |
132 |
| - html.Div(id="sout"), |
133 |
| - html.Div(id="lout"), |
| 131 | + html.Div(id="out"), |
134 | 132 | ]
|
135 | 133 | )
|
136 | 134 |
|
137 | 135 | @app.callback(
|
138 |
| - [ |
139 |
| - Output("mout", "children"), |
140 |
| - Output("sout", "children"), |
141 |
| - Output("lout", "children"), |
142 |
| - ], |
143 |
| - [ |
144 |
| - Input("memory", "modified_timestamp"), |
145 |
| - Input("session", "modified_timestamp"), |
146 |
| - Input("local", "modified_timestamp"), |
147 |
| - ], |
148 |
| - [ |
149 |
| - State("memory", "data"), |
150 |
| - State("session", "data"), |
151 |
| - State("local", "data"), |
152 |
| - ], |
| 136 | + Output("out", "children"), |
| 137 | + [Input(storage_type, "modified_timestamp")], |
| 138 | + [State(storage_type, "data")], |
153 | 139 | )
|
154 |
| - def update_output(mts, sts, lts, mdata, sdata, ldata): |
155 |
| - if None in {mdata, sdata, ldata}: |
156 |
| - return ("nil",) * 3 |
157 |
| - return [fingerprint(data) for data in (mdata, sdata, ldata)] |
| 140 | + def update_output(mts, data): |
| 141 | + if data is None: |
| 142 | + return "nil" |
| 143 | + return fingerprint(data) |
158 | 144 |
|
159 |
| - @app.callback( |
160 |
| - [ |
161 |
| - Output("memory", "data"), |
162 |
| - Output("local", "data"), |
163 |
| - Output("session", "data"), |
164 |
| - ], |
165 |
| - [Input("btn", "n_clicks")], |
166 |
| - ) |
| 145 | + @app.callback(Output(storage_type, "data"), [Input("btn", "n_clicks")]) |
167 | 146 | def on_click(n_clicks):
|
168 | 147 | if n_clicks is None:
|
169 | 148 | raise PreventUpdate
|
170 |
| - return (fake_data,) * 3 |
| 149 | + return csv_5mb |
171 | 150 |
|
172 | 151 | dash_duo.start_server(app)
|
173 |
| - outputs = ('#mout', '#lout', '#sout') |
174 |
| - for output in outputs: |
175 |
| - assert dash_duo.find_element(output).text == 'nil' |
176 | 152 |
|
177 |
| - dash_duo.find_element('#btn').click() |
178 |
| - for output in outputs: |
179 |
| - dash_duo.wait_for_text_to_equal(output, fingerprint(fake_data)) |
| 153 | + assert dash_duo.find_element("#out").text == "nil" |
180 | 154 |
|
| 155 | + dash_duo.find_element("#btn").click() |
| 156 | + dash_duo.wait_for_text_to_equal("#out", fingerprint(csv_5mb)) |
0 commit comments