Skip to content

Commit a565a5b

Browse files
committed
Convert cleanup decorator into autouse fixture.
Any non-default styles can be specified with `@pytest.mark.style('name')`.
1 parent 70831bd commit a565a5b

File tree

8 files changed

+55
-18
lines changed

8 files changed

+55
-18
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
from matplotlib.tests.conftest import mpl_test_settings

lib/matplotlib/tests/conftest.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import pytest
5+
6+
import matplotlib
7+
8+
9+
@pytest.fixture(autouse=True)
10+
def mpl_test_settings(request):
11+
from matplotlib.testing.decorators import _do_cleanup
12+
13+
original_units_registry = matplotlib.units.registry.copy()
14+
original_settings = matplotlib.rcParams.copy()
15+
16+
style = 'classic'
17+
style_marker = request.keywords.get('style')
18+
if style_marker is not None:
19+
assert len(style_marker.args) == 1, \
20+
"Marker 'style' must specify 1 style."
21+
style = style_marker.args[0]
22+
23+
matplotlib.style.use(style)
24+
try:
25+
yield
26+
finally:
27+
_do_cleanup(original_units_registry,
28+
original_settings)

lib/matplotlib/tests/test_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def test_autoscale_tiny_range():
200200
ax[i].plot([0, 1], [1, 1 + y1])
201201

202202

203-
@cleanup(style='default')
203+
@pytest.mark.style('default')
204204
def test_autoscale_tight():
205205
fig, ax = plt.subplots(1, 1)
206206
ax.plot([1, 2, 3, 4])
@@ -210,7 +210,7 @@ def test_autoscale_tight():
210210
assert_allclose(ax.get_ylim(), (1.0, 4.0))
211211

212212

213-
@cleanup(style='default')
213+
@pytest.mark.style('default')
214214
def test_autoscale_log_shared():
215215
# related to github #7587
216216
# array starts at zero to trigger _minpos handling
@@ -228,7 +228,7 @@ def test_autoscale_log_shared():
228228
assert_allclose(ax2.get_ylim(), (x[0], x[-1]))
229229

230230

231-
@cleanup(style='default')
231+
@pytest.mark.style('default')
232232
def test_use_sticky_edges():
233233
fig, ax = plt.subplots()
234234
ax.imshow([[0, 1], [2, 3]], origin='lower')
@@ -4573,7 +4573,7 @@ def test_loglog():
45734573
ax.tick_params(length=15, width=2, which='minor')
45744574

45754575

4576-
@cleanup('default')
4576+
@pytest.mark.style('default')
45774577
def test_axes_margins():
45784578
fig, ax = plt.subplots()
45794579
ax.plot([0, 1, 2, 3])
@@ -4924,7 +4924,7 @@ def test_fill_betweenx_2d_x2_input():
49244924
ax.fill_betweenx(y, x1, x2)
49254925

49264926

4927-
@cleanup(style='default')
4927+
@pytest.mark.style('default')
49284928
def test_fillbetween_cycle():
49294929
fig, ax = plt.subplots()
49304930

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
import matplotlib.pyplot as plt
1313
from matplotlib.compat import subprocess
1414
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
15-
from matplotlib.testing.decorators import (_image_directories, switch_backend,
16-
cleanup)
15+
from matplotlib.testing.decorators import _image_directories, switch_backend
1716

1817
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
1918

@@ -83,7 +82,7 @@ def create_figure():
8382

