|
1 | 1 | import os |
| 2 | +from pathlib import Path |
2 | 3 | import shutil |
3 | 4 | import subprocess |
| 5 | +from tempfile import TemporaryDirectory |
4 | 6 |
|
5 | 7 | import numpy as np |
6 | 8 | import pytest |
|
15 | 17 |
|
16 | 18 |
|
17 | 19 | def check_for(texsystem): |
18 | | - header = """ |
19 | | - \\documentclass{minimal} |
20 | | - \\usepackage{pgf} |
21 | | - \\begin{document} |
22 | | - \\typeout{pgfversion=\\pgfversion} |
23 | | - \\makeatletter |
24 | | - \\@@end |
25 | | - """ |
26 | | - try: |
27 | | - latex = subprocess.Popen([str(texsystem), "-halt-on-error"], |
28 | | - stdin=subprocess.PIPE, |
29 | | - stdout=subprocess.PIPE) |
30 | | - stdout, stderr = latex.communicate(header.encode("utf8")) |
31 | | - except OSError: |
32 | | - return False |
33 | | - |
34 | | - return latex.returncode == 0 |
| 20 | + with TemporaryDirectory() as tmpdir: |
| 21 | + tex_path = Path(tmpdir, "test.tex") |
| 22 | + tex_path.write_text(r""" |
| 23 | + \documentclass{minimal} |
| 24 | + \usepackage{pgf} |
| 25 | + \begin{document} |
| 26 | + \typeout{pgfversion=\pgfversion} |
| 27 | + \makeatletter |
| 28 | + \@@end |
| 29 | + """) |
| 30 | + try: |
| 31 | + subprocess.check_call( |
| 32 | + [texsystem, "-halt-on-error", str(tex_path)], cwd=tmpdir, |
| 33 | + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 34 | + except (OSError, subprocess.CalledProcessError): |
| 35 | + return False |
| 36 | + return True |
35 | 37 |
|
36 | 38 |
|
37 | 39 | needs_xelatex = pytest.mark.skipif(not check_for('xelatex'), |
@@ -97,7 +99,6 @@ def test_xelatex(): |
97 | 99 | @image_comparison(baseline_images=['pgf_pdflatex'], extensions=['pdf'], |
98 | 100 | style='default') |
99 | 101 | def test_pdflatex(): |
100 | | - import os |
101 | 102 | if os.environ.get('APPVEYOR', False): |
102 | 103 | pytest.xfail("pdflatex test does not work on appveyor due to missing " |
103 | 104 | "LaTeX fonts") |
|
0 commit comments