|
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): |
@@ -272,3 +273,36 @@ def frames_generator(): |
272 | 273 | # If cache_frame_data is True, then the weakref should be alive; |
273 | 274 | # if cache_frame_data is False, then the weakref should be dead (None). |
274 | 275 | assert (f() is None) != cache_frame_data |
| 276 | + |
| 277 | + |
| 278 | +def test_draw_frame(): |
| 279 | + # test _draw_frame method |
| 280 | + |
| 281 | + fig, ax = plt.subplots() |
| 282 | + line, = ax.plot([]) |
| 283 | + |
| 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): |
| 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, )) |
0 commit comments