8483
# test compiling a figure to pdf with xelatex
8584
@needs_xelatex
86-
@cleanup(style='classic')
85+
@pytest.mark.style('classic')
8786
@switch_backend('pgf')
8887
def test_xelatex():
8988
rc_xelatex = {'font.family': 'serif',
@@ -95,7 +94,7 @@ def test_xelatex():
9594

9695
# test compiling a figure to pdf with pdflatex
9796
@needs_pdflatex
98-
@cleanup(style='classic')
97+
@pytest.mark.style('classic')
9998
@switch_backend('pgf')
10099
def test_pdflatex():
101100
import os
@@ -117,7 +116,7 @@ def test_pdflatex():
117116
# test updating the rc parameters for each figure
118117
@needs_xelatex
119118
@needs_pdflatex
120-
@cleanup(style='classic')
119+
@pytest.mark.style('classic')
121120
@switch_backend('pgf')
122121
def test_rcupdate():
123122
rc_sets = []
@@ -148,7 +147,7 @@ def test_rcupdate():
148147

149148
# test backend-side clipping, since large numbers are not supported by TeX
150149
@needs_xelatex
151-
@cleanup(style='classic')
150+
@pytest.mark.style('classic')
152151
@switch_backend('pgf')
153152
def test_pathclip():
154153
rc_xelatex = {'font.family': 'serif',
@@ -165,7 +164,7 @@ def test_pathclip():
165164

166165
# test mixed mode rendering
167166
@needs_xelatex
168-
@cleanup(style='classic')
167+
@pytest.mark.style('classic')
169168
@switch_backend('pgf')
170169
def test_mixedmode():
171170
rc_xelatex = {'font.family': 'serif',
@@ -180,7 +179,7 @@ def test_mixedmode():
180179

181180
# test bbox_inches clipping
182181
@needs_xelatex
183-
@cleanup(style='classic')
182+
@pytest.mark.style('classic')
184183
@switch_backend('pgf')
185184
def test_bbox_inches():
186185
rc_xelatex = {'font.family': 'serif',

lib/matplotlib/tests/test_collections.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ def test_pandas_indexing():
635635
Collection(antialiaseds=aa)
636636

637637

638-
@cleanup(style='default')
638+
@pytest.mark.style('default')
639639
def test_lslw_bcast():
640640
col = mcollections.PathCollection([])
641641
col.set_linestyles(['-', '-'])

lib/matplotlib/tests/test_patches.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import numpy as np
1010
from numpy.testing import assert_almost_equal, assert_array_equal
11+
import pytest
1112

1213
from matplotlib.patches import Polygon
1314
from matplotlib.patches import Rectangle
@@ -174,7 +175,7 @@ def test_patch_alpha_override():
174175
ax.set_ylim([-1, 2])
175176

176177

177-
@cleanup(style='default')
178+
@pytest.mark.style('default')
178179
def test_patch_color_none():
179180
# Make sure the alpha kwarg does not override 'none' facecolor.
180181
# Addresses issue #7478.

lib/matplotlib/tests/test_ticker.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import warnings
1414

1515

16-
@cleanup(style='classic')
16+
@pytest.mark.style('classic')
1717
def test_MaxNLocator():
1818
loc = mticker.MaxNLocator(nbins=5)
1919
test_value = np.array([20., 40., 60., 80., 100.])
@@ -174,7 +174,7 @@ def test_SymmetricalLogLocator_set_params():
174174
assert sym.numticks == 8
175175

176176

177-
@cleanup(style='classic')
177+
@pytest.mark.style('classic')
178178
@pytest.mark.parametrize('left, right, offset',
179179
[(123, 189, 0),
180180
(-189, -123, 0),
@@ -240,7 +240,7 @@ def _sub_labels(axis, subs=()):
240240
assert label_test == label_expected
241241

242242

243-
@cleanup(style='default')
243+
@pytest.mark.style('default')
244244
def test_LogFormatter_sublabel():
245245
# test label locator
246246
fig, ax = plt.subplots()
@@ -318,6 +318,7 @@ def test_LogFormatterExponent_blank():
318318
assert formatter(10**0.1) == ''
319319

320320

321+
@pytest.mark.style('default')
321322
def test_LogFormatterSciNotation():
322323
test_cases = {
323324
10: (

lib/mpl_toolkits/tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
from matplotlib.tests.conftest import mpl_test_settings

0 commit comments

Comments
 (0)