1
- from __future__ import absolute_import , division , print_function
2
-
3
- import six
4
-
1
+ from pathlib import Path
5
2
import sys
6
3
import tempfile
7
4
@@ -42,25 +39,30 @@ def finish(self):
42
39
pass
43
40
44
41
45
- def test_null_movie_writer ():
46
- # Test running an animation with NullMovieWriter.
47
-
48
- fig = plt .figure ()
42
+ def make_animation (** kwargs ):
43
+ fig , ax = plt .subplots ()
44
+ line , = ax .plot ([])
49
45
50
46
def init ():
51
47
pass
52
48
53
49
def animate (i ):
54
- pass
50
+ line .set_data ([0 , 1 ], [0 , i ])
51
+ return line ,
52
+
53
+ return animation .FuncAnimation (fig , animate , ** kwargs )
54
+
55
+
56
+ def test_null_movie_writer ():
57
+ # Test running an animation with NullMovieWriter.
58
+
59
+ anim = make_animation (frames = 5 )
55
60
56
- num_frames = 5
57
61
filename = "unused.null"
58
62
dpi = 50
59
63
savefig_kwargs = dict (foo = 0 )
60
-
61
- anim = animation .FuncAnimation (fig , animate , init_func = init ,
62
- frames = num_frames )
63
64
writer = NullMovieWriter ()
65
+
64
66
anim .save (filename , dpi = dpi , writer = writer ,
65
67
savefig_kwargs = savefig_kwargs )
66
68
@@ -178,23 +180,8 @@ def animate(i):
178
180
179
181
180
182
def test_no_length_frames ():
181
- fig , ax = plt .subplots ()
182
- line , = ax .plot ([], [])
183
-
184
- def init ():
185
- line .set_data ([], [])
186
- return line ,
187
-
188
- def animate (i ):
189
- x = np .linspace (0 , 10 , 100 )
190
- y = np .sin (x + i )
191
- line .set_data (x , y )
192
- return line ,
193
-
194
- anim = animation .FuncAnimation (fig , animate , init_func = init ,
195
- frames = iter (range (5 )))
196
- writer = NullMovieWriter ()
197
- anim .save ('unused.null' , writer = writer )
183
+ (make_animation (frames = iter (range (5 )))
184
+ .save ('unused.null' , writer = NullMovieWriter ()))
198
185
199
186
200
187
def test_movie_writer_registry ():
@@ -212,10 +199,30 @@ def test_movie_writer_registry():
212
199
assert not animation .writers .is_available ("ffmpeg" )
213
200
# something which is guaranteed to be available in path
214
201
# and exits immediately
215
- bin = u "true" if sys .platform != 'win32' else u "where"
202
+ bin = "true" if sys .platform != 'win32' else "where"
216
203
mpl .rcParams ['animation.ffmpeg_path' ] = bin
217
204
assert animation .writers ._dirty
218
205
animation .writers .list () # resets
219
206
assert not animation .writers ._dirty
220
207
assert animation .writers .is_available ("ffmpeg" )
221
208
mpl .rcParams ['animation.ffmpeg_path' ] = ffmpeg_path
209
+
210
+
211
+ @pytest .mark .parametrize ("method_name" , ["to_html5_video" , "to_jshtml" ])
212
+ def test_embed_limit (method_name , caplog ):
213
+ mpl .rcParams ["animation.embed_limit" ] = 1e-6 # Approximately 1 byte.
214
+ getattr (make_animation (frames = 1 ), method_name )()
215
+ assert len (caplog .records ) == 1
216
+ record , = caplog .records
217
+ assert (record .name == "matplotlib.animation"
218
+ and record .levelname == "WARNING" )
219
+
220
+
221
+ @pytest .mark .parametrize (
222
+ "method_name" ,
223
+ ["to_html5_video" ,
224
+ pytest .mark .xfail ("to_jshtml" )]) # Needs to be fixed.
225
+ def test_cleanup_temporaries (method_name , tmpdir ):
226
+ with tmpdir .as_cwd ():
227
+ getattr (make_animation (frames = 1 ), method_name )()
228
+ assert list (Path (tmpdir ).iterdir ()) == []
0 commit comments