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

Skip to content

Commit 9a80aaa

Browse files
committed
Various test fixes.
1 parent dd2099b commit 9a80aaa

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
@@ -1330,7 +1330,6 @@ def rc_context(rc=None, fname=None):
13301330
dict.update(rcParams, orig)
13311331

13321332

1333-
# Could be entirely replaced by pyplot.switch_backends.
13341333
def use(arg, warn=True, force=False):
13351334
"""
13361335
Set the Matplotlib backend.
@@ -1343,11 +1342,16 @@ def use(arg, warn=True, force=False):
13431342
13441343
Parameters
13451344
----------
1346-
arg : str or List[str]
1347-
The name of the backend to use. If a list of backends, they will be
1348-
tried in order until one successfully loads.
1345+
arg : str
1346+
The name of the backend to use.
13491347
"""
1350-
rcParams["backend"] = arg
1348+
if not isinstance(arg, six.string_types):
1349+
# We want to keep 'use(...); rcdefaults()' working, which means that
1350+
# use(...) needs to force the default backend, and thus be a single
1351+
# string.
1352+
raise TypeError("matplotlib.use takes a single string as argument")
1353+
rcParams["backend"] = \
1354+
rcParamsDefault["backend"] = rcParamsOrig["backend"] = arg
13511355

13521356

13531357
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
@@ -58,11 +58,9 @@ def test_rcparams():
5858
assert mpl.rcParams['lines.linewidth'] == linewidth
5959

6060
# test rc_file
61-
try:
61+
with mpl.rc_context():
6262
mpl.rc_file(fname)
6363
assert mpl.rcParams['lines.linewidth'] == 33
64-
finally:
65-
mpl.rcParams['lines.linewidth'] = linewidth
6664

6765

6866
def test_RcParams_class():

0 commit comments

Comments
 (0)