66import shutil
77
88import numpy as np
9- from nose . plugins . skip import SkipTest
9+ import pytest
1010
1111import matplotlib as mpl
1212import matplotlib .pyplot as plt
@@ -38,6 +38,12 @@ def check_for(texsystem):
3838 return latex .returncode == 0
3939
4040
41+ needs_xelatex = pytest .mark .skipif (not check_for ('xelatex' ),
42+ reason = 'xelatex + pgf is required' )
43+ needs_pdflatex = pytest .mark .skipif (not check_for ('pdflatex' ),
44+ reason = 'pdflatex + pgf is required' )
45+
46+
4147def compare_figure (fname , savefig_kwargs = {}, tol = 0 ):
4248 actual = os .path .join (result_dir , fname )
4349 plt .savefig (actual , ** savefig_kwargs )
@@ -76,12 +82,10 @@ def create_figure():
7682
7783
7884# test compiling a figure to pdf with xelatex
85+ @needs_xelatex
7986@cleanup (style = 'classic' )
8087@switch_backend ('pgf' )
8188def test_xelatex ():
82- if not check_for ('xelatex' ):
83- raise SkipTest ('xelatex + pgf is required' )
84-
8589 rc_xelatex = {'font.family' : 'serif' ,
8690 'pgf.rcfonts' : False }
8791 mpl .rcParams .update (rc_xelatex )
@@ -90,6 +94,7 @@ def test_xelatex():
9094
9195
9296# test compiling a figure to pdf with pdflatex
97+ @needs_pdflatex
9398@cleanup (style = 'classic' )
9499@switch_backend ('pgf' )
95100def test_pdflatex ():
@@ -98,8 +103,6 @@ def test_pdflatex():
98103 from matplotlib .testing import xfail
99104 xfail ("pdflatex test does not work on appveyor due "
100105 "to missing latex fonts" )
101- if not check_for ('pdflatex' ):
102- raise SkipTest ('pdflatex + pgf is required' )
103106
104107 rc_pdflatex = {'font.family' : 'serif' ,
105108 'pgf.rcfonts' : False ,
@@ -112,12 +115,11 @@ def test_pdflatex():
112115
113116
114117# test updating the rc parameters for each figure
118+ @needs_xelatex
119+ @needs_pdflatex
115120@cleanup (style = 'classic' )
116121@switch_backend ('pgf' )
117122def test_rcupdate ():
118- if not check_for ('xelatex' ) or not check_for ('pdflatex' ):
119- raise SkipTest ('xelatex and pdflatex + pgf required' )
120-
121123 rc_sets = []
122124 rc_sets .append ({'font.family' : 'sans-serif' ,
123125 'font.size' : 30 ,
@@ -145,12 +147,10 @@ def test_rcupdate():
145147
146148
147149# test backend-side clipping, since large numbers are not supported by TeX
150+ @needs_xelatex
148151@cleanup (style = 'classic' )
149152@switch_backend ('pgf' )
150153def test_pathclip ():
151- if not check_for ('xelatex' ):
152- raise SkipTest ('xelatex + pgf is required' )
153-
154154 rc_xelatex = {'font.family' : 'serif' ,
155155 'pgf.rcfonts' : False }
156156 mpl .rcParams .update (rc_xelatex )
@@ -164,12 +164,10 @@ def test_pathclip():
164164
165165
166166# test mixed mode rendering
167+ @needs_xelatex
167168@cleanup (style = 'classic' )
168169@switch_backend ('pgf' )
169170def test_mixedmode ():
170- if not check_for ('xelatex' ):
171- raise SkipTest ('xelatex + pgf is required' )
172-
173171 rc_xelatex = {'font.family' : 'serif' ,
174172 'pgf.rcfonts' : False }
175173 mpl .rcParams .update (rc_xelatex )
@@ -181,12 +179,10 @@ def test_mixedmode():
181179
182180
183181# test bbox_inches clipping
182+ @needs_xelatex
184183@cleanup (style = 'classic' )
185184@switch_backend ('pgf' )
186185def test_bbox_inches ():
187- if not check_for ('xelatex' ):
188- raise SkipTest ('xelatex + pgf is required' )
189-
190186 rc_xelatex = {'font.family' : 'serif' ,
191187 'pgf.rcfonts' : False }
192188 mpl .rcParams .update (rc_xelatex )
@@ -202,8 +198,3 @@ def test_bbox_inches():
202198 bbox = ax1 .get_window_extent ().transformed (fig .dpi_scale_trans .inverted ())
203199 compare_figure ('pgf_bbox_inches.pdf' , savefig_kwargs = {'bbox_inches' : bbox },
204200 tol = 0 )
205-
206-
207- if __name__ == '__main__' :
208- import nose
209- nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
0 commit comments