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

Commit0a22a47

Browse files
committed
Add some animation tests.
1 parentd610a5d commit0a22a47

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

‎lib/matplotlib/tests/test_animation.py

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
from __future__importabsolute_import,division,print_function
2-
3-
importsix
4-
1+
frompathlibimportPath
52
importsys
63
importtempfile
74

@@ -42,25 +39,30 @@ def finish(self):
4239
pass
4340

4441

45-
deftest_null_movie_writer():
46-
# Test running an animation with NullMovieWriter.
47-
48-
fig=plt.figure()
42+
defmake_animation(**kwargs):
43+
fig,ax=plt.subplots()
44+
line,=ax.plot([])
4945

5046
definit():
5147
pass
5248

5349
defanimate(i):
54-
pass
50+
line.set_data([0,1], [0,i])
51+
returnline,
52+
53+
returnanimation.FuncAnimation(fig,animate,**kwargs)
54+
55+
56+
deftest_null_movie_writer():
57+
# Test running an animation with NullMovieWriter.
58+
59+
anim=make_animation(frames=5)
5560

56-
num_frames=5
5761
filename="unused.null"
5862
dpi=50
5963
savefig_kwargs=dict(foo=0)
60-
61-
anim=animation.FuncAnimation(fig,animate,init_func=init,
62-
frames=num_frames)
6364
writer=NullMovieWriter()
65+
6466
anim.save(filename,dpi=dpi,writer=writer,
6567
savefig_kwargs=savefig_kwargs)
6668

@@ -178,23 +180,8 @@ def animate(i):
178180

179181

180182
deftest_no_length_frames():
181-
fig,ax=plt.subplots()
182-
line,=ax.plot([], [])
183-
184-
definit():
185-
line.set_data([], [])
186-
returnline,
187-
188-
defanimate(i):
189-
x=np.linspace(0,10,100)
190-
y=np.sin(x+i)
191-
line.set_data(x,y)
192-
returnline,
193-
194-
anim=animation.FuncAnimation(fig,animate,init_func=init,
195-
frames=iter(range(5)))
196-
writer=NullMovieWriter()
197-
anim.save('unused.null',writer=writer)
183+
(make_animation(frames=iter(range(5)))
184+
.save('unused.null',writer=NullMovieWriter()))
198185

199186

200187
deftest_movie_writer_registry():
@@ -212,10 +199,30 @@ def test_movie_writer_registry():
212199
assertnotanimation.writers.is_available("ffmpeg")
213200
# something which is guaranteed to be available in path
214201
# and exits immediately
215-
bin=u"true"ifsys.platform!='win32'elseu"where"
202+
bin="true"ifsys.platform!='win32'else"where"
216203
mpl.rcParams['animation.ffmpeg_path']=bin
217204
assertanimation.writers._dirty
218205
animation.writers.list()# resets
219206
assertnotanimation.writers._dirty
220207
assertanimation.writers.is_available("ffmpeg")
221208
mpl.rcParams['animation.ffmpeg_path']=ffmpeg_path
209+
210+
211+
@pytest.mark.parametrize("method_name", ["to_html5_video","to_jshtml"])
212+
deftest_embed_limit(method_name,caplog):
213+
mpl.rcParams["animation.embed_limit"]=1e-6# Approximately 1 byte.
214+
getattr(make_animation(frames=1),method_name)()
215+
assertlen(caplog.records)==1
216+
record,=caplog.records
217+
assert (record.name=="matplotlib.animation"
218+
andrecord.levelname=="WARNING")
219+
220+
221+
@pytest.mark.parametrize(
222+
"method_name",
223+
["to_html5_video",
224+
pytest.mark.xfail("to_jshtml")])# Needs to be fixed.
225+
deftest_cleanup_temporaries(method_name,tmpdir):
226+
withtmpdir.as_cwd():
227+
getattr(make_animation(frames=1),method_name)()
228+
assertlist(Path(tmpdir).iterdir())== []

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp