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

Appearance settings

Commit ba30f11

Browse filesBrowse files
committed
TST: Parametrize tests that were using yield.
1 parent 17fe952 commit ba30f11
Copy full SHA for ba30f11

File tree

Expand file treeCollapse file tree

5 files changed

+273
-260
lines changed
Filter options
Expand file treeCollapse file tree

5 files changed

+273
-260
lines changed

‎lib/matplotlib/tests/test_animation.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_animation.py
+16-11Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
import os
77
import sys
88
import tempfile
9+
910
import numpy as np
11+
import pytest
12+
1013
import matplotlib as mpl
1114
from matplotlib import pyplot as plt
1215
from matplotlib import animation
@@ -91,23 +94,25 @@ def isAvailable(self):
9194
return True
9295

9396

94-
WRITER_OUTPUT = dict(ffmpeg='mp4', ffmpeg_file='mp4',
95-
mencoder='mp4', mencoder_file='mp4',
96-
avconv='mp4', avconv_file='mp4',
97-
imagemagick='gif', imagemagick_file='gif',
98-
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+
]
99108

100109

101110
# Smoke test for saving animations. In the future, we should probably
102111
# design more sophisticated tests which compare resulting frames a-la
103112
# matplotlib.testing.image_comparison
104-
def test_save_animation_smoketest():
105-
for writer, extension in six.iteritems(WRITER_OUTPUT):
106-
yield check_save_animation, writer, extension
107-
108-
109113
@cleanup
110-
def check_save_animation(writer, extension='mp4'):
114+
@pytest.mark.parametrize('writer, extension', WRITER_OUTPUT)
115+
def test_save_animation_smoketest(writer, extension):
111116
try:
112117
# for ImageMagick the rcparams must be patched to account for
113118
# 'convert' being a built in MS tool, not the imagemagick

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+45-31Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from numpy import ma
1919
from numpy import arange
2020
from cycler import cycler
21+
import pytest
2122

2223
import warnings
2324

@@ -4269,13 +4270,7 @@ def test_violin_point_mass():
42694270
plt.violinplot(np.array([0, 0]))
42704271

42714272

