Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6798266

Browse files
authored
Merge pull request #9487 from anntzer/determinism_tex-test
Improve test_backend_svg.test_determinism.
2 parents 2dc0930 + 2875d61 commit 6798266

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

lib/matplotlib/tests/test_backend_svg.py

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -152,47 +152,43 @@ def _test_determinism_save(filename, usetex):
152152
FigureCanvasSVG(fig).print_svg(filename)
153153

154154

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):
156161
import sys
157162
from subprocess import check_output, STDOUT, CalledProcessError
158163
plots = []
159164
for i in range(3):
160165
# Using check_output and setting stderr to STDOUT will capture the real
161166
# problem in the output property of the exception
162167
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)
172177
except CalledProcessError as e:
173178
# it's easier to use utf8 and ask for forgiveness than try
174179
# to figure out what the current console has as an
175180
# encoding :-/
176181
print(e.output.decode(encoding="utf-8", errors="ignore"))
177182
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)
181188
for p in plots[1:]:
182189
assert p == plots[0]
183190

184191

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-
196192
@needs_usetex
197193
def test_missing_psfont(monkeypatch):
198194
"""An error is raised if a TeX font lacks a Type-1 equivalent"""

0 commit comments

Comments
 (0)