1010import matplotlib as mpl
1111from matplotlib import pyplot as plt
1212from matplotlib import animation
13+ from matplotlib import artist
1314
1415
1516class NullMovieWriter (animation .AbstractMovieWriter ):
@@ -280,32 +281,29 @@ def test_draw_frame():
280281 fig , ax = plt .subplots ()
281282 line , = ax .plot ([])
282283
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 ):
285291
286- def animate_case_1 (i ):
287292 # 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 ,))
290294
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' , ))
296297
297- def animate_case_3 (i ):
298298 # 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 , ))
301300
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' ,), ))
306304
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