4272-
def _eb_succes_helper(ax, x, y, xerr=None, yerr=None):
4273-
eb = ax.errorbar(x, y, xerr=xerr, yerr=yerr)
4274-
eb.remove()
4275-
4276-
4277-
@cleanup
4278-
def test_errorbar_inputs_shotgun():
4273+
def generate_errorbar_inputs():
42794274
base_xy = cycler('x', [np.arange(5)]) + cycler('y', [np.ones((5, ))])
42804275
err_cycler = cycler('err', [1,
42814276
[1, 1, 1, 1, 1],
@@ -4296,15 +4291,17 @@ def test_errorbar_inputs_shotgun():
42964291
yerr_only = base_xy * yerr_cy
42974292
both_err = base_xy * yerr_cy * xerr_cy
42984293

4299-
test_cyclers = xerr_only, yerr_only, both_err, empty
4294+
test_cyclers = chain(xerr_only, yerr_only, both_err, empty)
4295+
4296+
return test_cyclers
4297+
43004298

4299+
@cleanup
4300+
@pytest.mark.parametrize('kwargs', generate_errorbar_inputs())
4301+
def test_errorbar_inputs_shotgun(kwargs):
43014302
ax = plt.gca()
4302-
# should do this as a generative test, but @cleanup seems to break that
4303-
# for p in chain(*test_cyclers):
4304-
# yield (_eb_succes_helper, ax) + tuple(p.get(k, None) for
4305-
# k in ['x', 'y', 'xerr', 'yerr'])
4306-
for p in chain(*test_cyclers):
4307-
_eb_succes_helper(ax, **p)
4303+
eb = ax.errorbar(**kwargs)
4304+
eb.remove()
43084305

43094306

43104307
@cleanup
@@ -4386,8 +4383,8 @@ def test_axes_margins():
43864383
assert ax.get_ybound() == (-0.5, 9.5)
43874384

43884385

4389-
@cleanup
4390-
def test_remove_shared_axes():
4386+
@pytest.fixture(params=['x', 'y'])
4387+
def shared_axis_remover(request):
43914388
def _helper_x(ax):
43924389
ax2 = ax.twinx()
43934390
ax2.remove()
@@ -4402,26 +4399,43 @@ def _helper_y(ax):
44024399
r = ax.yaxis.get_major_locator()()
44034400
assert r[-1] > 14
44044401

4402+
if request.param == 'x':
4403+
return _helper_x
4404+
elif request.param == 'y':
4405+
return _helper_y
4406+
else:
4407+
assert False, 'Request param %s is invalid.' % (request.param, )
4408+
4409+
4410+
@pytest.fixture(params=['gca', 'subplots', 'subplots_shared', 'add_axes'])
4411+
def shared_axes_generator(request):
44054412
# test all of the ways to get fig/ax sets
4406-
fig = plt.figure()
4407-
ax = fig.gca()
4408-
yield _helper_x, ax
4409-
yield _helper_y, ax
4413+
if request.param == 'gca':
4414+
fig = plt.figure()
4415+
ax = fig.gca()
4416+
elif request.param == 'subplots':
4417+
fig, ax = plt.subplots()
4418+
elif request.param == 'subplots_shared':
4419+
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4420+
ax = ax_lst[0][0]
4421+
elif request.param == 'add_axes':
4422+
fig = plt.figure()
4423+
ax = fig.add_axes([.1, .1, .8, .8])
4424+
else:
4425+
assert False, 'Request param %s is invalid.' % (request.param, )
44104426

4411-
fig, ax = plt.subplots()
4412-
yield _helper_x, ax
4413-
yield _helper_y, ax
4427+
return fig, ax
44144428

4415-
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
4416-
ax = ax_lst[0][0]
4417-
yield _helper_x, ax
4418-
yield _helper_y, ax
44194429

4420-
fig = plt.figure()
4421-
ax = fig.add_axes([.1, .1, .8, .8])
4422-
yield _helper_x, ax
4423-
yield _helper_y, ax
4430+
@cleanup
4431+
def test_remove_shared_axes(shared_axes_generator, shared_axis_remover):
4432+
# test all of the ways to get fig/ax sets
4433+
fig, ax = shared_axes_generator
4434+
shared_axis_remover(ax)
4435+
44244436

4437+
@cleanup
4438+
def test_remove_shared_axes_relim():
44254439
fig, ax_lst = plt.subplots(2, 2, sharex='all', sharey='all')
44264440
ax = ax_lst[0][0]
44274441
orig_xlim = ax_lst[0][1].get_xlim()

‎lib/matplotlib/tests/test_cbook.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_cbook.py
+50-53Lines changed: 50 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from numpy.testing.utils import (assert_array_equal, assert_approx_equal,
1313
assert_array_almost_equal)
1414
from nose.tools import raises, assert_raises
15+
import pytest
1516

1617
import matplotlib.cbook as cbook
1718
import matplotlib.colors as mcolors
@@ -343,65 +344,61 @@ def test_sanitize_sequence():
343344
assert k == cbook.sanitize_sequence(k)
344345

345346

346-
def _kwarg_norm_helper(inp, expected, kwargs_to_norm, warn_count=0):
347-
347+
fail_mapping = (
348+
({'a': 1}, {'forbidden': ('a')}),
349+
({'a': 1}, {'required': ('b')}),
350+
({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()})
351+
)
352+
353+
warn_passing_mapping = (
354+
({'a': 1, 'b': 2}, {'a': 1}, {'alias_mapping': {'a': ['b']}}, 1),
355+
({'a': 1, 'b': 2}, {'a': 1},
356+
{'alias_mapping': {'a': ['b']}, 'allowed': ('a',)}, 1),
357+
({'a': 1, 'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}, 1),
358+
({'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'c': 3},
359+
{'alias_mapping': {'a': ['b']}, 'required': ('a', )}, 1),
360+
)
361+
362+
pass_mapping = (
363+
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}),
364+
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
365+
({'b': 2}, {'a': 2},
366+
{'alias_mapping': {'a': ['b']}, 'forbidden': ('b', )}),
367+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
368+
{'required': ('a', ), 'allowed': ('c', )}),
369+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
370+
{'required': ('a', 'c'), 'allowed': ('c', )}),
371+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
372+
{'required': ('a', 'c'), 'allowed': ('a', 'c')}),
373+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3},
374+
{'required': ('a', 'c'), 'allowed': ()}),
375+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c')}),
376+
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'allowed': ('a', 'c')}),
377+
)
378+
379+
380+
@pytest.mark.parametrize('inp, kwargs_to_norm', fail_mapping)
381+
def test_normalize_kwargs_fail(inp, kwargs_to_norm):
382+
with pytest.raises(TypeError):
383+
cbook.normalize_kwargs(inp, **kwargs_to_norm)
384+
385+
386+
@pytest.mark.parametrize('inp, expected, kwargs_to_norm, warn_count',
387+
warn_passing_mapping)
388+
def test_normalize_kwargs_warn(inp, expected, kwargs_to_norm, warn_count):
348389
with warnings.catch_warnings(record=True) as w:
349390
warnings.simplefilter("always")
350391
assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
351392
assert len(w) == warn_count
352393

