Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b4fd83c

Browse files
committed
STY: Move
1 parent c3c32c8 commit b4fd83c

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

lib/matplotlib/tests/test_animation.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@
1313
from matplotlib import animation
1414

1515

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+
1643
class NullMovieWriter(animation.AbstractMovieWriter):
1744
"""
1845
A minimal MovieWriter. It doesn't actually write anything.
@@ -118,32 +145,6 @@ def isAvailable(cls):
118145
(writer, Path(output)) for writer, output in WRITER_OUTPUT]
119146

120147

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-
147148
# Smoke test for saving animations. In the future, we should probably
148149
# design more sophisticated tests which compare resulting frames a-la
149150
# matplotlib.testing.image_comparison

0 commit comments

Comments
 (0)