Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 90ca48e

Browse filesBrowse files
committed
Cleanup
1 parent 5cadac1 commit 90ca48e
Copy full SHA for 90ca48e

File tree

Expand file treeCollapse file tree

3 files changed

+21
-23
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-23
lines changed

‎lib/matplotlib/testing/decorators.py

Copy file name to clipboardExpand all lines: lib/matplotlib/testing/decorators.py
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import nose
1515
import numpy as np
1616

17+
import matplotlib as mpl
1718
import matplotlib.tests
1819
import matplotlib.units
1920
from matplotlib import cbook
@@ -329,3 +330,19 @@ def find_dotted_module(module_name, path=None):
329330
cbook.mkdirs(result_dir)
330331

331332
return baseline_dir, result_dir
333+
334+
335+
def switch_backend(backend):
336+
def switch_backend_decorator(func):
337+
def backend_switcher(*args, **kwargs):
338+
try:
339+
prev_backend = mpl.get_backend()
340+
matplotlib.tests.setup()
341+
plt.switch_backend(backend)
342+
result = func(*args, **kwargs)
343+
finally:
344+
plt.switch_backend(prev_backend)
345+
return result
346+
347+
return nose.tools.make_decorator(func)(backend_switcher)
348+
return switch_backend_decorator

‎lib/matplotlib/tests/test_backend_pgf.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_pgf.py
+1-18Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import matplotlib.pyplot as plt
1616
from matplotlib.compat import subprocess
1717
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
18-
from matplotlib.testing.decorators import _image_directories
18+
from matplotlib.testing.decorators import _image_directories, switch_backend
1919

2020

2121
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
@@ -41,23 +41,6 @@ def check_for(texsystem):
4141
return latex.returncode == 0
4242

4343

44-
def switch_backend(backend):
45-
46-
def switch_backend_decorator(func):
47-
def backend_switcher(*args, **kwargs):
48-
try:
49-
prev_backend = mpl.get_backend()
50-
mpl.rcdefaults()
51-
plt.switch_backend(backend)
52-
result = func(*args, **kwargs)
53-
finally:
54-
plt.switch_backend(prev_backend)
55-
return result
56-
57-
return nose.tools.make_decorator(func)(backend_switcher)
58-
return switch_backend_decorator
59-
60-
6144
def compare_figure(fname, savefig_kwargs={}):
6245
actual = os.path.join(result_dir, fname)
6346
plt.savefig(actual, **savefig_kwargs)

‎lib/matplotlib/tests/test_backend_qt4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt4.py
+3-5Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from matplotlib.externals import six
55
from matplotlib.externals.six import unichr
66
from matplotlib import pyplot as plt
7-
from matplotlib.testing.decorators import cleanup
7+
from matplotlib.testing.decorators import cleanup, switch_backend
88
from matplotlib.testing.decorators import knownfailureif
99
from matplotlib._pylab_helpers import Gcf
1010
import copy
@@ -31,10 +31,8 @@
3131

3232
@cleanup
3333
@knownfailureif(not HAS_QT)
34+
@switch_backend('Qt4Agg')
3435
def test_fig_close():
35-
# force switch to the Qt4 backend
36-
plt.switch_backend('Qt4Agg')
37-
3836
#save the state of Gcf.figs
3937
init_figs = copy.copy(Gcf.figs)
4038

@@ -50,14 +48,14 @@ def test_fig_close():
5048
assert(init_figs == Gcf.figs)
5149

5250

51+
@switch_backend('Qt4Agg')
5352
def assert_correct_key(qt_key, qt_mods, answer):
5453
"""
5554
Make a figure
5655
Send a key_press_event event (using non-public, qt4 backend specific api)
5756
Catch the event
5857
Assert sent and caught keys are the same
5958
"""
60-
plt.switch_backend('Qt4Agg')
6159
qt_canvas = plt.figure().canvas
6260

6361
event = mock.Mock()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.