Skip to content

Commit 73ed804

Browse files
authored
Merge pull request #7318 from QuLogic/pytest-yield
Convert a few test files to Pytest
2 parents f9b06c8 + 8a1daab commit 73ed804

File tree

6 files changed

+522
-517
lines changed

6 files changed

+522
-517
lines changed

lib/matplotlib/__init__.py

-5
Original file line numberDiff line numberDiff line change
@@ -1470,10 +1470,8 @@ def _jupyter_nbextension_paths():
14701470

14711471
default_test_modules = [
14721472
'matplotlib.tests.test_agg',
1473-
'matplotlib.tests.test_animation',
14741473
'matplotlib.tests.test_arrow_patches',
14751474
'matplotlib.tests.test_artist',
1476-
'matplotlib.tests.test_axes',
14771475
'matplotlib.tests.test_backend_bases',
14781476
'matplotlib.tests.test_backend_pdf',
14791477
'matplotlib.tests.test_backend_pgf',
@@ -1483,7 +1481,6 @@ def _jupyter_nbextension_paths():
14831481
'matplotlib.tests.test_backend_svg',
14841482
'matplotlib.tests.test_basic',
14851483
'matplotlib.tests.test_bbox_tight',
1486-
'matplotlib.tests.test_cbook',
14871484
'matplotlib.tests.test_coding_standards',
14881485
'matplotlib.tests.test_collections',
14891486
'matplotlib.tests.test_colorbar',
@@ -1508,7 +1505,6 @@ def _jupyter_nbextension_paths():
15081505
'matplotlib.tests.test_pickle',
15091506
'matplotlib.tests.test_png',
15101507
'matplotlib.tests.test_quiver',
1511-
'matplotlib.tests.test_rcparams',
15121508
'matplotlib.tests.test_sankey',
15131509
'matplotlib.tests.test_scale',
15141510
'matplotlib.tests.test_simplification',
@@ -1520,7 +1516,6 @@ def _jupyter_nbextension_paths():
15201516
'matplotlib.tests.test_table',
15211517
'matplotlib.tests.test_text',
15221518
'matplotlib.tests.test_texmanager',
1523-
'matplotlib.tests.test_ticker',
15241519
'matplotlib.tests.test_tightlayout',
15251520
'matplotlib.tests.test_transforms',
15261521
'matplotlib.tests.test_triangulation',

lib/matplotlib/tests/test_animation.py

+31-33
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
import os
77
import sys
88
import tempfile
9+
910
import numpy as np
10-
from numpy.testing import assert_equal
11-
from nose.tools import assert_false, assert_true
11+
import pytest
12+
1213
import matplotlib as mpl
1314
from matplotlib import pyplot as plt
1415
from matplotlib import animation
@@ -67,12 +68,12 @@ def animate(i):
6768
anim.save(filename, dpi=dpi, writer=writer,
6869
savefig_kwargs=savefig_kwargs)
6970

70-
assert_equal(writer.fig, fig)
71-
assert_equal(writer.outfile, filename)
72-
assert_equal(writer.dpi, dpi)
73-
assert_equal(writer.args, ())
74-
assert_equal(writer.savefig_kwargs, savefig_kwargs)
75-
assert_equal(writer._count, num_frames)
71+
assert writer.fig == fig
72+
assert writer.outfile == filename
73+
assert writer.dpi == dpi
74+
assert writer.args == ()
75+
assert writer.savefig_kwargs == savefig_kwargs
76+
assert writer._count == num_frames
7677

7778

7879
@animation.writers.register('null')
@@ -93,23 +94,25 @@ def isAvailable(self):
9394
return True
9495

9596

96-
WRITER_OUTPUT = dict(ffmpeg='mp4', ffmpeg_file='mp4',
97-
mencoder='mp4', mencoder_file='mp4',
98-
avconv='mp4', avconv_file='mp4',
99-
imagemagick='gif', imagemagick_file='gif',
100-
null='null')
97+
WRITER_OUTPUT = [
98+
('ffmpeg', 'mp4'),
99+
('ffmpeg_file', 'mp4'),
100+
('mencoder', 'mp4'),
101+
('mencoder_file', 'mp4'),
102+
('avconv', 'mp4'),
103+
('avconv_file', 'mp4'),
104+
('imagemagick', 'gif'),
105+
('imagemagick_file', 'gif'),
106+
('null', 'null')
107+
]
101108

102109

103110
# Smoke test for saving animations. In the future, we should probably
104111
# design more sophisticated tests which compare resulting frames a-la
105112
# matplotlib.testing.image_comparison
106-
def test_save_animation_smoketest():
107-
for writer, extension in six.iteritems(WRITER_OUTPUT):
108-
yield check_save_animation, writer, extension
109-
110-
111113
@cleanup
112-
def check_save_animation(writer, extension='mp4'):
114+
@pytest.mark.parametrize('writer, extension', WRITER_OUTPUT)
115+
def test_save_animation_smoketest(writer, extension):
113116
try:
114117
# for ImageMagick the rcparams must be patched to account for
115118
# 'convert' being a built in MS tool, not the imagemagick
@@ -174,26 +177,21 @@ def test_movie_writer_registry():
174177
ffmpeg_path = mpl.rcParams['animation.ffmpeg_path']
175178
# Not sure about the first state as there could be some writer
176179
# which set rcparams
177-
#assert_false(animation.writers._dirty)
178-
assert_true(len(animation.writers._registered) > 0)
180+
# assert not animation.writers._dirty
181+
assert len(animation.writers._registered) > 0
179182
animation.writers.list() # resets dirty state
180-
assert_false(animation.writers._dirty)
183+
assert not animation.writers._dirty
181184
mpl.rcParams['animation.ffmpeg_path'] = u"not_available_ever_xxxx"
182-
assert_true(animation.writers._dirty)
185+
assert animation.writers._dirty
183186
animation.writers.list() # resets
184-
assert_false(animation.writers._dirty)
185-
assert_false(animation.writers.is_available("ffmpeg"))
187+
assert not animation.writers._dirty
188+
assert not animation.writers.is_available("ffmpeg")
186189
# something which is guaranteed to be available in path
187190
# and exits immediately
188191
bin = u"true" if sys.platform != 'win32' else u"where"
189192
mpl.rcParams['animation.ffmpeg_path'] = bin
190-
assert_true(animation.writers._dirty)
193+
assert animation.writers._dirty
191194
animation.writers.list() # resets
192-
assert_false(animation.writers._dirty)
193-
assert_true(animation.writers.is_available("ffmpeg"))
195+
assert not animation.writers._dirty
196+
assert animation.writers.is_available("ffmpeg")
194197
mpl.rcParams['animation.ffmpeg_path'] = ffmpeg_path
195-
196-
197-
if __name__ == "__main__":
198-
import nose
199-
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

0 commit comments

Comments
 (0)