Skip to content

Commit 98dfc0d

Browse files
committed
Unify (parametrize) test_composite across backends.
1 parent 6336f2d commit 98dfc0d

File tree

3 files changed

+20
-48
lines changed

3 files changed

+20
-48
lines changed

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,30 +81,6 @@ def test_savefig_to_stringio(format, use_log, rcParams):
8181
buffer.close()
8282

8383

84-
def test_composite_image():
85-
# Test that figures can be saved with and without combining multiple images
86-
# (on a single set of axes) into a single composite image.
87-
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
88-
Z = np.sin(Y ** 2)
89-
fig = plt.figure()
90-
ax = fig.add_subplot(1, 1, 1)
91-
ax.set_xlim(0, 3)
92-
ax.imshow(Z, extent=[0, 1, 0, 1])
93-
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
94-
plt.rcParams['image.composite_image'] = True
95-
with io.BytesIO() as ps:
96-
fig.savefig(ps, format="ps")
97-
ps.seek(0)
98-
buff = ps.read()
99-
assert buff.count(six.b(' colorimage')) == 1
100-
plt.rcParams['image.composite_image'] = False
101-
with io.BytesIO() as ps:
102-
fig.savefig(ps, format="ps")
103-
ps.seek(0)
104-
buff = ps.read()
105-
assert buff.count(six.b(' colorimage')) == 2
106-
107-
10884
def test_patheffects():
10985
with matplotlib.rc_context():
11086
matplotlib.rcParams['path.effects'] = [

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -63,30 +63,6 @@ def test_noscale():
6363
ax.imshow(Z, cmap='gray', interpolation='none')
6464

6565

66-
def test_composite_images():
67-
#Test that figures can be saved with and without combining multiple images
68-
#(on a single set of axes) into a single composite image.
69-
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
70-
Z = np.sin(Y ** 2)
71-
fig = plt.figure()
72-
ax = fig.add_subplot(1, 1, 1)
73-
ax.set_xlim(0, 3)
74-
ax.imshow(Z, extent=[0, 1, 0, 1])
75-
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
76-
plt.rcParams['image.composite_image'] = True
77-
with BytesIO() as svg:
78-
fig.savefig(svg, format="svg")
79-
svg.seek(0)
80-
buff = svg.read()
81-
assert buff.count(six.b('<image ')) == 1
82-
plt.rcParams['image.composite_image'] = False
83-
with BytesIO() as svg:
84-
fig.savefig(svg, format="svg")
85-
svg.seek(0)
86-
buff = svg.read()
87-
assert buff.count(six.b('<image ')) == 2
88-
89-
9066
def test_text_urls():
9167
fig = plt.figure()
9268

lib/matplotlib/tests/test_image.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def do_figimage(suppressComposite):
8686
fig.figimage(img[:,::-1], xo=100, yo=0, origin='lower')
8787
fig.figimage(img[::-1,::-1], xo=100, yo=100, origin='lower')
8888

89+
8990
@image_comparison(baseline_images=['figimage-0'],
9091
extensions=['png','pdf'])
9192
def test_figimage0():
@@ -849,3 +850,22 @@ def test_full_invalid():
849850
ax.imshow(x)
850851

851852
f.canvas.draw()
853+
854+
855+
@pytest.mark.parametrize("fmt,counted",
856+
[("ps", b" colorimage"), ("svg", b"<image")])
857+
@pytest.mark.parametrize("composite_image,count", [(True, 1), (False, 2)])
858+
def test_composite(fmt, counted, composite_image, count):
859+
# Test that figures can be saved with and without combining multiple images
860+
# (on a single set of axes) into a single composite image.
861+
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
862+
Z = np.sin(Y ** 2)
863+
fig = plt.figure()
864+
ax = fig.add_subplot(1, 1, 1)
865+
ax.set_xlim(0, 3)
866+
ax.imshow(Z, extent=[0, 1, 0, 1])
867+
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
868+
plt.rcParams['image.composite_image'] = composite_image
869+
buf = io.BytesIO()
870+
fig.savefig(buf, format=fmt)
871+
assert buf.getvalue().count(counted) == count

0 commit comments

Comments
 (0)