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 af17a9b

Browse filesBrowse files
authored
Merge pull request #20543 from anntzer/ums
Deprecate `@pytest.mark.style(...)`.
2 parents a8832f6 + 4e565d2 commit af17a9b
Copy full SHA for af17a9b

File tree

Expand file treeCollapse file tree

15 files changed

+46
-39
lines changed
Filter options
Expand file treeCollapse file tree

15 files changed

+46
-39
lines changed
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``@pytest.mark.style`` is deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Use ``@mpl.style.context``, which has the same effect.

‎lib/matplotlib/testing/conftest.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/conftest.py
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def pytest_configure(config):
1313
("markers", "flaky: (Provided by pytest-rerunfailures.)"),
1414
("markers", "timeout: (Provided by pytest-timeout.)"),
1515
("markers", "backend: Set alternate Matplotlib backend temporarily."),
16-
("markers", "style: Set alternate Matplotlib style temporarily."),
16+
("markers",
17+
"style: Set alternate Matplotlib style temporarily (deprecated)."),
1718
("markers", "baseline_images: Compare output against references."),
1819
("markers", "pytz: Tests that require pytz to be installed."),
1920
("markers", "network: Tests that reach out to the network."),
@@ -65,6 +66,8 @@ def mpl_test_settings(request):
6566
if style_marker is not None:
6667
assert len(style_marker.args) == 1, \
6768
"Marker 'style' must specify 1 style."
69+
_api.warn_deprecated("3.5", name="style", obj_type="pytest marker",
70+
alternative="@mpl.style.context(...)")
6871
style, = style_marker.args
6972

7073
matplotlib.testing.setup()

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from matplotlib import ft2font
1919
from matplotlib import pyplot as plt
2020
from matplotlib import ticker
21-
2221
from .compare import comparable_formats, compare_images, make_test_filename
2322
from .exceptions import ImageComparisonFailure
2423

@@ -220,7 +219,7 @@ def decorator(func):
220219

221220
@functools.wraps(func)
222221
@pytest.mark.parametrize('extension', extensions)
223-
@pytest.mark.style(style)
222+
@matplotlib.style.context(style)
224223
@_checked_on_freetype_version(freetype_version)
225224
@functools.wraps(func)
226225
def wrapper(*args, extension, request, **kwargs):

‎lib/matplotlib/tests/test_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ def test_autoscale_tiny_range():
457457
ax.plot([0, 1], [1, 1 + y1])
458458

459459

460-
@pytest.mark.style('default')
460+
@mpl.style.context('default')
461461
def test_autoscale_tight():
462462
fig, ax = plt.subplots(1, 1)
463463
ax.plot([1, 2, 3, 4])
@@ -467,7 +467,7 @@ def test_autoscale_tight():
467467
assert_allclose(ax.get_ylim(), (1.0, 4.0))
468468

469469

470-
@pytest.mark.style('default')
470+
@mpl.style.context('default')
471471
def test_autoscale_log_shared():
472472
# related to github #7587
473473
# array starts at zero to trigger _minpos handling
@@ -485,7 +485,7 @@ def test_autoscale_log_shared():
485485
assert_allclose(ax2.get_ylim(), (x[0], x[-1]))
486486

487487

488-
@pytest.mark.style('default')
488+
@mpl.style.context('default')
489489
def test_use_sticky_edges():
490490
fig, ax = plt.subplots()
491491
ax.imshow([[0, 1], [2, 3]], origin='lower')
@@ -822,7 +822,7 @@ def test_nonfinite_limits():
822822
ax.plot(x, y)
823823

824824

825-
@pytest.mark.style('default')
825+
@mpl.style.context('default')
826826
@pytest.mark.parametrize('plot_fun',
827827
['scatter', 'plot', 'fill_between'])
828828
@check_figures_equal(extensions=["png"])
@@ -1696,8 +1696,8 @@ def test_bar_pandas_indexed(pd):
16961696
ax.bar(df.x, 1., width=df.width)
16971697

16981698

1699+
@mpl.style.context('default')
16991700
@check_figures_equal()
1700-
@pytest.mark.style('default')
17011701
def test_bar_hatches(fig_test, fig_ref):
17021702
ax_test = fig_test.subplots()
17031703
ax_ref = fig_ref.subplots()
@@ -2190,7 +2190,7 @@ def test_scatter_unfilled(self):
21902190
[0.5, 0.5, 0.5, 1]])
21912191
assert_array_equal(coll.get_linewidths(), [1.1, 1.2, 1.3])
21922192

2193-
@pytest.mark.style('default')
2193+
@mpl.style.context('default')
21942194
def test_scatter_unfillable(self):
21952195
coll = plt.scatter([0, 1, 2], [1, 3, 2], c=['0.1', '0.3', '0.5'],
21962196
marker='x',
@@ -2340,7 +2340,7 @@ def get_next_color():
23402340
c=c_case, edgecolors="black", kwargs={}, xsize=xsize,
23412341
get_next_color_func=get_next_color)
23422342

2343-
@pytest.mark.style('default')
2343+
@mpl.style.context('default')
23442344
@check_figures_equal(extensions=["png"])
23452345
def test_scatter_single_color_c(self, fig_test, fig_ref):
23462346
rgb = [[1, 0.5, 0.05]]
@@ -5575,7 +5575,7 @@ def test_loglog_nonpos():
55755575
ax.set_yscale("log", nonpositive=mcy)
55765576

55775577

5578-
@pytest.mark.style('default')
5578+
@mpl.style.context('default')
55795579
def test_axes_margins():
55805580
fig, ax = plt.subplots()
55815581
ax.plot([0, 1, 2, 3])
@@ -6060,7 +6060,7 @@ def test_tick_param_label_rotation():
60606060
assert text.get_rotation() == 35
60616061

60626062

6063-
@pytest.mark.style('default')
6063+
@mpl.style.context('default')
60646064
def test_fillbetween_cycle():
60656065
fig, ax = plt.subplots()
60666066

@@ -6878,7 +6878,7 @@ def test_polar_interpolation_steps_variable_r(fig_test, fig_ref):
68786878
np.linspace(0, np.pi/2, 101), np.linspace(1, 2, 101))
68796879

68806880

6881-
@pytest.mark.style('default')
6881+
@mpl.style.context('default')
68826882
def test_autoscale_tiny_sticky():
68836883
fig, ax = plt.subplots()
68846884
ax.bar(0, 1e-9)
@@ -6908,7 +6908,7 @@ def test_ytickcolor_is_not_yticklabelcolor():
69086908

69096909
@pytest.mark.parametrize('size', [size for size in mfont_manager.font_scalings
69106910
if size is not None] + [8, 10, 12])
6911-
@pytest.mark.style('default')
6911+
@mpl.style.context('default')
69126912
def test_relative_ticklabel_sizes(size):
69136913
mpl.rcParams['xtick.labelsize'] = size
69146914
mpl.rcParams['ytick.labelsize'] = size
@@ -7066,7 +7066,7 @@ def test_patch_bounds(): # PR 19078
70667066
np.array((-0.525, -(bot+0.05), 1.05, bot+0.1)), ax.dataLim.bounds, 16)
70677067

70687068

7069-
@pytest.mark.style('default')
7069+
@mpl.style.context('default')
70707070
def test_warn_ignored_scatter_kwargs():
70717071
with pytest.warns(UserWarning,
70727072
match=r"You passed a edgecolor/edgecolors"):

‎lib/matplotlib/tests/test_backend_pdf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pdf.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ def psfont(*args, **kwargs):
308308
fig.savefig(tmpfile, format='pdf')
309309

310310

311-
@pytest.mark.style('default')
311+
@mpl.style.context('default')
312312
@check_figures_equal(extensions=["pdf", "eps"])
313313
def test_pdf_eps_savefig_when_color_is_none(fig_test, fig_ref):
314314
ax_test = fig_test.add_subplot()

