Create a simple animation (with options).
(request)
| 19 | |
| 20 | @pytest.fixture() |
| 21 | def anim(request): |
| 22 | """Create a simple animation (with options).""" |
| 23 | fig, ax = plt.subplots() |
| 24 | line, = ax.plot([], []) |
| 25 | |
| 26 | ax.set_xlim(0, 10) |
| 27 | ax.set_ylim(-1, 1) |
| 28 | |
| 29 | def init(): |
| 30 | line.set_data([], []) |
| 31 | return line, |
| 32 | |
| 33 | def animate(i): |
| 34 | x = np.linspace(0, 10, 100) |
| 35 | y = np.sin(x + i) |
| 36 | line.set_data(x, y) |
| 37 | return line, |
| 38 | |
| 39 | # "klass" can be passed to determine the class returned by the fixture |
| 40 | kwargs = dict(getattr(request, 'param', {})) # make a copy |
| 41 | klass = kwargs.pop('klass', animation.FuncAnimation) |
| 42 | if 'frames' not in kwargs: |
| 43 | kwargs['frames'] = 5 |
| 44 | return klass(fig=fig, func=animate, init_func=init, **kwargs) |
| 45 | |
| 46 | |
| 47 | def test_invalid_writer(): |