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

Skip to content

Commit bf725a0

Browse files
author
pwuertz
committed
backend_pgf: check latex+pgf environment when running tests
1 parent 6b57189 commit bf725a0

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,21 @@
1111

1212
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
1313

14-
def run(*args):
15-
try:
16-
subprocess.check_output(args)
17-
return True
18-
except:
19-
return False
14+
def check_for(texsystem):
15+
header = r"""
16+
\documentclass{minimal}
17+
\usepackage{pgf}
18+
\begin{document}
19+
\typeout{pgfversion=\pgfversion}
20+
\makeatletter
21+
\@@end
22+
"""
23+
latex = subprocess.Popen(["xelatex", "-halt-on-error"],
24+
stdin=subprocess.PIPE,
25+
stdout=subprocess.PIPE)
26+
stdout, stderr = latex.communicate(header.encode("utf8"))
27+
28+
return latex.returncode == 0
2029

2130
def switch_backend(backend):
2231
import nose
@@ -58,7 +67,7 @@ def create_figure():
5867

5968

6069
# test compiling a figure to pdf with xelatex
61-
@knownfailureif(not run('xelatex', '-v'), msg="xelatex is required for this test")
70+
@knownfailureif(not check_for('xelatex'), msg='xelatex + pgf is required')
6271
@switch_backend('pgf')
6372
def test_xelatex():
6473
rc_xelatex = {'font.family': 'serif',
@@ -69,7 +78,7 @@ def test_xelatex():
6978

7079

7180
# test compiling a figure to pdf with pdflatex
72-
@knownfailureif(not run('pdflatex', '-v'), msg="pdflatex is required for this test")
81+
@knownfailureif(not check_for('pdflatex'), msg='pdflatex + pgf is required')
7382
@switch_backend('pgf')
7483
def test_pdflatex():
7584
rc_pdflatex = {'font.family': 'serif',
@@ -83,8 +92,8 @@ def test_pdflatex():
8392

8493

8594
# test updating the rc parameters for each figure
86-
@knownfailureif(not run('pdflatex', '-v') or not run('xelatex', '-v'),
87-
msg="xelatex and pdflatex are required for this test")
95+
@knownfailureif(not check_for('xelatex') or not check_for('pdflatex'),
96+
msg="xelatex and pdflatex + pgf required")
8897
@switch_backend('pgf')
8998
def test_rcupdate():
9099
rc_sets = []

0 commit comments

Comments
 (0)