‎lib/matplotlib/tests/test_backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pgf.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def test_pdflatex():
118118
# test updating the rc parameters for each figure
119119
@needs_xelatex
120120
@needs_pdflatex
121-
@pytest.mark.style('default')
121+
@mpl.style.context('default')
122122
@pytest.mark.backend('pgf')
123123
def test_rcupdate():
124124
rc_sets = [{'font.family': 'sans-serif',
@@ -149,7 +149,7 @@ def test_rcupdate():
149149

150150
# test backend-side clipping, since large numbers are not supported by TeX
151151
@needs_xelatex
152-
@pytest.mark.style('default')
152+
@mpl.style.context('default')
153153
@pytest.mark.backend('pgf')
154154
def test_pathclip():
155155
np.random.seed(19680801)
@@ -179,7 +179,7 @@ def test_mixedmode():
179179

180180
# test bbox_inches clipping
181181
@needs_xelatex
182-
@pytest.mark.style('default')
182+
@mpl.style.context('default')
183183
@pytest.mark.backend('pgf')
184184
def test_bbox_inches():
185185
mpl.rcParams.update({'font.family': 'serif', 'pgf.rcfonts': False})
@@ -192,7 +192,7 @@ def test_bbox_inches():
192192
tol=0)
193193

194194

195-
@pytest.mark.style('default')
195+
@mpl.style.context('default')
196196
@pytest.mark.backend('pgf')
197197
@pytest.mark.parametrize('system', [
198198
pytest.param('lualatex', marks=[needs_lualatex]),
@@ -234,7 +234,7 @@ def test_pdf_pages(system):
234234
assert pdf.get_pagecount() == 3
235235

236236

237-
@pytest.mark.style('default')
237+
@mpl.style.context('default')
238238
@pytest.mark.backend('pgf')
239239
@pytest.mark.parametrize('system', [
240240
pytest.param('lualatex', marks=[needs_lualatex]),

‎lib/matplotlib/tests/test_backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_svg.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def psfont(*args, **kwargs):
198198

199199

200200
# Use Computer Modern Sans Serif, not Helvetica (which has no \textwon).
201-
@pytest.mark.style('default')
201+
@mpl.style.context('default')
202202
@needs_usetex
203203
def test_unicode_won():
204204
fig = Figure()

‎lib/matplotlib/tests/test_category.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_category.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pytest
33
import numpy as np
44

5+
import matplotlib as mpl
56
from matplotlib._api import MatplotlibDeprecationWarning
67
from matplotlib.axes import Axes
78
import matplotlib.pyplot as plt
@@ -281,7 +282,7 @@ def test_mixed_type_update_exception(self, plotter, xdata):
281282
plotter(ax, xdata, [1, 2])
282283

283284

284-
@pytest.mark.style('default')
285+
@mpl.style.context('default')
285286
@check_figures_equal(extensions=["png"])
286287
def test_overriding_units_in_plot(fig_test, fig_ref):
287288
from datetime import datetime

‎lib/matplotlib/tests/test_collections.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_collections.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def test_add_collection():
304304
assert ax.dataLim.bounds == bounds
305305

306306

307-
@pytest.mark.style('mpl20')
307+
@mpl.style.context('mpl20')
308308
@check_figures_equal(extensions=['png'])
309309
def test_collection_log_datalim(fig_test, fig_ref):
310310
# Data limits should respect the minimum x/y when using log scale.
@@ -515,7 +515,7 @@ def test_pandas_indexing(pd):
515515
Collection(antialiaseds=aa)
516516

517517

518-
@pytest.mark.style('default')
518+
@mpl.style.context('default')
519519
def test_lslw_bcast():
520520
col = mcollections.PathCollection([])
521521
col.set_linestyles(['-', '-'])
@@ -529,15 +529,15 @@ def test_lslw_bcast():
529529
assert (col.get_linewidths() == [1, 2, 3]).all()
530530

531531

532-
@pytest.mark.style('default')
532+
@mpl.style.context('default')
533533
def test_capstyle():
534534
col = mcollections.PathCollection([], capstyle='round')
535535
assert col.get_capstyle() == 'round'
536536
col.set_capstyle('butt')
537537
assert col.get_capstyle() == 'butt'
538538

539539

540-
@pytest.mark.style('default')
540+
@mpl.style.context('default')
541541
def test_joinstyle():
542542
col = mcollections.PathCollection([], joinstyle='round')
543543
assert col.get_joinstyle() == 'round'
@@ -933,7 +933,7 @@ def test_legend_inverse_size_label_relationship():
933933
assert_array_almost_equal(handle_sizes, legend_sizes, decimal=1)
934934

935935

936-
@pytest.mark.style('default')
936+
@mpl.style.context('default')
937937
@pytest.mark.parametrize('pcfunc', [plt.pcolor, plt.pcolormesh])
938938
def test_color_logic(pcfunc):
939939
z = np.arange(12).reshape(3, 4)

‎lib/matplotlib/tests/test_contour.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_contour.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ def test_contour_line_start_on_corner_edge():
466466
cbar.add_lines(lines)
467467

468468

469-
@pytest.mark.style("default")
469+
@mpl.style.context("default")
470470
def test_contour_autolabel_beyond_powerlimits():
471471
ax = plt.figure().add_subplot()
472472
cs = plt.contour(np.geomspace(1e-6, 1e-4, 100).reshape(10, 10),

‎lib/matplotlib/tests/test_figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_figure.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def test_autofmt_xdate(which):
409409
assert int(label.get_rotation()) == angle
410410

411411

412-
@pytest.mark.style('default')
412+
@mpl.style.context('default')
413413
def test_change_dpi():
414414
fig = plt.figure(figsize=(4, 4))
415415
fig.draw_no_output()
@@ -598,7 +598,7 @@ def test_removed_axis():
598598
fig.canvas.draw()
599599

600600

601-
@pytest.mark.style('mpl20')
601+
@mpl.style.context('mpl20')
602602
def test_picking_does_not_stale():
603603
fig, ax = plt.subplots()
604604
col = ax.scatter([0], [0], [1000], picker=True)

‎lib/matplotlib/tests/test_image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_image.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ def test_image_array_alpha_validation():
11171117
plt.imshow(np.zeros((2, 2)), alpha=[1, 1])
11181118

11191119

1120-
@pytest.mark.style('mpl20')
1120+
@mpl.style.context('mpl20')
11211121
def test_exact_vmin():
11221122
cmap = copy(plt.cm.get_cmap("autumn_r"))
11231123
cmap.set_under(color="lightgrey")

‎lib/matplotlib/tests/test_patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_patches.py
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
from numpy.testing import assert_almost_equal, assert_array_equal
66
import pytest
77

8+
import matplotlib as mpl
89
from matplotlib.patches import (Annulus, Patch, Polygon, Rectangle,
910
FancyArrowPatch)
1011
from matplotlib.testing.decorators import image_comparison, check_figures_equal
1112
from matplotlib.transforms import Bbox
1213
import matplotlib.pyplot as plt
1314
from matplotlib import (
1415
collections as mcollections, colors as mcolors, patches as mpatches,
15-
path as mpath, style as mstyle, transforms as mtransforms, rcParams)
16+
path as mpath, transforms as mtransforms, rcParams)
1617

1718
import sys
1819
on_win = (sys.platform == 'win32')
@@ -197,7 +198,7 @@ def test_patch_alpha_override():
197198
ax.set_ylim([-1, 2])
198199

199200

200-
@pytest.mark.style('default')
201+
@mpl.style.context('default')
201202
def test_patch_color_none():
202203
# Make sure the alpha kwarg does not override 'none' facecolor.
203204
# Addresses issue #7478.
@@ -410,7 +411,7 @@ def test_multi_color_hatch():
410411
ax.autoscale(False)
411412

412413
for i in range(5):
413-
with mstyle.context({'hatch.color': 'C{}'.format(i)}):
414+
with mpl.style.context({'hatch.color': 'C{}'.format(i)}):
414415
r = Rectangle((i - .8 / 2, 5), .8, 1, hatch='//', fc='none')
415416
ax.add_patch(r)
416417

‎lib/matplotlib/tests/test_ticker.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_ticker.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class TestLogFormatterSciNotation:
672672
(10, 500000, '$\\mathdefault{5\\times10^{5}}$'),
673673
]
674674

675-
@pytest.mark.style('default')
675+
@mpl.style.context('default')
676676
@pytest.mark.parametrize('base, value, expected', test_data)
677677
def test_basic(self, base, value, expected):
678678
formatter = mticker.LogFormatterSciNotation(base=base)
@@ -833,7 +833,7 @@ def _sub_labels(self, axis, subs=()):
833833
label_test = [fmt(x) != '' for x in minor_tlocs]
834834
assert label_test == label_expected
835835

836-
@pytest.mark.style('default')
836+
@mpl.style.context('default')
837837
def test_sublabel(self):
838838
# test label locator
839839
fig, ax = plt.subplots()
@@ -1368,7 +1368,7 @@ def test_bad_locator_subs(sub):
13681368

13691369

13701370
@pytest.mark.parametrize('numticks', [1, 2, 3, 9])
1371-
@pytest.mark.style('default')
1371+
@mpl.style.context('default')
13721372
def test_small_range_loglocator(numticks):
13731373
ll = mticker.LogLocator()
13741374
ll.set_params(numticks=numticks)

‎lib/mpl_toolkits/tests/test_mplot3d.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_mplot3d.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ def convert_lim(dmin, dmax):
14031403
assert z_center != pytest.approx(z_center0)
14041404

14051405

1406-
@pytest.mark.style('default')
1406+
@mpl.style.context('default')
14071407
@check_figures_equal(extensions=["png"])
14081408
def test_scalarmap_update(fig_test, fig_ref):
14091409

0 commit comments

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