Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 482bde0

Browse files
authored
Merge pull request #10347 from anntzer/hide-backendqt-rc-warning
Hide the backend.qt4/5 rcparam deprecation warning in test suite.
2 parents 3db8a0d + a0c0b29 commit 482bde0

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

lib/matplotlib/rcsetup.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import warnings
2525
import re
2626

27-
from matplotlib import cbook
27+
from matplotlib import cbook, testing
2828
from matplotlib.cbook import mplDeprecation, deprecated, ls_mapper
2929
from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
3030
from matplotlib.colors import is_color_like
@@ -266,19 +266,28 @@ def validate_backend(s):
266266
return _validate_standard_backends(s)
267267

268268

269-
@deprecated("2.2",
269+
def validate_qt4(s):
270+
# Don't spam the test suite with warnings every time the rcparams are
271+
# reset. While it may seem better to use filterwarnings from within the
272+
# test suite, pytest 3.1+ explicitly disregards warnings filters (pytest
273+
# issue #2430).
274+
if not testing.is_called_from_pytest():
275+
cbook.warn_deprecated(
276+
"2.2",
270277
"The backend.qt4 rcParam was deprecated in version 2.2. In order "
271278
"to force the use of a specific Qt4 binding, either import that "
272279
"binding first, or set the QT_API environment variable.")
273-
def validate_qt4(s):
274280
return ValidateInStrings("backend.qt4", ['PyQt4', 'PySide', 'PyQt4v2'])(s)
275281

276282

277-
@deprecated("2.2",
283+
def validate_qt5(s):
284+
# See comment re: validate_qt4.
285+
if not testing.is_called_from_pytest():
286+
cbook.warn_deprecated(
287+
"2.2",
278288
"The backend.qt5 rcParam was deprecated in version 2.2. In order "
279289
"to force the use of a specific Qt5 binding, either import that "
280290
"binding first, or set the QT_API environment variable.")
281-
def validate_qt5(s):
282291
return ValidateInStrings("backend.qt5", ['PyQt5', 'PySide2'])(s)
283292

284293

lib/matplotlib/testing/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import functools
55
import warnings
66

7-
import matplotlib
8-
from matplotlib import cbook, rcParams, rcdefaults, use
7+
import matplotlib as mpl
8+
from matplotlib import cbook
99

1010

1111
def _is_list_like(obj):
@@ -15,7 +15,7 @@ def _is_list_like(obj):
1515

1616
def is_called_from_pytest():
1717
"""Returns whether the call was done from pytest"""
18-
return getattr(matplotlib, '_called_from_pytest', False)
18+
return getattr(mpl, '_called_from_pytest', False)
1919

2020

2121
def _copy_metadata(src_func, tgt_func):
@@ -26,13 +26,13 @@ def _copy_metadata(src_func, tgt_func):
2626

2727

2828
def set_font_settings_for_testing():
29-
rcParams['font.family'] = 'DejaVu Sans'
30-
rcParams['text.hinting'] = False
31-
rcParams['text.hinting_factor'] = 8
29+
mpl.rcParams['font.family'] = 'DejaVu Sans'
30+
mpl.rcParams['text.hinting'] = False
31+
mpl.rcParams['text.hinting_factor'] = 8
3232

3333

3434
def set_reproducibility_for_testing():
35-
rcParams['svg.hashsalt'] = 'matplotlib'
35+
mpl.rcParams['svg.hashsalt'] = 'matplotlib'
3636

3737

3838
def setup():
@@ -51,12 +51,12 @@ def setup():
5151
"Could not set locale to English/United States. "
5252
"Some date-related tests may fail")
5353

54-
use('Agg', warn=False) # use Agg backend for these tests
54+
mpl.use('Agg', warn=False) # use Agg backend for these tests
5555

5656
# These settings *must* be hardcoded for running the comparison
5757
# tests and are not necessarily the default values as specified in
5858
# rcsetup.py
59-
rcdefaults() # Start with all defaults
59+
mpl.rcdefaults() # Start with all defaults
6060

6161
set_font_settings_for_testing()
6262
set_reproducibility_for_testing()

0 commit comments

Comments
 (0)