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

Skip to content

Commit 26f86c0

Browse files
committed
TST: add smoke test for saving of animations
1 parent 0b6e803 commit 26f86c0

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

lib/matplotlib/animation.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def list(self):
5353
''' Get a list of available MovieWriters.'''
5454
return self.avail.keys()
5555

56+
def is_available(self, name):
57+
return name in self.avail
58+
5659
def __getitem__(self, name):
5760
if not self.avail:
5861
raise RuntimeError("No MovieWriters available!")
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import os
2+
import tempfile
3+
import numpy as np
4+
from matplotlib import pyplot as plt
5+
from matplotlib import animation
6+
from matplotlib.testing.noseclasses import KnownFailureTest
7+
8+
9+
# Smoke test for saving animations. In the future, we should probably
10+
# design more sophisticated tests which compare resulting frames a-la
11+
# matplotlib.testing.image_comparison
12+
def test_save_animation_smoketest():
13+
writers = ['ffmpeg', 'ffmpeg_file',
14+
'mencoder', 'mencoder_file',
15+
'avconv', 'avconv_file',
16+
'imagemagick', 'imagemagick_file']
17+
18+
for writer in writers:
19+
if writer.startswith('imagemagick'):
20+
extension = '.gif'
21+
else:
22+
extension = '.mp4'
23+
24+
yield check_save_animation, writer, extension
25+
26+
27+
def check_save_animation(writer, extension='.mp4'):
28+
if not animation.writers.is_available(writer):
29+
raise KnownFailureTest("writer '%s' not available on this system"
30+
% writer)
31+
fig, ax = plt.subplots()
32+
line, = ax.plot([], [])
33+
34+
def init():
35+
line.set_data([], [])
36+
return line,
37+
38+
def animate(i):
39+
x = np.linspace(0, 10, 100)
40+
y = np.sin(x + i)
41+
line.set_data(x, y)
42+
return line,
43+
44+
fid, fname = tempfile.mkstemp(suffix=extension)
45+
46+
anim = animation.FuncAnimation(fig, animate, init_func=init, frames=5)
47+
anim.save(fname, fps=30, writer=writer)
48+
49+
os.remove(fname)
50+
51+
52+
if __name__ == '__main__':
53+
import nose
54+
nose.runmodule()

matplotlibrc.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
435435
#animation.ffmpeg_path: 'ffmpeg' # Path to ffmpeg binary. Without full path
436436
# $PATH is searched
437437
#animation.ffmpeg_args: '' # Additional arugments to pass to ffmpeg
438-
#animation.avconv_path: 'avconv' # Path to ffmpeg binary. Without full path
438+
#animation.avconv_path: 'avconv' # Path to avconv binary. Without full path
439439
# $PATH is searched
440440
#animation.avconv_args: '' # Additional arugments to pass to ffmpeg
441441
#animation.mencoder_path: 'mencoder'

0 commit comments

Comments
 (0)