|
13 | 13 | from matplotlib import animation
|
14 | 14 |
|
15 | 15 |
|
| 16 | +@pytest.fixture() |
| 17 | +def anim(request): |
| 18 | + """Create a simple animation (with options).""" |
| 19 | + fig, ax = plt.subplots() |
| 20 | + line, = ax.plot([], []) |
| 21 | + |
| 22 | + ax.set_xlim(0, 10) |
| 23 | + ax.set_ylim(-1, 1) |
| 24 | + |
| 25 | + def init(): |
| 26 | + line.set_data([], []) |
| 27 | + return line, |
| 28 | + |
| 29 | + def animate(i): |
| 30 | + x = np.linspace(0, 10, 100) |
| 31 | + y = np.sin(x + i) |
| 32 | + line.set_data(x, y) |
| 33 | + return line, |
| 34 | + |
| 35 | + # "klass" can be passed to determine the class returned by the fixture |
| 36 | + kwargs = dict(getattr(request, 'param', {})) # make a copy |
| 37 | + klass = kwargs.pop('klass', animation.FuncAnimation) |
| 38 | + if 'frames' not in kwargs: |
| 39 | + kwargs['frames'] = 5 |
| 40 | + return klass(fig=fig, func=animate, init_func=init, **kwargs) |
| 41 | + |
| 42 | + |
16 | 43 | class NullMovieWriter(animation.AbstractMovieWriter):
|
17 | 44 | """
|
18 | 45 | A minimal MovieWriter. It doesn't actually write anything.
|
@@ -118,32 +145,6 @@ def isAvailable(cls):
|
118 | 145 | (writer, Path(output)) for writer, output in WRITER_OUTPUT]
|
119 | 146 |
|
120 | 147 |
|
121 |
| -@pytest.fixture() |
122 |
| -def anim(request): |
123 |
| - fig, ax = plt.subplots() |
124 |
| - line, = ax.plot([], []) |
125 |
| - |
126 |
| - ax.set_xlim(0, 10) |
127 |
| - ax.set_ylim(-1, 1) |
128 |
| - |
129 |
| - def init(): |
130 |
| - line.set_data([], []) |
131 |
| - return line, |
132 |
| - |
133 |
| - def animate(i): |
134 |
| - x = np.linspace(0, 10, 100) |
135 |
| - y = np.sin(x + i) |
136 |
| - line.set_data(x, y) |
137 |
| - return line, |
138 |
| - |
139 |
| - # "klass" can be passed to determine the class returned by the fixture |
140 |
| - kwargs = dict(getattr(request, 'param', {})) # make a copy |
141 |
| - klass = kwargs.pop('klass', animation.FuncAnimation) |
142 |
| - if 'frames' not in kwargs: |
143 |
| - kwargs['frames'] = 5 |
144 |
| - return klass(fig=fig, func=animate, init_func=init, **kwargs) |
145 |
| - |
146 |
| - |
147 | 148 | # Smoke test for saving animations. In the future, we should probably
|
148 | 149 | # design more sophisticated tests which compare resulting frames a-la
|
149 | 150 | # matplotlib.testing.image_comparison
|
|
0 commit comments