Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7a39ef6

Browse files
committed
TST: add testcases for some decorated plot methods
These tests need to be either included in the original test if they use the same baseline image or use a differetn baseline image. Using two different test functions and the same baseline image results in races which kill ghostscript and others when they happen to access the same image.
1 parent 77be376 commit 7a39ef6

1 file changed

Lines changed: 149 additions & 18 deletions

File tree

lib/matplotlib/tests/test_axes.py

Lines changed: 149 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
import warnings
2323
from matplotlib.cbook import IgnoredKeywordWarning
2424

25+
# Note: Some test cases are run twice: once normally and once with labeled data
26+
# These two must be defined in the same test function or need to have
27+
# different baseline images to prevent race conditions when nose runs
28+
# the tests with multiple threads.
2529

2630
@image_comparison(baseline_images=['formatter_ticker_001',
2731
'formatter_ticker_002',
@@ -274,7 +278,7 @@ def test_fill_units():
274278
fig.autofmt_xdate()
275279

276280

277-
@image_comparison(baseline_images=['single_point'])
281+
@image_comparison(baseline_images=['single_point', 'single_point'])
278282
def test_single_point():
279283
# Issue #1796: don't let lines.marker affect the grid
280284
matplotlib.rcParams['lines.marker'] = 'o'
@@ -287,6 +291,16 @@ def test_single_point():
287291
plt.subplot(212)
288292
plt.plot([1], [1], 'o')
289293

294+
# Reuse testcase from above for a labeled data test
295+
data = {'a':[0], 'b':[1]}
296+
297+
fig = plt.figure()
298+
plt.subplot(211)
299+
plt.plot('a', 'a', 'o', data=data)
300+
301+
plt.subplot(212)
302+
plt.plot('b','b', 'o', data=data)
303+
290304

291305
@image_comparison(baseline_images=['single_date'])
292306
def test_single_date():
@@ -482,7 +496,7 @@ def test_axhspan_epoch():
482496
ax.set_ylim(t0 - 5.0*dt, tf + 5.0*dt)
483497

484498

485-
@image_comparison(baseline_images=['hexbin_extent'],
499+
@image_comparison(baseline_images=['hexbin_extent', 'hexbin_extent'],
486500
remove_text=True, extensions=['png'])
487501
def test_hexbin_extent():
488502
# this test exposes sf bug 2856228
@@ -495,6 +509,14 @@ def test_hexbin_extent():
495509

496510
ax.hexbin(x, y, extent=[.1, .3, .6, .7])
497511

512+
# Reuse testcase from above for a labeled data test
513+
data = {"x": x, "y": y}
514+
515+
fig = plt.figure()
516+
ax = fig.add_subplot(111)
517+
ax.hexbin("x", "y", extent=[.1, .3, .6, .7], data=data)
518+
519+
498520
@image_comparison(baseline_images=['hexbin_empty'], remove_text=True,
499521
extensions=['png'])
500522
def test_hexbin_empty():
@@ -575,7 +597,7 @@ def test_nonfinite_limits():
575597
ax.plot(x, y)
576598

577599

578-
@image_comparison(baseline_images=['imshow'],
600+
@image_comparison(baseline_images=['imshow', 'imshow'],
579601
remove_text=True)
580602
def test_imshow():
581603
# Create a NxN image
@@ -591,6 +613,12 @@ def test_imshow():
591613

592614
ax.imshow(r)
593615

616+
# Reuse testcase from above for a labeled data test
617+
data={"r": r}
618+
fig = plt.figure()
619+
ax = fig.add_subplot(111)
620+
ax.imshow("r", data=data)
621+
594622

595623
@image_comparison(baseline_images=['imshow_clip'])
596624
def test_imshow_clip():
@@ -1011,13 +1039,21 @@ def test_marker_edges():
10111039
ax.plot(x+0.2, np.sin(x), 'y.', ms=30.0, mew=2, mec='b')
10121040

10131041

1014-
@image_comparison(baseline_images=['bar_tick_label_single'],
1042+
@image_comparison(baseline_images=['bar_tick_label_single',
1043+
'bar_tick_label_single'],
10151044
extensions=['png'])
10161045
def test_bar_tick_label_single():
10171046
# From 2516: plot bar with array of string labels for x axis
10181047
ax = plt.gca()
10191048
ax.bar(0, 1 , tick_label='a')
10201049

1050+
# Reuse testcase from above for a labeled data test
1051+
data = {"a": 0, "b": 1}
1052+
fig = plt.figure()
1053+
ax = fig.add_subplot(111)
1054+
ax = plt.gca()
1055+
ax.bar("a", "b" , tick_label='a', data=data)
1056+
10211057

10221058
@image_comparison(baseline_images=['bar_tick_label_multiple'],
10231059
extensions=['png'])
@@ -1147,7 +1183,7 @@ def test_contour_colorbar():
11471183
cbar.add_lines(cs2, erase=False)
11481184

11491185

1150-
@image_comparison(baseline_images=['hist2d'])
1186+
@image_comparison(baseline_images=['hist2d', 'hist2d'])
11511187
def test_hist2d():
11521188
np.random.seed(0)
11531189
# make it not symetric in case we switch x and y axis
@@ -1157,6 +1193,12 @@ def test_hist2d():
11571193
ax = fig.add_subplot(111)
11581194
ax.hist2d(x, y, bins=10)
11591195

1196+
# Reuse testcase from above for a labeled data test
1197+
data = {"x": x, "y": y}
1198+
fig = plt.figure()
1199+
ax = fig.add_subplot(111)
1200+
ax.hist2d("x", "y", bins=10, data=data)
1201+
11601202

11611203
@image_comparison(baseline_images=['hist2d_transpose'])
11621204
def test_hist2d_transpose():
@@ -1170,11 +1212,17 @@ def test_hist2d_transpose():
11701212
ax.hist2d(x, y, bins=10)
11711213

11721214

1173-
@image_comparison(baseline_images=['scatter'])
1215+
@image_comparison(baseline_images=['scatter', 'scatter'])
11741216
def test_scatter_plot():
11751217
ax = plt.axes()
1176-
ax.scatter([3, 4, 2, 6], [2, 5, 2, 3],
1177-
c=['r', 'y', 'b', 'lime'], s=[24, 15, 19, 29])
1218+
data = {"x": [3, 4, 2, 6], "y": [2, 5, 2, 3], "c": ['r', 'y', 'b', 'lime'],
1219+
"s": [24, 15, 19, 29]}
1220+
1221+
ax.scatter(data["x"], data["y"], c=data["c"], s=data["s"])
1222+
1223+
# Reuse testcase from above for a labeled data test
1224+
ax = plt.axes()
1225+
ax.scatter("x", "y", c="c", s="s", data=data)
11781226

11791227

11801228
@image_comparison(baseline_images=['scatter_marker'], remove_text=True,
@@ -1252,7 +1300,8 @@ def test_log_scales():
12521300
ax.set_xscale('log', basex=9.0)
12531301

12541302

1255-
@image_comparison(baseline_images=['stackplot_test_image'])
1303+
@image_comparison(baseline_images=['stackplot_test_image',
1304+
'stackplot_test_image'])
12561305
def test_stackplot():
12571306
fig = plt.figure()
12581307
x = np.linspace(0, 10, 10)
@@ -1264,6 +1313,14 @@ def test_stackplot():
12641313
ax.set_xlim((0, 10))
12651314
ax.set_ylim((0, 70))
12661315

1316+
# Reuse testcase from above for a labeled data test
1317+
data={"x": x, "y1": y1, "y2": y2, "y3": y3}
1318+
fig = plt.figure()
1319+
ax = fig.add_subplot(1, 1, 1)
1320+
ax.stackplot("x", "y1", "y2", "y3", data=data)
1321+
ax.set_xlim((0, 10))
1322+
ax.set_ylim((0, 70))
1323+
12671324

12681325
@image_comparison(baseline_images=['stackplot_test_baseline'],
12691326
remove_text=True)
@@ -1646,7 +1703,7 @@ def test_bxp_bad_positions():
16461703
assert_raises(ValueError, ax.bxp, logstats, positions=[2, 3])
16471704

16481705

1649-
@image_comparison(baseline_images=['boxplot'])
1706+
@image_comparison(baseline_images=['boxplot', 'boxplot'])
16501707
def test_boxplot():
16511708
x = np.linspace(-7, 7, 140)
16521709
x = np.hstack([-25, x, 25])
@@ -1655,6 +1712,12 @@ def test_boxplot():
16551712
ax.boxplot([x, x], bootstrap=10000, notch=1)
16561713
ax.set_ylim((-30, 30))
16571714

1715+
# Reuse testcase from above for a labeled data test
1716+
data={"x": [x, x]}
1717+
fig, ax = plt.subplots()
1718+
ax.boxplot("x", bootstrap=10000, notch=1, data=data)
1719+
ax.set_ylim((-30, 30))
1720+
16581721

16591722
@image_comparison(baseline_images=['boxplot_sym2'],
16601723
remove_text=True, extensions=['png'])
@@ -1834,7 +1897,8 @@ def test_boxplot_mod_artist_after_plotting():
18341897
obj.set_color('green')
18351898

18361899

1837-
@image_comparison(baseline_images=['violinplot_vert_baseline'],
1900+
@image_comparison(baseline_images=['violinplot_vert_baseline',
1901+
'violinplot_vert_baseline'],
18381902
extensions=['png'])
18391903
def test_vert_violinplot_baseline():
18401904
# First 9 digits of frac(sqrt(2))
@@ -1844,6 +1908,13 @@ def test_vert_violinplot_baseline():
18441908
ax.violinplot(data, positions=range(4), showmeans=0, showextrema=0,
18451909
showmedians=0)
18461910

1911+
# Reuse testcase from above for a labeled data test
1912+
data = {"d": data}
1913+
fig, ax = plt.subplots()
1914+
ax = plt.axes()
1915+
ax.violinplot("d", positions=range(4), showmeans=0, showextrema=0,
1916+
showmedians=0, data=data)
1917+
18471918

18481919
@image_comparison(baseline_images=['violinplot_vert_showmeans'],
18491920
extensions=['png'])
@@ -2021,7 +2092,8 @@ def test_manage_xticks():
20212092
assert_array_equal(old_xlim, new_xlim)
20222093

20232094

2024-
@image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed'])
2095+
@image_comparison(baseline_images=['errorbar_basic', 'errorbar_mixed',
2096+
'errorbar_basic'])
20252097
def test_errorbar():
20262098
x = np.arange(0.1, 4, 0.5)
20272099
y = np.exp(-x)
@@ -2065,6 +2137,15 @@ def test_errorbar():
20652137

20662138
fig.suptitle('Variable errorbars')
20672139

2140+
2141+
# Reuse te first testcase from above for a labeled data test
2142+
data = {"x": x, "y": y}
2143+
fig = plt.figure()
2144+
ax = fig.gca()
2145+
ax.errorbar("x", "y", xerr=0.2, yerr=0.4, data=data)
2146+
ax.set_title("Simplest errorbars, 0.2 in x, 0.4 in y")
2147+
2148+
20682149
@cleanup
20692150
def test_errorbar_shape():
20702151
fig = plt.figure()
@@ -2129,7 +2210,8 @@ def test_errorbar_limits():
21292210
ax.set_title('Errorbar upper and lower limits')
21302211

21312212

2132-
@image_comparison(baseline_images=['hist_stacked_stepfilled'])
2213+
@image_comparison(baseline_images=['hist_stacked_stepfilled',
2214+
'hist_stacked_stepfilled'])
21332215
def test_hist_stacked_stepfilled():
21342216
# make some data
21352217
d1 = np.linspace(1, 3, 20)
@@ -2138,6 +2220,12 @@ def test_hist_stacked_stepfilled():
21382220
ax = fig.add_subplot(111)
21392221
ax.hist((d1, d2), histtype="stepfilled", stacked=True)
21402222

2223+
# Reuse testcase from above for a labeled data test
2224+
data = {"x": (d1, d2)}
2225+
fig = plt.figure()
2226+
ax = fig.add_subplot(111)
2227+
ax.hist("x", histtype="stepfilled", stacked=True, data=data)
2228+
21412229

21422230
@image_comparison(baseline_images=['hist_offset'])
21432231
def test_hist_offset():
@@ -2386,7 +2474,7 @@ def test_alpha():
23862474
markersize=20, lw=10)
23872475

23882476

2389-
@image_comparison(baseline_images=['eventplot'], remove_text=True)
2477+
@image_comparison(baseline_images=['eventplot', 'eventplot'], remove_text=True)
23902478
def test_eventplot():
23912479
'''
23922480
test that eventplot produces the correct output
@@ -2423,6 +2511,15 @@ def test_eventplot():
24232511
num_collections = len(colls)
24242512
np.testing.assert_equal(num_collections, num_datasets)
24252513

2514+
# Reuse testcase from above for a labeled data test
2515+
data = {"pos": data, "c": colors, "lo": lineoffsets, "ll": linelengths}
2516+
fig = plt.figure()
2517+
axobj = fig.add_subplot(111)
2518+
colls = axobj.eventplot("pos", colors="c", lineoffsets="lo",
2519+
linelengths="ll", data=data)
2520+
num_collections = len(colls)
2521+
np.testing.assert_equal(num_collections, num_datasets)
2522+
24262523

24272524
@image_comparison(baseline_images=['test_eventplot_defaults'], extensions=['png'], remove_text=True)
24282525
def test_eventplot_defaults():
@@ -2543,7 +2640,8 @@ def test_eb_line_zorder():
25432640
ax.set_title("errorbar zorder test")
25442641

25452642

2546-
@image_comparison(baseline_images=['step_linestyle'], remove_text=True)
2643+
@image_comparison(baseline_images=['step_linestyle', 'step_linestyle'],
2644+
remove_text=True)
25472645
def test_step_linestyle():
25482646
x = y = np.arange(10)
25492647

@@ -2560,6 +2658,18 @@ def test_step_linestyle():
25602658
ax.set_xlim([-1, 5])
25612659
ax.set_ylim([-1, 7])
25622660

2661+
# Reuse testcase from above for a labeled data test
2662+
data = {"x": x, "y": y, "y1": y+1, "y2": y+2}
2663+
fig, ax_lst = plt.subplots(2, 2)
2664+
ax_lst = ax_lst.flatten()
2665+
ln_styles = ['-', '--', '-.', ':']
2666+
for ax, ls in zip(ax_lst, ln_styles):
2667+
ax.step("x", "y", lw=5, linestyle=ls, where='pre', data=data)
2668+
ax.step("x", "y1", lw=5, linestyle=ls, where='mid', data=data)
2669+
ax.step("x", "y2", lw=5, linestyle=ls, where='post', data=data)
2670+
ax.set_xlim([-1, 5])
2671+
ax.set_ylim([-1, 7])
2672+
25632673

25642674
@image_comparison(baseline_images=['mixed_collection'], remove_text=True)
25652675
def test_mixed_collection():
@@ -3501,8 +3611,8 @@ def make_patch_spines_invisible(ax):
35013611
host.tick_params(axis='x', **tkw)
35023612

35033613

3504-
@image_comparison(baseline_images=['twin_spines_on_top'], extensions=['png'],
3505-
remove_text=True)
3614+
@image_comparison(baseline_images=['twin_spines_on_top', 'twin_spines_on_top'],
3615+
extensions=['png'], remove_text=True)
35063616
def test_twin_spines_on_top():
35073617
matplotlib.rcParams['axes.linewidth'] = 48.0
35083618
matplotlib.rcParams['lines.linewidth'] = 48.0
@@ -3521,6 +3631,16 @@ def test_twin_spines_on_top():
35213631
ax2.plot(data[0], data[1]/1E3, color='#7FC97F')
35223632
ax2.fill_between(data[0], data[1]/1E3, color='#7FC97F', alpha=.5)
35233633

3634+
# Reuse testcase from above for a labeled data test
3635+
data = {"x": data[0], "y": data[1]/1E3}
3636+
fig = plt.figure()
3637+
ax1 = fig.add_subplot(1, 1, 1)
3638+
ax2 = ax1.twinx()
3639+
ax1.plot("x", "y", color='#BEAED4', data=data)
3640+
ax1.fill_between("x", "y", color='#BEAED4', alpha=.8, data=data)
3641+
ax2.plot("x", "y", color='#7FC97F', data=data)
3642+
ax2.fill_between("x", "y", color='#7FC97F', alpha=.5, data=data)
3643+
35243644

35253645
@cleanup
35263646
def test_rcparam_grid_minor():
@@ -3606,7 +3726,8 @@ def test_text_labelsize():
36063726
ax.tick_params(direction='out')
36073727

36083728

3609-
@image_comparison(baseline_images=['pie_linewidth_0'], extensions=['png'])
3729+
@image_comparison(baseline_images=['pie_linewidth_0', 'pie_linewidth_0'],
3730+
extensions=['png'])
36103731
def test_pie_linewidth_0():
36113732
# The slices will be ordered and plotted counter-clockwise.
36123733
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
@@ -3620,6 +3741,16 @@ def test_pie_linewidth_0():
36203741
# Set aspect ratio to be equal so that pie is drawn as a circle.
36213742
plt.axis('equal')
36223743

3744+
# Reuse testcase from above for a labeled data test
3745+
data = {"l": labels, "s": sizes, "c": colors, "ex": explode}
3746+
# FIXME: Workaround until the pyplot is regenerated
3747+
fig = plt.figure()
3748+
ax = fig.gca()
3749+
ax.pie("s", explode="ex", labels="l", colors="c",
3750+
autopct='%1.1f%%', shadow=True, startangle=90,
3751+
wedgeprops={'linewidth': 0}, data=data)
3752+
ax.axis('equal')
3753+
36233754

36243755
@image_comparison(baseline_images=['pie_center_radius'], extensions=['png'])
36253756
def test_pie_center_radius():

0 commit comments

Comments
 (0)