8000 Replace some image_comparisons by return-value-tests/check_figures_eq… · matplotlib/matplotlib@73e4eab · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 73e4eab

Browse files
committed
Replace some image_comparisons by return-value-tests/check_figures_equal.
1 parent 49609c3 commit 73e4eab

File tree

5 files changed

+35
-31
lines changed

5 files changed

+35
-31
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 5 deletions

lib/matplotlib/tests/test_pickle.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5787,18 +5787,21 @@ def test_adjust_numtick_aspect():
57875787
assert len(ax.yaxis.get_major_locator()()) > 2
57885788

57895789

5790-
@image_comparison(["auto_numticks.png"], style='default')
5790+
@mpl.style.context("default")
57915791
def test_auto_numticks():
5792-
# Make tiny, empty subplots, verify that there are only 3 ticks.
5793-
plt.subplots(4, 4)
5792+
axs = plt.figure().subplots(4, 4)
5793+
for ax in axs.flat: # Tiny, empty subplots have only 3 ticks.
5794+
assert [*ax.get_xticks()] == [*ax.get_yticks()] == [0, 0.5, 1]
57945795

57955796

5796-
@image_comparison(["auto_numticks_log.png"], style='default')
5797+
@mpl.style.context("default")
57975798
def test_auto_numticks_log():
57985799
# Verify that there are not too many ticks with a large log range.
57995800
fig, ax = plt.subplots()
5800-
matplotlib.rcParams['axes.autolimit_mode'] = 'round_numbers'
5801+
mpl.rcParams['axes.autolimit_mode'] = 'round_numbers'
58015802
ax.loglog([1e-20, 1e5], [1e-16, 10])
5803+
assert (np.log10(ax.get_xticks()) == np.arange(-26, 18, 4)).all()
5804+
assert (np.log10(ax.get_yticks()) == np.arange(-20, 10, 3)).all()
58025805

58035806

58045807
def test_broken_barh_empty():
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import numpy as np
55
import pytest
66

7+
import matplotlib as mpl
78
from matplotlib import cm
8-
from matplotlib.testing.decorators import image_comparison
9+
from matplotlib.testing.decorators import check_figures_equal
910
from matplotlib.dates import rrulewrapper
1011
import matplotlib.pyplot as plt
1112
import matplotlib.transforms as mtransforms
@@ -40,13 +41,11 @@ def test_simple():
4041
pickle.dump(fig, BytesIO(), pickle.HIGHEST_PROTOCOL)
4142

4243

43-
@image_comparison(
44-
['multi_pickle.png'], remove_text=True, style='mpl20', tol=0.082)
45-
def test_complete():
46-
# Remove this line when this test image is regenerated.
47-
plt.rcParams['pcolormesh.snap'] = False
48-
49-
fig = plt.figure('Figure with a label?', figsize=(10, 6))
44+
@mpl.style.context("default")
45+
@check_figures_equal(extensions=["png"])
46+
def test_complete(fig_test, fig_ref):
47+
fig_ref.set_size_inches((10, 6))
48+
plt.figure(fig_ref)
5049

5150
plt.suptitle('Can you fit any more in a figure?')
5251

@@ -89,25 +88,27 @@ def test_complete():
8988
plt.subplot(3, 3, 9)
9089
plt.errorbar(x, x * -0.5, xerr=0.2, yerr=0.4)
9190

92-
#
9391
# plotting is done, now test its pickle-ability
94-
#
95-
result_fh = BytesIO()
96-
pickle.dump(fig, result_fh, pickle.HIGHEST_PROTOCOL)
97-
98-
plt.close('all')
99-
100-
# make doubly sure that there are no figures left
101-
assert plt._pylab_helpers.Gcf.figs == {}
102-
103-
# wind back the fh and load in the figure
104-
result_fh.seek(0)
105-
fig = pickle.load(result_fh)
106-
107-
# make sure there is now a figure manager
108-
assert plt._pylab_helpers.Gcf.figs != {}
109-
110-
assert fig.get_label() == 'Figure with a label?'
92+
pkl = BytesIO()
93+
pickle.dump(fig_ref, pkl, pickle.HIGHEST_PROTOCOL)
94+
loaded = pickle.loads(pkl.getbuffer())
95+
loaded.canvas.draw()
96+
97+
fig_test.set_size_inches(loaded.get_size_inches())
98+
fig_test.figimage(loaded.canvas.renderer.buffer_rgba())
99+
100+
plt.close(loaded)
101+
102+
103+
def test_gcf():
104+
fig = plt.figure("a label")
105+
buf = BytesIO()
106+
pickle.dump(fig, buf, pickle.HIGHEST_PROTOCOL)
107+
plt.close("all")
108+
assert plt._pylab_helpers.Gcf.figs == {} # No figures must be left.
109+
fig = pickle.loads(buf.getbuffer())
110+
assert plt._pylab_helpers.Gcf.figs != {} # A manager is there again.
111+
assert fig.get_label() == "a label"
111112

112113

113114
def test_no_pyplot():

0 commit comments

Comments
 (0)
0