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

Skip to content

Commit 4654a9f

Browse files
committed
Merge pull request #5512 from matplotlib/v2.0.x
V2.0.x
2 parents 91ca2a3 + deeec9c commit 4654a9f

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

lib/matplotlib/testing/__init__.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from contextlib import contextmanager
66

77
from matplotlib.cbook import is_string_like, iterable
8+
from matplotlib import rcParams, rcdefaults, use
89

910

1011
def _is_list_like(obj):
@@ -70,3 +71,36 @@ def assert_produces_warning(expected_warning=Warning, filter_level="always",
7071
% expected_warning.__name__)
7172
assert not extra_warnings, ("Caused unexpected warning(s): %r."
7273
% extra_warnings)
74+
75+
76+
def set_font_settings_for_testing():
77+
rcParams['font.family'] = 'DejaVu Sans'
78+
rcParams['text.hinting'] = False
79+
rcParams['text.hinting_factor'] = 8
80+
81+
82+
def setup():
83+
# The baseline images are created in this locale, so we should use
84+
# it during all of the tests.
85+
import locale
86+
import warnings
87+
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
88+
89+
try:
90+
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
91+
except locale.Error:
92+
try:
93+
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
94+
except locale.Error:
95+
warnings.warn(
96+
"Could not set locale to English/United States. "
97+
"Some date-related tests may fail")
98+
99+
use('Agg', warn=False) # use Agg backend for these tests
100+
101+
# These settings *must* be hardcoded for running the comparison
102+
# tests and are not necessarily the default values as specified in
103+
# rcsetup.py
104+
rcdefaults() # Start with all defaults
105+
106+
set_font_settings_for_testing()

lib/matplotlib/testing/decorators.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
import matplotlib as mpl
1818
import matplotlib.style
19-
import matplotlib.tests
2019
import matplotlib.units
20+
import matplotlib.testing
2121
from matplotlib import cbook
2222
from matplotlib import ticker
2323
from matplotlib import pyplot as plt
@@ -85,7 +85,7 @@ class CleanupTest(object):
8585
def setup_class(cls):
8686
cls.original_units_registry = matplotlib.units.registry.copy()
8787
cls.original_settings = mpl.rcParams.copy()
88-
matplotlib.tests.setup()
88+
matplotlib.testing.setup()
8989

9090
@classmethod
9191
def teardown_class(cls):
@@ -175,7 +175,7 @@ def setup_class(cls):
175175
mpl.rcParams.update(cls._initial_settings)
176176
raise
177177
cls.original_settings = cls._initial_settings
178-
matplotlib.tests.set_font_settings_for_testing()
178+
matplotlib.testing.set_font_settings_for_testing()
179179
cls._func()
180180

181181
@classmethod
@@ -396,7 +396,7 @@ def switch_backend_decorator(func):
396396
def backend_switcher(*args, **kwargs):
397397
try:
398398
prev_backend = mpl.get_backend()
399-
matplotlib.tests.setup()
399+
matplotlib.testing.setup()
400400
plt.switch_backend(backend)
401401
result = func(*args, **kwargs)
402402
finally:

lib/matplotlib/tests/__init__.py

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
import difflib
77
import os
88

9-
from matplotlib import rcParams, rcdefaults, use
10-
9+
from matplotlib.testing import setup
1110

1211
_multiprocess_can_split_ = True
1312

@@ -22,39 +21,6 @@
2221
'test data.')
2322

2423

25-
def set_font_settings_for_testing():
26-
rcParams['font.family'] = 'DejaVu Sans'
27-
rcParams['text.hinting'] = False
28-
rcParams['text.hinting_factor'] = 8
29-
30-
31-
def setup():
32-
# The baseline images are created in this locale, so we should use
33-
# it during all of the tests.
34-
import locale
35-
import warnings
36-
from matplotlib.backends import backend_agg, backend_pdf, backend_svg
37-
38-
try:
39-
locale.setlocale(locale.LC_ALL, str('en_US.UTF-8'))
40-
except locale.Error:
41-
try:
42-
locale.setlocale(locale.LC_ALL, str('English_United States.1252'))
43-
except locale.Error:
44-
warnings.warn(
45-
"Could not set locale to English/United States. "
46-
"Some date-related tests may fail")
47-
48-
use('Agg', warn=False) # use Agg backend for these tests
49-
50-
# These settings *must* be hardcoded for running the comparison
51-
# tests and are not necessarily the default values as specified in
52-
# rcsetup.py
53-
rcdefaults() # Start with all defaults
54-
55-
set_font_settings_for_testing()
56-
57-
5824
def assert_str_equal(reference_str, test_str,
5925
format_str=('String {str1} and {str2} do not '
6026
'match:\n{differences}')):

0 commit comments

Comments
 (0)