Skip to content

Backport PR #27624 on branch v3.8.x (Prepare for Pytest v8) #27660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,7 @@ def close(self):
_api.warn_deprecated("3.8", message=(
"Keeping empty pdf files is deprecated since %(since)s and support "
"will be removed %(removal)s."))
PdfFile(self._filename, metadata=self._metadata) # touch the file.
PdfFile(self._filename, metadata=self._metadata).close() # touch the file.

def infodict(self):
"""
Expand Down
11 changes: 8 additions & 3 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import copy
import itertools
import unittest.mock
from packaging.version import parse as parse_version

from io import BytesIO
import numpy as np
Expand Down Expand Up @@ -147,9 +148,13 @@ def test_double_register_builtin_cmap():
with pytest.raises(ValueError, match='A colormap named "viridis"'):
with pytest.warns(mpl.MatplotlibDeprecationWarning):
cm.register_cmap(name, mpl.colormaps[name])
with pytest.warns(UserWarning):
# TODO is warning more than once!
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)

if parse_version(pytest.__version__).major < 8:
with pytest.warns(UserWarning):
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)
else:
with pytest.warns(UserWarning), pytest.warns(mpl.MatplotlibDeprecationWarning):
cm.register_cmap(name, mpl.colormaps[name], override_builtin=True)


def test_unregister_builtin_cmap():
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,12 @@ def test_rcparams_update():
rc = mpl.RcParams({'figure.figsize': (3.5, 42)})
bad_dict = {'figure.figsize': (3.5, 42, 1)}
# make sure validation happens on input
with pytest.raises(ValueError), \
pytest.warns(UserWarning, match="validate"):
with pytest.raises(ValueError):
rc.update(bad_dict)


def test_rcparams_init():
with pytest.raises(ValueError), \
pytest.warns(UserWarning, match="validate"):
with pytest.raises(ValueError):
mpl.RcParams({'figure.figsize': (3.5, 42, 1)})


Expand Down
16 changes: 12 additions & 4 deletions lib/matplotlib/tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import locale
import logging
import re
from packaging.version import parse as parse_version

import numpy as np
from numpy.testing import assert_almost_equal, assert_array_equal
Expand Down Expand Up @@ -914,10 +915,17 @@ def test_mathtext_ticks(self):
'axes.formatter.use_mathtext': False
})

with pytest.warns(UserWarning, match='cmr10 font should ideally'):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()
if parse_version(pytest.__version__).major < 8:
with pytest.warns(UserWarning, match='cmr10 font should ideally'):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()
else:
with (pytest.warns(UserWarning, match="Glyph 8722"),
pytest.warns(UserWarning, match='cmr10 font should ideally')):
fig, ax = plt.subplots()
ax.set_xticks([-1, 0, 1])
fig.canvas.draw()

def test_cmr10_substitutions(self, caplog):
mpl.rcParams.update({
Expand Down