@@ -152,47 +152,43 @@ def _test_determinism_save(filename, usetex):
152
152
FigureCanvasSVG (fig ).print_svg (filename )
153
153
154
154
155
- def _test_determinism (filename , usetex ):
155
+ @pytest .mark .parametrize (
156
+ "filename, usetex" ,
157
+ # unique filenames to allow for parallel testing
158
+ [("determinism_notex.svg" , False ),
159
+ needs_usetex (("determinism_tex.svg" , True ))])
160
+ def test_determinism (filename , usetex ):
156
161
import sys
157
162
from subprocess import check_output , STDOUT , CalledProcessError
158
163
plots = []
159
164
for i in range (3 ):
160
165
# Using check_output and setting stderr to STDOUT will capture the real
161
166
# problem in the output property of the exception
162
167
try :
163
- check_output ([ sys . executable , '-R' , '-c' ,
164
- 'import matplotlib; '
165
- 'matplotlib._called_from_pytest = True; '
166
- 'matplotlib.use("svg") ; '
167
- 'from matplotlib.tests.test_backend_svg '
168
- 'import _test_determinism_save; '
169
- '_test_determinism_save(%r, %r)' % ( filename ,
170
- usetex )],
171
- stderr = STDOUT )
168
+ check_output (
169
+ [ sys . executable , '-R' , '-c' ,
170
+ 'import matplotlib; '
171
+ 'matplotlib._called_from_pytest = True ; '
172
+ ' matplotlib.use("svg"); '
173
+ 'from matplotlib.tests.test_backend_svg '
174
+ 'import _test_determinism_save;'
175
+ '_test_determinism_save(%r, %r)' % ( filename , usetex )],
176
+ stderr = STDOUT )
172
177
except CalledProcessError as e :
173
178
# it's easier to use utf8 and ask for forgiveness than try
174
179
# to figure out what the current console has as an
175
180
# encoding :-/
176
181
print (e .output .decode (encoding = "utf-8" , errors = "ignore" ))
177
182
raise e
178
- with open (filename , 'rb' ) as fd :
179
- plots .append (fd .read ())
180
- os .unlink (filename )
183
+ else :
184
+ with open (filename , 'rb' ) as fd :
185
+ plots .append (fd .read ())
186
+ finally :
187
+ os .unlink (filename )
181
188
for p in plots [1 :]:
182
189
assert p == plots [0 ]
183
190
184
191
185
- def test_determinism_notex ():
186
- # unique filename to allow for parallel testing
187
- _test_determinism ('determinism_notex.svg' , usetex = False )
188
-
189
-
190
- @needs_usetex
191
- def test_determinism_tex ():
192
- # unique filename to allow for parallel testing
193
- _test_determinism ('determinism_tex.svg' , usetex = True )
194
-
195
-
196
192
@needs_usetex
197
193
def test_missing_psfont (monkeypatch ):
198
194
"""An error is raised if a TeX font lacks a Type-1 equivalent"""
0 commit comments