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

Skip to content

Unify (parametrize) test_composite across backends. #9917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,30 +81,6 @@ def test_savefig_to_stringio(format, use_log, rcParams):
buffer.close()


def test_composite_image():
# Test that figures can be saved with and without combining multiple images
# (on a single set of axes) into a single composite image.
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
Z = np.sin(Y ** 2)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(0, 3)
ax.imshow(Z, extent=[0, 1, 0, 1])
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
plt.rcParams['image.composite_image'] = True
with io.BytesIO() as ps:
fig.savefig(ps, format="ps")
ps.seek(0)
buff = ps.read()
assert buff.count(six.b(' colorimage')) == 1
plt.rcParams['image.composite_image'] = False
with io.BytesIO() as ps:
fig.savefig(ps, format="ps")
ps.seek(0)
buff = ps.read()
assert buff.count(six.b(' colorimage')) == 2


def test_patheffects():
with matplotlib.rc_context():
matplotlib.rcParams['path.effects'] = [
Expand Down
24 changes: 0 additions & 24 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,30 +63,6 @@ def test_noscale():
ax.imshow(Z, cmap='gray', interpolation='none')


def test_composite_images():
#Test that figures can be saved with and without combining multiple images
#(on a single set of axes) into a single composite image.
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
Z = np.sin(Y ** 2)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(0, 3)
ax.imshow(Z, extent=[0, 1, 0, 1])
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
plt.rcParams['image.composite_image'] = True
with BytesIO() as svg:
fig.savefig(svg, format="svg")
svg.seek(0)
buff = svg.read()
assert buff.count(six.b('<image ')) == 1
plt.rcParams['image.composite_image'] = False
with BytesIO() as svg:
fig.savefig(svg, format="svg")
svg.seek(0)
buff = svg.read()
assert buff.count(six.b('<image ')) == 2


def test_text_urls():
fig = plt.figure()

Expand Down
20 changes: 20 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def do_figimage(suppressComposite):
fig.figimage(img[:,::-1], xo=100, yo=0, origin='lower')
fig.figimage(img[::-1,::-1], xo=100, yo=100, origin='lower')


@image_comparison(baseline_images=['figimage-0'],
extensions=['png','pdf'])
def test_figimage0():
Expand Down Expand Up @@ -849,3 +850,22 @@ def test_full_invalid():
ax.imshow(x)

f.canvas.draw()


@pytest.mark.parametrize("fmt,counted",
[("ps", b" colorimage"), ("svg", b"<image")])
@pytest.mark.parametrize("composite_image,count", [(True, 1), (False, 2)])
def test_composite(fmt, counted, composite_image, count):
# Test that figures can be saved with and without combining multiple images
# (on a single set of axes) into a single composite image.
X, Y = np.meshgrid(np.arange(-5, 5, 1), np.arange(-5, 5, 1))
Z = np.sin(Y ** 2)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_xlim(0, 3)
ax.imshow(Z, extent=[0, 1, 0, 1])
ax.imshow(Z[::-1], extent=[2, 3, 0, 1])
plt.rcParams['image.composite_image'] = composite_image
buf = io.BytesIO()
fig.savefig(buf, format=fmt)
assert buf.getvalue().count(counted) == count