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

Skip to content

TST: Add test for _repr_html_ #18501

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 4 commits into from
Sep 22, 2020
Merged
Changes from 1 commit
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
66 changes: 49 additions & 17 deletions lib/matplotlib/tests/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import pytest

import matplotlib as mpl
from matplotlib import pyplot as plt
from matplotlib import pyplot as plt, rc_context
from matplotlib import animation


Expand Down Expand Up @@ -136,27 +136,14 @@ def isAvailable(cls):
(writer, Path(output)) for writer, output in WRITER_OUTPUT]


# Smoke test for saving animations. In the future, we should probably
# design more sophisticated tests which compare resulting frames a-la
# matplotlib.testing.image_comparison
@pytest.mark.parametrize('writer, output', WRITER_OUTPUT)
def test_save_animation_smoketest(tmpdir, writer, output):
if not animation.writers.is_available(writer):
pytest.skip("writer '%s' not available on this system" % writer)
@pytest.fixture()
def simple_animation():
fig, ax = plt.subplots()
line, = ax.plot([], [])

ax.set_xlim(0, 10)
ax.set_ylim(-1, 1)

dpi = None
codec = None
if writer == 'ffmpeg':
# Issue #8253
fig.set_size_inches((10.85, 9.21))
dpi = 100.
codec = 'h264'

def init():
line.set_data([], [])
return line,
Expand All @@ -167,14 +154,59 @@ def animate(i):
line.set_data(x, y)
return line,

return dict(fig=fig, func=animate, init_func=init, frames=5)


# Smoke test for saving animations. In the future, we should probably
# design more sophisticated tests which compare resulting frames a-la
# matplotlib.testing.image_comparison
@pytest.mark.parametrize('writer, output', WRITER_OUTPUT)
def test_save_animation_smoketest(tmpdir, writer, output, simple_animation):
if not animation.writers.is_available(writer):
pytest.skip("writer '%s' not available on this system" % writer)

dpi = None
codec = None
if writer == 'ffmpeg':
# Issue #8253
simple_animation['fig'].set_size_inches((10.85, 9.21))
dpi = 100.
codec = 'h264'

# Use temporary directory for the file-based writers, which produce a file
# per frame with known names.
with tmpdir.as_cwd():
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5)
anim = animation.FuncAnimation(**simple_animation)
anim.save(output, fps=30, writer=writer, bitrate=500, dpi=dpi,
codec=codec)


@pytest.mark.parametrize('writer', [
pytest.param('ffmpeg',
marks=pytest.mark.skipif(
not animation.FFMpegWriter.isAvailable(),
reason='Requires FFMpeg')),
pytest.param('imagemagick',
marks=pytest.mark.skipif(
not animation.ImageMagickWriter.isAvailable(),
reason='Requires ImageMagick')),
])
@pytest.mark.parametrize('html, want', [
('none', None),
('html5', '<video width'),
('jshtml', '<script ')
])
def test_animation_repr_html(writer, html, want, simple_animation):
anim = animation.FuncAnimation(**simple_animation)
with plt.rc_context({'animation.writer': writer,
'animation.html': html}):
html = anim._repr_html_()
if want is None:
assert html is None
else:
assert want in html


def test_no_length_frames():
(make_animation(frames=iter(range(5)))
.save('unused.null', writer=NullMovieWriter()))
Expand Down