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 2875d61

Browse filesBrowse files
committed
Improve test_backend_svg.test_determinism.
1. Use standard parametrization mechanisms. 2. Always cleanup the created temporary file, even if the subprocess fails (e.g. due to missing tex packages).
1 parent 2dc0930 commit 2875d61
Copy full SHA for 2875d61

File tree

Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+20
-24
lines changed

‎lib/matplotlib/tests/test_backend_svg.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_svg.py
+20-24Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.