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

Skip to content

Commit 8fa4fec

Browse files
committed
Various test fixes.
1 parent bc6914f commit 8fa4fec

4 files changed

Lines changed: 18 additions & 28 deletions

File tree

lib/matplotlib/__init__.py

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

13141314

1315-
# Could be entirely replaced by pyplot.switch_backends.
13161315
def use(arg, warn=True, force=False):
13171316
"""
13181317
Set the Matplotlib backend.
@@ -1325,11 +1324,16 @@ def use(arg, warn=True, force=False):
13251324
13261325
Parameters
13271326
----------
1328-
arg : str or List[str]
1329-
The name of the backend to use. If a list of backends, they will be
1330-
tried in order until one successfully loads.
1327+
arg : str
1328+
The name of the backend to use.
13311329
"""
1332-
rcParams["backend"] = arg
1330+
if not isinstance(arg, six.string_types):
1331+
# We want to keep 'use(...); rcdefaults()' working, which means that
1332+
# use(...) needs to force the default backend, and thus be a single
1333+
# string.
1334+
raise TypeError("matplotlib.use takes a single string as argument")
1335+
rcParams["backend"] = \
1336+
rcParamsDefault["backend"] = rcParamsOrig["backend"] = arg
13331337

13341338

13351339
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
unicode_literals)
33

44
import functools
5+
import locale
56
import warnings
67

78
import matplotlib
@@ -38,9 +39,6 @@ def set_reproducibility_for_testing():
3839
def setup():
3940
# The baseline images are created in this locale, so we should use
4041
# it during all of the tests.
41-
import locale
42-
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
43-
4442
try:
4543
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
4644
except locale.Error:
@@ -49,14 +47,12 @@ def setup():
4947
except locale.Error:
5048
warnings.warn(
5149
"Could not set locale to English/United States. "
52-
"Some date-related tests may fail")
53-
54-
use('Agg', warn=False) # use Agg backend for these tests
50+
"Some date-related tests may fail.")
5551

56-
# These settings *must* be hardcoded for running the comparison
57-
# tests and are not necessarily the default values as specified in
58-
# rcsetup.py
52+
matplotlib.use("agg")
5953
rcdefaults() # Start with all defaults
6054

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

lib/matplotlib/tests/test_rcparams.py

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

5959
# test rc_file
60-
try:
60+
with mpl.rc_context():
6161
mpl.rc_file(fname)
6262
assert mpl.rcParams['lines.linewidth'] == 33
63-
finally:
64-
mpl.rcParams['lines.linewidth'] = linewidth
6563

6664

6765
def test_RcParams_class():

0 commit comments

Comments
 (0)