Skip to content

Commit f3039ac

Browse files
parameterize test_px
1 parent dff2c11 commit f3039ac

File tree

1 file changed

+36
-37
lines changed
  • packages/python/plotly/plotly/tests/test_core/test_px

1 file changed

+36
-37
lines changed

packages/python/plotly/plotly/tests/test_core/test_px/test_px.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import plotly.express as px
22
import numpy as np
33
import pytest
4+
from itertools import permutations
45

56

67
def test_scatter():
@@ -185,54 +186,52 @@ def test_px_templates():
185186
assert fig.layout.yaxis3.showgrid
186187

187188

188-
def test_orthogonal_orderings():
189-
from itertools import permutations
190-
191-
df = px.data.tips()
192-
189+
def assert_orderings(days_order, days_check, times_order, times_check):
193190
symbol_sequence = ["circle", "diamond", "square", "cross"]
194191
color_sequence = ["red", "blue"]
192+
fig = px.scatter(
193+
px.data.tips(),
194+
x="total_bill",
195+
y="tip",
196+
facet_row="time",
197+
facet_col="day",
198+
color="time",
199+
symbol="day",
200+
symbol_sequence=symbol_sequence,
201+
color_discrete_sequence=color_sequence,
202+
category_orders=dict(day=days_order, time=times_order),
203+
)
204+
205+
for col in range(len(days_check)):
206+
for trace in fig.select_traces(col=col + 1):
207+
assert days_check[col] in trace.hovertemplate
195208

196-
def assert_orderings(days_order, days_check, times_order, times_check):
197-
fig = px.scatter(
198-
df,
199-
x="total_bill",
200-
y="tip",
201-
facet_row="time",
202-
facet_col="day",
203-
color="time",
204-
symbol="day",
205-
symbol_sequence=symbol_sequence,
206-
color_discrete_sequence=color_sequence,
207-
category_orders=dict(day=days_order, time=times_order),
208-
)
209-
210-
for col in range(len(days_check)):
211-
for trace in fig.select_traces(col=col + 1):
212-
assert days_check[col] in trace.hovertemplate
213-
214-
for row in range(len(times_check)):
215-
for trace in fig.select_traces(row=2 - row):
216-
assert times_check[row] in trace.hovertemplate
217-
218-
for trace in fig.data:
219-
for i, day in enumerate(days_check):
220-
if day in trace.name:
221-
assert trace.marker.symbol == symbol_sequence[i]
222-
for i, time in enumerate(times_check):
223-
if time in trace.name:
224-
assert trace.marker.color == color_sequence[i]
209+
for row in range(len(times_check)):
210+
for trace in fig.select_traces(row=2 - row):
211+
assert times_check[row] in trace.hovertemplate
225212

213+
for trace in fig.data:
214+
for i, day in enumerate(days_check):
215+
if day in trace.name:
216+
assert trace.marker.symbol == symbol_sequence[i]
217+
for i, time in enumerate(times_check):
218+
if time in trace.name:
219+
assert trace.marker.color == color_sequence[i]
220+
221+
222+
def test_noisy_orthogonal_orderings():
226223
assert_orderings(
227224
["x", "Sun", "Sat", "y", "Fri", "z"], # add extra noise, missing Thur
228225
["Sun", "Sat", "Fri", "Thur"], # Thur is at the back
229226
["a", "Lunch", "b"], # add extra noise, missing Dinner
230227
["Lunch", "Dinner"], # Dinner is at the back
231228
)
232229

233-
for days in permutations(df["day"].unique()):
234-
for times in permutations(df["time"].unique()):
235-
assert_orderings(days, days, times, times)
230+
231+
@pytest.mark.parametrize("days", permutations(["Sun", "Sat", "Fri", "Thur"]))
232+
@pytest.mark.parametrize("times", permutations(["Lunch", "Dinner"]))
233+
def test_orthogonal_orderings(days, times):
234+
assert_orderings(days, days, times, times)
236235

237236

238237
def test_permissive_defaults():

0 commit comments

Comments
 (0)