353394

354-
def _kwarg_norm_fail_helper(inp, kwargs_to_norm):
355-
assert_raises(TypeError, cbook.normalize_kwargs, inp, **kwargs_to_norm)
356-
357-
358-
def test_normalize_kwargs():
359-
fail_mapping = (
360-
({'a': 1}, {'forbidden': ('a')}),
361-
({'a': 1}, {'required': ('b')}),
362-
({'a': 1, 'b': 2}, {'required': ('a'), 'allowed': ()})
363-
)
364-
365-
for inp, kwargs in fail_mapping:
366-
yield _kwarg_norm_fail_helper, inp, kwargs
367-
368-
warn_passing_mapping = (
369-
({'a': 1, 'b': 2}, {'a': 1}, {'alias_mapping': {'a': ['b']}}, 1),
370-
({'a': 1, 'b': 2}, {'a': 1}, {'alias_mapping': {'a': ['b']},
371-
'allowed': ('a',)}, 1),
372-
({'a': 1, 'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}, 1),
373-
374-
({'a': 1, 'b': 2, 'c': 3}, {'a': 1, 'c': 3},
375-
{'alias_mapping': {'a': ['b']}, 'required': ('a', )}, 1),
376-
377-
)
378-
379-
for inp, exp, kwargs, wc in warn_passing_mapping:
380-
yield _kwarg_norm_helper, inp, exp, kwargs, wc
381-
382-
pass_mapping = (
383-
({'a': 1, 'b': 2}, {'a': 1, 'b': 2}, {}),
384-
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['a', 'b']}}),
385-
({'b': 2}, {'a': 2}, {'alias_mapping': {'a': ['b']},
386-
'forbidden': ('b', )}),
387-
388-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', ),
389-
'allowed': ('c', )}),
390-
391-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c'),
392-
'allowed': ('c', )}),
393-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c'),
394-
'allowed': ('a', 'c')}),
395-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c'),
396-
'allowed': ()}),
397-
398-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'required': ('a', 'c')}),
399-
({'a': 1, 'c': 3}, {'a': 1, 'c': 3}, {'allowed': ('a', 'c')}),
400-
401-
)
402-
403-
for inp, exp, kwargs in pass_mapping:
404-
yield _kwarg_norm_helper, inp, exp, kwargs
395+
@pytest.mark.parametrize('inp, expected, kwargs_to_norm',
396+
pass_mapping)
397+
def test_normalize_kwargs_pass(inp, expected, kwargs_to_norm):
398+
with warnings.catch_warnings(record=True) as w:
399+
warnings.simplefilter("always")
400+
assert expected == cbook.normalize_kwargs(inp, **kwargs_to_norm)
401+
assert len(w) == 0
405402

406403

407404
def test_to_prestep():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.