10
10
import matplotlib as mpl
11
11
from matplotlib import pyplot as plt
12
12
from matplotlib import animation
13
+ from matplotlib import artist
13
14
14
15
15
16
class NullMovieWriter (animation .AbstractMovieWriter ):
@@ -280,32 +281,29 @@ def test_draw_frame():
280
281
fig , ax = plt .subplots ()
281
282
line , = ax .plot ([])
282
283
283
- def init ():
284
- pass
284
+ def animate (i , arg ):
285
+ # general update func
286
+ line .set_data ([0 , 1 ], [0 , i ])
287
+ if arg :
288
+ return arg
289
+
290
+ with pytest .raises (RuntimeError ):
285
291
286
- def animate_case_1 (i ):
287
292
# user forgot to return (returns None)
288
- line .set_data ([0 , 1 ], [0 , i ])
289
- # return line
293
+ animation .FuncAnimation (fig , animate , blit = True , fargs = (None ,))
290
294
291
- def animate_case_2 (i ):
292
- # user forgot to put comma or return a sequence
293
- # TypeError will be raised (same with returning a number or bool)
294
- line .set_data ([0 , 1 ], [0 , i ])
295
- return line
295
+ # user (for some reason) returned a string...AttributeError is raised
296
+ animation .FuncAnimation (fig , animate , blit = True , fargs = ('string' , ))
296
297
297
- def animate_case_3 (i ):
298
298
# user (for some reason) returned a string...AttributeError is raised
299
- line .set_data ([0 , 1 ], [0 , i ])
300
- return 'a string'
299
+ animation .FuncAnimation (fig , animate , blit = True , fargs = (1 , ))
301
300
302
- def animate_case_4 (i ):
303
- # user returns a sequence other objects instead of Artist.
304
- line .set_data ([0 , 1 ], [0 , i ])
305
- return 'a string' ,
301
+ # user returns a sequence of other objects
302
+ # e.g. a string instead of Artist
303
+ animation .FuncAnimation (fig , animate , blit = True , fargs = (('string' ,), ))
306
304
307
- with pytest . raises ( RuntimeError ) as context :
308
- animation . FuncAnimation ( fig , animate_case_1 , blit = True )
309
- animation . FuncAnimation ( fig , animate_case_2 , blit = True )
310
- animation .FuncAnimation (fig , animate_case_3 , blit = True )
311
- animation . FuncAnimation ( fig , animate_case_4 , blit = True )
305
+ # user forgot to put comma or return a sequence
306
+ # TypeError will be raised (same with returning a number or bool )
307
+ artist_obj = artist . Artist ( )
308
+ animation .FuncAnimation (fig , animate , blit = True , fargs = ( artist_obj , ) )
309
+
0 commit comments