This repository was archived by the owner on Jun 3, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathtest_graph_basics.py
137 lines (117 loc) · 4 KB
/
test_graph_basics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import pytest
import pandas as pd
from multiprocessing import Value
import numpy as np
from time import sleep
import dash
import dash_html_components as html
import dash_core_components as dcc
from dash.dependencies import Input, Output
import dash.testing.wait as wait
@pytest.mark.parametrize("is_eager", [True, False])
def test_grbs001_graph_without_ids(dash_dcc, is_eager):
app = dash.Dash(__name__, eager_loading=is_eager)
app.layout = html.Div(
[
dcc.Graph(className="graph-no-id-1"),
dcc.Graph(className="graph-no-id-2"),
]
)
dash_dcc.start_server(app)
assert not dash_dcc.wait_for_element(".graph-no-id-1").get_attribute(
"id"
), "the graph should contain no more auto-generated id"
assert not dash_dcc.wait_for_element(".graph-no-id-2").get_attribute(
"id"
), "the graph should contain no more auto-generated id"
@pytest.mark.DCC608
@pytest.mark.parametrize("is_eager", [True, False])
def test_grbs002_wrapped_graph_has_no_infinite_loop(dash_dcc, is_eager):
df = pd.DataFrame(np.random.randn(50, 50))
figure = {
"data": [
{"x": df.columns, "y": df.index, "z": df.values, "type": "heatmap"}
],
"layout": {"xaxis": {"scaleanchor": "y"}},
}
app = dash.Dash(__name__, eager_loading=is_eager)
app.layout = html.Div(
style={
"backgroundColor": "red",
"height": "100vmin",
"width": "100vmin",
"overflow": "hidden",
"position": "relative",
},
children=[
dcc.Loading(
children=[
dcc.Graph(
id="graph",
figure=figure,
style={
"position": "absolute",
"top": 0,
"left": 0,
"backgroundColor": "blue",
"width": "100%",
"height": "100%",
"overflow": "hidden",
},
)
]
)
],
)
call_count = Value("i", 0)
@app.callback(Output("graph", "figure"), [Input("graph", "relayoutData")])
def selected_df_figure(selection):
call_count.value += 1
figure["data"][0]["x"] = df.columns
figure["data"][0]["y"] = df.index
figure["data"][0]["z"] = df.values
return figure
dash_dcc.start_server(app)
wait.until(lambda: dash_dcc.driver.title == "Dash", timeout=2)
sleep(1)
# TODO: not sure 2 calls actually makes sense here, shouldn't it be 1?
# but that's what we had as of the 608 fix, PR 621, so let's lock that
# in for now.
assert call_count.value == 2
@pytest.mark.DCC672
def test_grbs002_graph_wrapped_in_loading_component_does_not_fail(dash_dcc):
app = dash.Dash(__name__, suppress_callback_exceptions=True)
app.layout = html.Div([
html.H1('subplot issue'),
dcc.Location(id='url', refresh=False),
dcc.Loading(id="page-content")
])
@app.callback(Output('page-content', 'children'), [Input('url', 'value')])
def render_page(url):
return [
dcc.Dropdown(
id='my-dropdown',
options=[
{'label': 'option 1', 'value': '1'},
{'label': 'option 2', 'value': '2'}
],
value='1'
),
dcc.Graph(id='my-graph')
]
@app.callback(Output('my-graph', 'figure'), [Input('my-dropdown', 'value')])
def update_graph(value):
values = [1, 2, 3]
ranges = [1, 2, 3]
return {
'data': [{
'x': ranges,
'y': values,
'line': {
'shape': 'spline'
}
}],
}
dash_dcc.start_server(app)
dash_dcc.wait_for_element('#my-graph .main-svg')
assert not dash_dcc.get_logs()