Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 9480ad8

Browse files
byronbyronz
authored andcommitted
♻️ refactoring data size test
1 parent e7dd243 commit 9480ad8

File tree

3 files changed

+24
-50
lines changed

3 files changed

+24
-50
lines changed

dev-requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pandas
22
xlrd
3-
flake8
3+
flake8
4+
mimesis

tests/integration/store/conftest.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ def on_click(n_clicks):
6666
yield app
6767

6868

69-
@pytest.fixture(scope="module")
70-
def fake_data():
71-
buf = ""
72-
chunk = ""
69+
@pytest.fixture(scope="session")
70+
def csv_5mb():
71+
buf, chunks = None, []
7372
limit = 5 * 1024 * 1024
7473
while sys.getsizeof(buf) <= limit:
7574
g = mimesis.Generic()
@@ -79,9 +78,7 @@ def fake_data():
7978
for _ in range(10000)
8079
)
8180
)
82-
buf += chunk
83-
84-
with open("/tmp/x.csv", "w") as fp:
85-
fp.write(buf[len(chunk):limit])
81+
chunks.append(chunk)
82+
buf = ''.join(chunks)
8683

8784
yield buf[len(chunk):limit]

tests/integration/store/test_store_data.py

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import hashlib
33
import itertools
4+
import pytest
45
import dash
56
from dash.dependencies import Input, Output, State
67
from dash.exceptions import PreventUpdate
@@ -117,64 +118,39 @@ def on_ts(ts, data):
117118
dash_duo.wait_for_text_to_equal("#output", json.dumps(nested_list))
118119

119120

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):
121123
def fingerprint(data):
122124
return hashlib.sha1(data.encode("utf-8")).hexdigest()
123125

124126
app = dash.Dash(__name__)
125127
app.layout = html.Div(
126128
[
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),
130130
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"),
134132
]
135133
)
136134

137135
@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")],
153139
)
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)
158144

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")])
167146
def on_click(n_clicks):
168147
if n_clicks is None:
169148
raise PreventUpdate
170-
return (fake_data,) * 3
149+
return csv_5mb
171150

172151
dash_duo.start_server(app)
173-
outputs = ('#mout', '#lout', '#sout')
174-
for output in outputs:
175-
assert dash_duo.find_element(output).text == 'nil'
176152

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"
180154

155+
dash_duo.find_element("#btn").click()
156+
dash_duo.wait_for_text_to_equal("#out", fingerprint(csv_5mb))

0 commit comments

Comments
 (0)