Skip to content

Commit 8d41044

Browse files
committed
TST: Add a frame test for animations
1 parent 2e95730 commit 8d41044

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

lib/matplotlib/tests/test_animation.py

+35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import matplotlib as mpl
1212
from matplotlib import pyplot as plt
1313
from matplotlib import animation
14+
from matplotlib.testing.decorators import check_figures_equal
1415

1516

1617
@pytest.fixture()
@@ -402,3 +403,37 @@ def update(frame):
402403

403404
with pytest.warns(UserWarning, match="exhausted"):
404405
anim._start()
406+
407+
408+
@check_figures_equal(extensions=["png"])
409+
def test_animation_frame(tmpdir, fig_test, fig_ref):
410+
# Test the expected image after iterating through a few frames
411+
# we save the animation to get the iteration because we are not
412+
# in an interactive framework.
413+
ax = fig_test.add_subplot()
414+
ax.set_xlim(0, 2 * np.pi)
415+
ax.set_ylim(-1, 1)
416+
x = np.linspace(0, 2 * np.pi, 100)
417+
line, = ax.plot([], [])
418+
419+
def init():
420+
line.set_data([], [])
421+
return line,
422+
423+
def animate(i):
424+
line.set_data(x, np.sin(x + i / 100))
425+
return line,
426+
427+
anim = animation.FuncAnimation(
428+
fig_test, animate, init_func=init, frames=5,
429+
blit=True, repeat=False)
430+
with tmpdir.as_cwd():
431+
anim.save("test.gif")
432+
433+
# Reference figure without animation
434+
ax = fig_ref.add_subplot()
435+
ax.set_xlim(0, 2 * np.pi)
436+
ax.set_ylim(-1, 1)
437+
438+
# 5th frame's data
439+
ax.plot(x, np.sin(x + 4 / 100))

0 commit comments

Comments
 (0)