Skip to content

Support generative tests in @cleanup. #5809

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

Merged
merged 4 commits into from
Jan 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 25 additions & 11 deletions lib/matplotlib/testing/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import functools
import gc
import inspect
import os
import sys
import shutil
Expand Down Expand Up @@ -129,18 +130,31 @@ def cleanup(style=None):
# writing a decorator with optional arguments.

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)
if inspect.isgenerator(func):
@functools.wraps(func)
def wrapped_callable(*args, **kwargs):
original_units_registry = matplotlib.units.registry.copy()
original_settings = mpl.rcParams.copy()
matplotlib.style.use(style)
try:
for yielded in func(*args, **kwargs):
yield yielded
finally:
_do_cleanup(original_units_registry,
original_settings)
else:
@functools.wraps(func)
def wrapped_callable(*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
return wrapped_callable

if isinstance(style, six.string_types):
return make_cleanup
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4278,7 +4278,7 @@ def _helper_y(ax):
orig_xlim = ax_lst[0][1].get_xlim()
ax.remove()
ax.set_xlim(0, 5)
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)


@cleanup
Expand Down