-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Make "classic" style have effect #5437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
from matplotlib import ticker | ||
from matplotlib import pyplot as plt | ||
from matplotlib import ft2font | ||
from matplotlib import rcParams | ||
from matplotlib.testing.noseclasses import KnownFailureTest, \ | ||
KnownFailureDidNotFailTest, ImageComparisonFailure | ||
from matplotlib.testing.compare import comparable_formats, compare_images, \ | ||
|
@@ -109,18 +110,44 @@ def tearDownClass(cls): | |
cls.original_settings) | ||
|
||
|
||
def cleanup(func): | ||
@functools.wraps(func) | ||
def wrapped_function(*args, **kwargs): | ||
original_units_registry = matplotlib.units.registry.copy() | ||
original_settings = mpl.rcParams.copy() | ||
try: | ||
func(*args, **kwargs) | ||
finally: | ||
_do_cleanup(original_units_registry, | ||
original_settings) | ||
def cleanup(style=None): | ||
""" | ||
A decorator to ensure that any global state is reset before | ||
running a test. | ||
|
||
Parameters | ||
---------- | ||
style : str, optional | ||
The name of the style to apply. | ||
""" | ||
|
||
return wrapped_function | ||
# If cleanup is used without arguments, `style` will be a | ||
# callable, and we pass it directly to the wrapper generator. If | ||
# cleanup if called with an argument, it is a string naming a | ||
# style, and the function will be passed as an argument to what we | ||
# return. This is a confusing, but somewhat standard, pattern for | ||
# writing a decorator with optional arguments. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! Very clear and helpful. |
||
|
||
def make_cleanup(func): | ||
@functools.wraps(func) | ||
def wrapped_function(*args, **kwargs): | ||
original_units_registry = matplotlib.units.registry.copy() | ||
original_settings = mpl.rcParams.copy() | ||
matplotlib.style.use(style) | ||
try: | ||
func(*args, **kwargs) | ||
finally: | ||
_do_cleanup(original_units_registry, | ||
original_settings) | ||
|
||
return wrapped_function | ||
|
||
if isinstance(style, six.string_types): | ||
return make_cleanup | ||
else: | ||
result = make_cleanup(style) | ||
style = 'classic' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this backwards? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok, nevermind... I got mixed up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No. The idea here is to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps make a comment here explaining that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a comment. |
||
return result | ||
|
||
|
||
def check_freetype_version(ver): | ||
|
@@ -138,6 +165,7 @@ def check_freetype_version(ver): | |
class ImageComparisonTest(CleanupTest): | ||
@classmethod | ||
def setup_class(cls): | ||
CleanupTest.setup_class() | ||
cls._initial_settings = mpl.rcParams.copy() | ||
try: | ||
matplotlib.style.use(cls._style) | ||
|
@@ -146,11 +174,8 @@ def setup_class(cls): | |
mpl.rcParams.clear() | ||
mpl.rcParams.update(cls._initial_settings) | ||
raise | ||
# Because the setup of a CleanupTest might involve | ||
# modifying a few rcparams, this setup should come | ||
# last prior to running the image test. | ||
CleanupTest.setup_class() | ||
cls.original_settings = cls._initial_settings | ||
matplotlib.tests.set_font_settings_for_testing() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this solution to this problem. I got so tripped up by this when I was working on the classic mode PR. |
||
cls._func() | ||
|
||
@classmethod | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tab this over one so that it doesn't line up with the code block.
Sorry, made that comment in the commit rather than the PR.