|
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 |
14 | 13 |
|
15 | 14 |
|
16 | 15 | class NullMovieWriter(animation.AbstractMovieWriter): |
@@ -275,34 +274,32 @@ def frames_generator(): |
275 | 274 | assert (f() is None) != cache_frame_data |
276 | 275 |
|
277 | 276 |
|
278 | | -def test_draw_frame(): |
| 277 | +@pytest.mark.parametrize('return_value', [ |
| 278 | + # User forgot to return (returns None). |
| 279 | + None, |
| 280 | + # User returned a string. |
| 281 | + 'string', |
| 282 | + # User returned an int. |
| 283 | + 1, |
| 284 | + # User returns a sequence of other objects, e.g., string instead of Artist. |
| 285 | + ('string', ), |
| 286 | + # User forgot to return a sequence (handled in `animate` below.) |
| 287 | + 'artist', |
| 288 | +]) |
| 289 | +def test_draw_frame(return_value): |
279 | 290 | # test _draw_frame method |
280 | 291 |
|
281 | 292 | fig, ax = plt.subplots() |
282 | 293 | line, = ax.plot([]) |
283 | 294 |
|
284 | | - def animate(i, arg): |
| 295 | + def animate(i): |
285 | 296 | # general update func |
286 | 297 | line.set_data([0, 1], [0, i]) |
287 | | - if arg: |
288 | | - return arg |
| 298 | + if return_value == 'artist': |
| 299 | + # *not* a sequence |
| 300 | + return line |
| 301 | + else: |
| 302 | + return return_value |
289 | 303 |
|
290 | 304 | with pytest.raises(RuntimeError): |
291 | | - |
292 | | - # user forgot to return (returns None) |
293 | | - animation.FuncAnimation(fig, animate, blit=True, fargs=(None,)) |
294 | | - |
295 | | - # user (for some reason) returned a string...AttributeError is raised |
296 | | - animation.FuncAnimation(fig, animate, blit=True, fargs=('string', )) |
297 | | - |
298 | | - # user (for some reason) returned a string...AttributeError is raised |
299 | | - animation.FuncAnimation(fig, animate, blit=True, fargs=(1, )) |
300 | | - |
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',), )) |
304 | | - |
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, )) |
| 305 | + animation.FuncAnimation(fig, animate, blit=True) |
0 commit comments