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

Skip to content

Commit f5392d6

Browse files
committed
Add some animation tests.
1 parent d610a5d commit f5392d6

File tree

6 files changed

+44
-37
lines changed

6 files changed

+44
-37
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ install:
6363
- activate test-environment
6464
- echo %PYTHON_VERSION% %TARGET_ARCH%
6565
# pytest-cov>=2.3.1 due to https://github.com/pytest-dev/pytest-cov/issues/124
66-
- pip install -q "pytest!=3.3.0,>=3.2.0" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist
66+
- pip install -q "pytest>=3.3.1" "pytest-cov>=2.3.1" pytest-rerunfailures pytest-timeout pytest-xdist
6767

6868
# Apply patch to `subprocess` on Python versions > 2 and < 3.6.3
6969
# https://github.com/matplotlib/matplotlib/issues/9176

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ env:
5252
- NUMPY=numpy
5353
- PANDAS=
5454
- PYPARSING=pyparsing
55-
- PYTEST='pytest!=3.3.0,>=3.2.0'
55+
- PYTEST='pytest>=3.3.1'
5656
- PYTEST_COV=pytest-cov
5757
- PYTEST_PEP8=
5858
- SPHINX=sphinx
@@ -74,7 +74,7 @@ matrix:
7474
- NUMPY=numpy==1.10.0
7575
- PANDAS='pandas<0.21.0'
7676
- PYPARSING=pyparsing==2.0.1
77-
- PYTEST=pytest==3.1.0
77+
- PYTEST=pytest==3.3.1
7878
- PYTEST_COV=pytest-cov==2.3.1
7979
- SPHINX=sphinx==1.3
8080
- python: 3.5

doc/devel/contributing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ environment is set up properly::
151151

152152
.. note::
153153

154-
**Additional dependencies for testing**: pytest_ (version 3.1 or later),
154+
**Additional dependencies for testing**: pytest_ (version 3.3.1 or later),
155155
Ghostscript_, Inkscape_
156156

157157
.. seealso::

doc/devel/testing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ local FreeType build
2525

2626
The following software is required to run the tests:
2727

28-
- pytest_ (>=3.1)
28+
- pytest_ (>=3.3.1)
2929
- Ghostscript_ (to render PDF files)
3030
- Inkscape_ (to render SVG files)
3131

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__ import absolute_import, division, print_function
2-
3-
import six
4-
1+
from pathlib import Path
52
import sys
63
import tempfile
74

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

4441

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

5046
def init():
5147
pass
5248

5349
def animate(i):
54-
pass
50+
line.set_data([0, 1], [0, i])
51+
return line,
52+
53+
return animation.FuncAnimation(fig, animate, **kwargs)
54+
55+
56+
def test_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
def test_no_length_frames():
181-
fig, ax = plt.subplots()
182-
line, = ax.plot([], [])
183-
184-
def init():
185-
line.set_data([], [])
186-
return line,
187-
188-
def animate(i):
189-
x = np.linspace(0, 10, 100)
190-
y = np.sin(x + i)
191-
line.set_data(x, y)
192-
return line,
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
def test_movie_writer_registry():
@@ -212,10 +199,30 @@ def test_movie_writer_registry():
212199
assert not animation.writers.is_available("ffmpeg")
213200
# something which is guaranteed to be available in path
214201
# and exits immediately
215-
bin = u"true" if sys.platform != 'win32' else u"where"
202+
bin = "true" if sys.platform != 'win32' else "where"
216203
mpl.rcParams['animation.ffmpeg_path'] = bin
217204
assert animation.writers._dirty
218205
animation.writers.list() # resets
219206
assert not animation.writers._dirty
220207
assert animation.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+
def test_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+
assert len(caplog.records) == 1
216+
record, = caplog.records
217+
assert (record.name == "matplotlib.animation"
218+
and record.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+
def test_cleanup_temporaries(method_name, tmpdir):
226+
with tmpdir.as_cwd():
227+
getattr(make_animation(frames=1), method_name)()
228+
assert list(Path(tmpdir).iterdir()) == []

setupext.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ def get_namespace_packages(self):
739739

740740
class Tests(OptionalPackage):
741741
name = "tests"
742-
pytest_min_version = '3.1'
742+
pytest_min_version = '3.3.1'
743743
default_config = False
744744

745745
def check(self):

0 commit comments

Comments
 (0)