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

Skip to content

Commit 4365e95

Browse files
committed
Have image tests default to 'classic' style.
1 parent a3edefb commit 4365e95

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lib/matplotlib/style/core.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ def is_style_file(filename):
4242
def use(style):
4343
"""Use matplotlib style settings from a style specification.
4444
45+
The style name of 'default' is reserved for reverting back to
46+
the default style settings.
47+
4548
Parameters
4649
----------
4750
style : str, dict, or list
@@ -70,6 +73,9 @@ def use(style):
7073
if not cbook.is_string_like(style):
7174
mpl.rcParams.update(style)
7275
continue
76+
elif style == 'default':
77+
mpl.rcdefaults()
78+
continue
7379

7480
if style in library:
7581
mpl.rcParams.update(library[style])

lib/matplotlib/testing/decorators.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from matplotlib import ticker
2222
from matplotlib import pyplot as plt
2323
from matplotlib import ft2font
24+
from matplotlib.style import context as style_context
2425
from matplotlib.testing.noseclasses import KnownFailureTest, \
2526
KnownFailureDidNotFailTest, ImageComparisonFailure
2627
from matplotlib.testing.compare import comparable_formats, compare_images, \
@@ -132,7 +133,8 @@ class ImageComparisonTest(CleanupTest):
132133
def setup_class(cls):
133134
CleanupTest.setup_class()
134135

135-
cls._func()
136+
with style_context(cls._style):
137+
cls._func()
136138

137139
@staticmethod
138140
def remove_text(figure):
@@ -206,7 +208,7 @@ def do_test():
206208

207209
def image_comparison(baseline_images=None, extensions=None, tol=13,
208210
freetype_version=None, remove_text=False,
209-
savefig_kwarg=None):
211+
savefig_kwarg=None, style='classic'):
210212
"""
211213
call signature::
212214
@@ -243,6 +245,11 @@ def image_comparison(baseline_images=None, extensions=None, tol=13,
243245
*savefig_kwarg*: dict
244246
Optional arguments that are passed to the savefig method.
245247
248+
*style*: string
249+
Optional name for the base style to apply to the image
250+
test. The test itself can also apply additional styles
251+
if desired. Defaults to the 'classic' style.
252+
246253
"""
247254

248255
if baseline_images is None:
@@ -280,7 +287,8 @@ def compare_images_decorator(func):
280287
'_tol': tol,
281288
'_freetype_version': freetype_version,
282289
'_remove_text': remove_text,
283-
'_savefig_kwarg': savefig_kwarg})
290+
'_savefig_kwarg': savefig_kwarg,
291+
'_style': style})
284292

285293
return new_class
286294
return compare_images_decorator

0 commit comments

Comments
 (0)