Skip to content

Commit 1b06d3a

Browse files
committed
added tests
1 parent 1916166 commit 1b06d3a

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import plotly.express as px
2+
import plotly.graph_objects as go
3+
from numpy.testing import assert_array_equal
4+
5+
def _compare_figures(go_trace, px_fig):
6+
"""Compare a figure created with a go trace and a figure created with
7+
a px function call. Check that all values inside the go Figure are the
8+
same in the px figure (which sets more parameters).
9+
"""
10+
go_fig = go.Figure(go_trace)
11+
go_fig = go_fig.to_plotly_json()
12+
px_fig = px_fig.to_plotly_json()
13+
del go_fig["layout"]["template"]
14+
del px_fig["layout"]["template"]
15+
for key in go_fig['data'][0]:
16+
assert_array_equal(go_fig['data'][0][key], px_fig['data'][0][key])
17+
for key in go_fig['layout']:
18+
assert go_fig['layout'][key] == px_fig['layout'][key]
19+
20+
21+
def test_pie_like_px():
22+
# Pie
23+
labels = ['Oxygen','Hydrogen','Carbon_Dioxide','Nitrogen']
24+
values = [4500, 2500, 1053, 500]
25+
26+
fig = px.pie(names=labels, values=values)
27+
trace = go.Pie(labels=labels, values=values)
28+
_compare_figures(trace, fig)
29+
30+
labels = ["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"]
31+
parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve" ]
32+
values = [10, 14, 12, 10, 2, 6, 6, 4, 4]
33+
# Sunburst
34+
fig = px.sunburst(names=labels, parents=parents, values=values)
35+
trace = go.Sunburst(labels=labels, parents=parents, values=values)
36+
_compare_figures(trace, fig)
37+
# Treemap
38+
fig = px.treemap(names=labels, parents=parents, values=values)
39+
trace = go.Treemap(labels=labels, parents=parents, values=values)
40+
_compare_figures(trace, fig)
41+
42+
# Funnel
43+
x = ['A', 'B', 'C']
44+
y = [3, 2, 1]
45+
fig = px.funnel(y=y, x=x)
46+
trace = go.Funnel(y=y, x=x)
47+
_compare_figures(trace, fig)
48+
# Funnelarea
49+
fig = px.funnel_area(values=y, names=x)
50+
trace = go.Funnelarea(values=y, labels=x)
51+
_compare_figures(trace, fig)
52+

0 commit comments

Comments
 (0)