Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commiteef58c5

Browse files
committed
Use pytest fixture+marker instead of switch_backend.
Non default backends can be specified by marking test functions with`@pytest.mark.backend('backend')`.Note that because switch_backend calls `matplotlib.testing.setup`, andit appears _below_ the previous `@cleanup` decorator in the PGF tests,the specified 'classic' style is not actually used for those tests.
1 parenta6ca70d commiteef58c5

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

‎lib/matplotlib/tests/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,33 @@ def mpl_test_settings(request):
1313
original_units_registry=matplotlib.units.registry.copy()
1414
original_settings=matplotlib.rcParams.copy()
1515

16+
backend=None
17+
backend_marker=request.keywords.get('backend')
18+
ifbackend_markerisnotNone:
19+
assertlen(backend_marker.args)==1, \
20+
"Marker 'backend' must specify 1 backend."
21+
backend=backend_marker.args[0]
22+
prev_backend=matplotlib.get_backend()
23+
1624
style='classic'
1725
style_marker=request.keywords.get('style')
1826
ifstyle_markerisnotNone:
1927
assertlen(style_marker.args)==1, \
2028
"Marker 'style' must specify 1 style."
2129
style=style_marker.args[0]
2230

31+
matplotlib.testing.setup()
32+
ifbackendisnotNone:
33+
# This import must come after setup() so it doesn't load the default
34+
# backend prematurely.
35+
importmatplotlib.pyplotasplt
36+
plt.switch_backend(backend)
2337
matplotlib.style.use(style)
2438
try:
2539
yield
2640
finally:
41+
ifbackendisnotNone:
42+
importmatplotlib.pyplotasplt
43+
plt.switch_backend(prev_backend)
2744
_do_cleanup(original_units_registry,
2845
original_settings)

‎lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
importmatplotlib.pyplotasplt
1313
frommatplotlib.compatimportsubprocess
1414
frommatplotlib.testing.compareimportcompare_images,ImageComparisonFailure
15-
frommatplotlib.testing.decoratorsimport_image_directories,switch_backend
15+
frommatplotlib.testing.decoratorsimport_image_directories
1616

1717
baseline_dir,result_dir=_image_directories(lambda:'dummy func')
1818

@@ -82,8 +82,8 @@ def create_figure():
8282

8383
# test compiling a figure to pdf with xelatex
8484
@needs_xelatex
85-
@pytest.mark.style('classic')
86-
@switch_backend('pgf')
85+
@pytest.mark.style('default')
86+
@pytest.mark.backend('pgf')
8787
deftest_xelatex():
8888
rc_xelatex= {'font.family':'serif',
8989
'pgf.rcfonts':False}
@@ -94,8 +94,8 @@ def test_xelatex():
9494

9595
# test compiling a figure to pdf with pdflatex
9696
@needs_pdflatex
97-
@pytest.mark.style('classic')
98-
@switch_backend('pgf')
97+
@pytest.mark.style('default')
98+
@pytest.mark.backend('pgf')
9999
deftest_pdflatex():
100100
importos
101101
ifos.environ.get('APPVEYOR',False):
@@ -116,8 +116,8 @@ def test_pdflatex():
116116
# test updating the rc parameters for each figure
117117
@needs_xelatex
118118
@needs_pdflatex
119-
@pytest.mark.style('classic')
120-
@switch_backend('pgf')
119+
@pytest.mark.style('default')
120+
@pytest.mark.backend('pgf')
121121
deftest_rcupdate():
122122
rc_sets= []
123123
rc_sets.append({'font.family':'sans-serif',
@@ -147,8 +147,8 @@ def test_rcupdate():
147147

148148
# test backend-side clipping, since large numbers are not supported by TeX
149149
@needs_xelatex
150-
@pytest.mark.style('classic')
151-
@switch_backend('pgf')
150+
@pytest.mark.style('default')
151+
@pytest.mark.backend('pgf')
152152
deftest_pathclip():
153153
rc_xelatex= {'font.family':'serif',
154154
'pgf.rcfonts':False}
@@ -164,8 +164,8 @@ def test_pathclip():
164164

165165
# test mixed mode rendering
166166
@needs_xelatex
167-
@pytest.mark.style('classic')
168-
@switch_backend('pgf')
167+
@pytest.mark.style('default')
168+
@pytest.mark.backend('pgf')
169169
deftest_mixedmode():
170170
rc_xelatex= {'font.family':'serif',
171171
'pgf.rcfonts':False}
@@ -179,8 +179,8 @@ def test_mixedmode():
179179

180180
# test bbox_inches clipping
181181
@needs_xelatex
182-
@pytest.mark.style('classic')
183-
@switch_backend('pgf')
182+
@pytest.mark.style('default')
183+
@pytest.mark.backend('pgf')
184184
deftest_bbox_inches():
185185
rc_xelatex= {'font.family':'serif',
186186
'pgf.rcfonts':False}

‎lib/matplotlib/tests/test_backend_qt4.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
unicode_literals)
33

44
frommatplotlibimportpyplotasplt
5-
frommatplotlib.testing.decoratorsimportswitch_backend
65
frommatplotlib._pylab_helpersimportGcf
76
importmatplotlib
87
importcopy
@@ -34,7 +33,7 @@
3433
pytestmark=pytest.mark.xfail(reason='Qt4 is not available')
3534

3635

37-
@switch_backend('Qt4Agg')
36+
@pytest.mark.backend('Qt4Agg')
3837
deftest_fig_close():
3938
# save the state of Gcf.figs
4039
init_figs=copy.copy(Gcf.figs)
@@ -83,7 +82,7 @@ def test_fig_close():
8382
'non_unicode_key',
8483
]
8584
)
86-
@switch_backend('Qt4Agg')
85+
@pytest.mark.backend('Qt4Agg')
8786
deftest_correct_key(qt_key,qt_mods,answer):
8887
"""
8988
Make a figure

‎lib/matplotlib/tests/test_backend_qt5.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
unicode_literals)
33

44
frommatplotlibimportpyplotasplt
5-
frommatplotlib.testing.decoratorsimportswitch_backend
65
frommatplotlib._pylab_helpersimportGcf
76
importmatplotlib
87
importcopy
@@ -27,7 +26,7 @@
2726
_,ShiftModifier,ShiftKey=MODIFIER_KEYS[SHIFT]
2827

2928

30-
@switch_backend('Qt5Agg')
29+
@pytest.mark.backend('Qt5Agg')
3130
deftest_fig_close():
3231
# save the state of Gcf.figs
3332
init_figs=copy.copy(Gcf.figs)
@@ -76,7 +75,7 @@ def test_fig_close():
7675
'non_unicode_key',
7776
]
7877
)
79-
@switch_backend('Qt5Agg')
78+
@pytest.mark.backend('Qt5Agg')
8079
deftest_correct_key(qt_key,qt_mods,answer):
8180
"""
8281
Make a figure

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp