66from matplotlib .testing .noseclasses import KnownFailureTest
77
88
9+ WRITER_OUTPUT = dict (ffmpeg = 'mp4' , ffmpeg_file = 'mp4' ,
10+ mencoder = 'mp4' , mencoder_file = 'mp4' ,
11+ avconv = 'mp4' , avconv_file = 'mp4' ,
12+ imagemagick = 'gif' , imagemagick_file = 'gif' )
13+
14+
15+
916# Smoke test for saving animations. In the future, we should probably
1017# design more sophisticated tests which compare resulting frames a-la
1118# matplotlib.testing.image_comparison
1219def 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-
20+ for writer , extension in WRITER_OUTPUT .iteritems ():
2421 yield check_save_animation , writer , extension
2522
2623
27- def check_save_animation (writer , extension = '. mp4' ):
24+ def check_save_animation (writer , extension = 'mp4' ):
2825 if not animation .writers .is_available (writer ):
2926 raise KnownFailureTest ("writer '%s' not available on this system"
3027 % writer )
@@ -41,12 +38,10 @@ def animate(i):
4138 line .set_data (x , y )
4239 return line ,
4340
44- fid , fname = tempfile . mkstemp ( suffix = extension )
45-
41+ # Use NamedTemporaryFile: will be automatically deleted
42+ F = tempfile . NamedTemporaryFile ( suffix = '.' + extension )
4643 anim = animation .FuncAnimation (fig , animate , init_func = init , frames = 5 )
47- anim .save (fname , fps = 30 , writer = writer )
48-
49- os .remove (fname )
44+ anim .save (F .name , fps = 30 , writer = writer )
5045
5146
5247if __name__ == '__main__' :
0 commit comments