Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9cee283

Browse files
committed
TST: Add test for _repr_html_
1 parent5584ba7 commit9cee283

File tree

1 file changed

+49
-17
lines changed

1 file changed

+49
-17
lines changed

‎lib/matplotlib/tests/test_animation.py

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
importpytest
1010

1111
importmatplotlibasmpl
12-
frommatplotlibimportpyplotasplt
12+
frommatplotlibimportpyplotasplt,rc_context
1313
frommatplotlibimportanimation
1414

1515

@@ -136,27 +136,14 @@ def isAvailable(cls):
136136
(writer,Path(output))forwriter,outputinWRITER_OUTPUT]
137137

138138

139-
# Smoke test for saving animations. In the future, we should probably
140-
# design more sophisticated tests which compare resulting frames a-la
141-
# matplotlib.testing.image_comparison
142-
@pytest.mark.parametrize('writer, output',WRITER_OUTPUT)
143-
deftest_save_animation_smoketest(tmpdir,writer,output):
144-
ifnotanimation.writers.is_available(writer):
145-
pytest.skip("writer '%s' not available on this system"%writer)
139+
@pytest.fixture()
140+
defsimple_animation():
146141
fig,ax=plt.subplots()
147142
line,=ax.plot([], [])
148143

149144
ax.set_xlim(0,10)
150145
ax.set_ylim(-1,1)
151146

152-
dpi=None
153-
codec=None
154-
ifwriter=='ffmpeg':
155-
# Issue #8253
156-
fig.set_size_inches((10.85,9.21))
157-
dpi=100.
158-
codec='h264'
159-
160147
definit():
161148
line.set_data([], [])
162149
returnline,
@@ -167,14 +154,59 @@ def animate(i):
167154
line.set_data(x,y)
168155
returnline,
169156

157+
returndict(fig=fig,func=animate,init_func=init,frames=5)
158+
159+
160+
# Smoke test for saving animations. In the future, we should probably
161+
# design more sophisticated tests which compare resulting frames a-la
162+
# matplotlib.testing.image_comparison
163+
@pytest.mark.parametrize('writer, output',WRITER_OUTPUT)
164+
deftest_save_animation_smoketest(tmpdir,writer,output,simple_animation):
165+
ifnotanimation.writers.is_available(writer):
166+
pytest.skip("writer '%s' not available on this system"%writer)
167+
168+
dpi=None
169+
codec=None
170+
ifwriter=='ffmpeg':
171+
# Issue #8253
172+
simple_animation['fig'].set_size_inches((10.85,9.21))
173+
dpi=100.
174+
codec='h264'
175+
170176
# Use temporary directory for the file-based writers, which produce a file
171177
# per frame with known names.
172178
withtmpdir.as_cwd():
173-
anim=animation.FuncAnimation(fig,animate,init_func=init,frames=5)
179+
anim=animation.FuncAnimation(**simple_animation)
174180
anim.save(output,fps=30,writer=writer,bitrate=500,dpi=dpi,
175181
codec=codec)
176182

177183

184+
@pytest.mark.parametrize('writer', [
185+
pytest.param('ffmpeg',
186+
marks=pytest.mark.skipif(
187+
notanimation.FFMpegWriter.isAvailable(),
188+
reason='Requires FFMpeg')),
189+
pytest.param('imagemagick',
190+
marks=pytest.mark.skipif(
191+
notanimation.ImageMagickWriter.isAvailable(),
192+
reason='Requires ImageMagick')),
193+
])
194+
@pytest.mark.parametrize('html, want', [
195+
('none',None),
196+
('html5','<video width'),
197+
('jshtml','<script ')
198+
])
199+
deftest_animation_repr_html(writer,html,want,simple_animation):
200+
anim=animation.FuncAnimation(**simple_animation)
201+
withplt.rc_context({'animation.writer':writer,
202+
'animation.html':html}):
203+
html=anim._repr_html_()
204+
ifwantisNone:
205+
asserthtmlisNone
206+
else:
207+
assertwantinhtml
208+
209+
178210
deftest_no_length_frames():
179211
(make_animation(frames=iter(range(5)))
180212
.save('unused.null',writer=NullMovieWriter()))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp