6
6
from matplotlib .testing .noseclasses import KnownFailureTest
7
7
8
8
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
+
9
16
# Smoke test for saving animations. In the future, we should probably
10
17
# design more sophisticated tests which compare resulting frames a-la
11
18
# matplotlib.testing.image_comparison
12
19
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
-
20
+ for writer , extension in WRITER_OUTPUT .iteritems ():
24
21
yield check_save_animation , writer , extension
25
22
26
23
27
- def check_save_animation (writer , extension = '. mp4' ):
24
+ def check_save_animation (writer , extension = 'mp4' ):
28
25
if not animation .writers .is_available (writer ):
29
26
raise KnownFailureTest ("writer '%s' not available on this system"
30
27
% writer )
@@ -41,12 +38,10 @@ def animate(i):
41
38
line .set_data (x , y )
42
39
return line ,
43
40
44
- fid , fname = tempfile . mkstemp ( suffix = extension )
45
-
41
+ # Use NamedTemporaryFile: will be automatically deleted
42
+ F = tempfile . NamedTemporaryFile ( suffix = '.' + extension )
46
43
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 )
50
45
51
46
52
47
if __name__ == '__main__' :
0 commit comments