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

Skip to content

Commit 39df421

Browse files
committed
Various test fixes.
1 parent f0f351c commit 39df421

File tree

4 files changed

+18
-31
lines changed

4 files changed

+18
-31
lines changed

lib/matplotlib/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,7 +1327,6 @@ def rc_context(rc=None, fname=None):
13271327
dict.update(rcParams, orig)
13281328

13291329

1330-
# Could be entirely replaced by pyplot.switch_backends.
13311330
def use(arg, warn=True, force=False):
13321331
"""
13331332
Set the Matplotlib backend.
@@ -1340,11 +1339,16 @@ def use(arg, warn=True, force=False):
13401339
13411340
Parameters
13421341
----------
1343-
arg : str or List[str]
1344-
The name of the backend to use. If a list of backends, they will be
1345-
tried in order until one successfully loads.
1342+
arg : str
1343+
The name of the backend to use.
13461344
"""
1347-
rcParams["backend"] = arg
1345+
if not isinstance(arg, six.string_types):
1346+
# We want to keep 'use(...); rcdefaults()' working, which means that
1347+
# use(...) needs to force the default backend, and thus be a single
1348+
# string.
1349+
raise TypeError("matplotlib.use takes a single string as argument")
1350+
rcParams["backend"] = \
1351+
rcParamsDefault["backend"] = rcParamsOrig["backend"] = arg
13481352

13491353

13501354
def get_backend():

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,24 +154,16 @@
154154
import sphinx
155155

156156
sphinx_version = sphinx.__version__.split(".")
157-
# The split is necessary for sphinx beta versions where the string is
158-
# '6b1'
157+
# The split is necessary for sphinx beta versions where the string is '6b1'.
159158
sphinx_version = tuple([int(re.split('[^0-9]', x)[0])
160159
for x in sphinx_version[:2]])
161160

162161
import jinja2 # Sphinx dependency.
163162

164163
import matplotlib
164+
matplotlib.use("agg")
165165
import matplotlib.cbook as cbook
166-
try:
167-
with warnings.catch_warnings(record=True):
168-
warnings.simplefilter("error", UserWarning)
169-
matplotlib.use('Agg')
170-
except UserWarning:
171-
import matplotlib.pyplot as plt
172-
plt.switch_backend("Agg")
173-
else:
174-
import matplotlib.pyplot as plt
166+
import matplotlib.pyplot as plt
175167
from matplotlib import _pylab_helpers
176168

177169
__version__ = 2

lib/matplotlib/testing/__init__.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
unicode_literals)
33

44
import functools
5-
import inspect
5+
import locale
66
import warnings
7-
from contextlib import contextmanager
87

98
import matplotlib
109
from matplotlib.cbook import iterable
@@ -41,10 +40,6 @@ def set_reproducibility_for_testing():
4140
def setup():
4241
# The baseline images are created in this locale, so we should use
4342
# it during all of the tests.
44-
import locale
45-
import warnings
46-
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
47-
4843
try:
4944
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
5045
except locale.Error:
@@ -53,14 +48,12 @@ def setup():
5348
except locale.Error:
5449
warnings.warn(
5550
"Could not set locale to English/United States. "
56-
"Some date-related tests may fail")
57-
58-
use('Agg', warn=False) # use Agg backend for these tests
51+
"Some date-related tests may fail.")
5952

60-
# These settings *must* be hardcoded for running the comparison
61-
# tests and are not necessarily the default values as specified in
62-
# rcsetup.py
53+
matplotlib.use("agg")
6354
rcdefaults() # Start with all defaults
6455

56+
# These settings *must* be hardcoded for running the comparison tests and
57+
# are not necessarily the default values as specified in rcsetup.py.
6558
set_font_settings_for_testing()
6659
set_reproducibility_for_testing()

lib/matplotlib/tests/test_rcparams.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,9 @@ def test_rcparams():
5959
assert mpl.rcParams['lines.linewidth'] == linewidth
6060

6161
# test rc_file
62-
try:
62+
with mpl.rc_context():
6363
mpl.rc_file(fname)
6464
assert mpl.rcParams['lines.linewidth'] == 33
65-
finally:
66-
mpl.rcParams['lines.linewidth'] = linewidth
6765

6866

6967
def test_RcParams_class():

0 commit comments

Comments
 (0)