GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #5809 from anntzer/cleanup-generative-tests · matplotlib/matplotlib@0375ea4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/matplotlib
    • testing
      • decorators.py
    • tests
      • test_axes.py
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/matplotlib/testing/decorators.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+25-11Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import functools
77
import gc
8+
import inspect
89
import os
910
import sys
1011
import shutil
@@ -129,18 +130,31 @@ def cleanup(style=None):
129130
# writing a decorator with optional arguments.
130131

131132
def make_cleanup(func):
132-
@functools.wraps(func)
133-
def wrapped_function(*args, **kwargs):
134-
original_units_registry = matplotlib.units.registry.copy()
135-
original_settings = mpl.rcParams.copy()
136-
matplotlib.style.use(style)
137-
try:
138-
func(*args, **kwargs)
139-
finally:
140-
_do_cleanup(original_units_registry,
141-
original_settings)
133+
if inspect.isgenerator(func):
134+
@functools.wraps(func)
135+
def wrapped_callable(*args, **kwargs):
136+
original_units_registry = matplotlib.units.registry.copy()
137+
original_settings = mpl.rcParams.copy()
138+
matplotlib.style.use(style)
139+
try:
140+
for yielded in func(*args, **kwargs):
141+
yield yielded
142+
finally:
143+
_do_cleanup(original_units_registry,
144+
original_settings)
145+
else:
146+
@functools.wraps(func)
147+
def wrapped_callable(*args, **kwargs):
148+
original_units_registry = matplotlib.units.registry.copy()
149+
original_settings = mpl.rcParams.copy()
150+
matplotlib.style.use(style)
151+
try:
152+
func(*args, **kwargs)
153+
finally:
154+
_do_cleanup(original_units_registry,
155+
original_settings)
142156

143-
return wrapped_function
157+
return wrapped_callable
144158

145159
if isinstance(style, six.string_types):
146160
return make_cleanup
Collapse file

‎lib/matplotlib/tests/test_axes.py‎

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_axes.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4282,7 +4282,7 @@ def _helper_y(ax):
42824282
orig_xlim = ax_lst[0][1].get_xlim()
42834283
ax.remove()
42844284
ax.set_xlim(0, 5)
4285-
assert assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
4285+
assert_array_equal(ax_lst[0][1].get_xlim(), orig_xlim)
42864286

42874287

42884288
@cleanup

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.