|
1 | 1 | import datetime |
2 | 2 | from io import BytesIO |
3 | 3 | import os |
4 | | -from pathlib import Path |
5 | 4 | import shutil |
6 | 5 | import subprocess |
7 | | -from tempfile import TemporaryDirectory |
8 | 6 |
|
9 | 7 | import numpy as np |
10 | 8 | import pytest |
11 | 9 |
|
12 | 10 | import matplotlib as mpl |
13 | 11 | import matplotlib.pyplot as plt |
| 12 | +from matplotlib.testing import check_for_pgf |
14 | 13 | from matplotlib.testing.compare import compare_images, ImageComparisonFailure |
15 | 14 | from matplotlib.backends.backend_pgf import PdfPages, common_texification |
16 | 15 | from matplotlib.testing.decorators import (_image_directories, |
|
19 | 18 |
|
20 | 19 | baseline_dir, result_dir = _image_directories(lambda: 'dummy func') |
21 | 20 |
|
22 | | - |
23 | | -def check_for(texsystem): |
24 | | - with TemporaryDirectory() as tmpdir: |
25 | | - tex_path = Path(tmpdir, "test.tex") |
26 | | - tex_path.write_text(r""" |
27 | | - \documentclass{minimal} |
28 | | - \usepackage{pgf} |
29 | | - \begin{document} |
30 | | - \typeout{pgfversion=\pgfversion} |
31 | | - \makeatletter |
32 | | - \@@end |
33 | | - """) |
34 | | - try: |
35 | | - subprocess.check_call( |
36 | | - [texsystem, "-halt-on-error", str(tex_path)], cwd=tmpdir, |
37 | | - stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
38 | | - except (OSError, subprocess.CalledProcessError): |
39 | | - return False |
40 | | - return True |
41 | | - |
42 | | - |
43 | | -needs_xelatex = pytest.mark.skipif(not check_for('xelatex'), |
| 21 | +needs_xelatex = pytest.mark.skipif(not check_for_pgf('xelatex'), |
44 | 22 | reason='xelatex + pgf is required') |
45 | | -needs_pdflatex = pytest.mark.skipif(not check_for('pdflatex'), |
| 23 | +needs_pdflatex = pytest.mark.skipif(not check_for_pgf('pdflatex'), |
46 | 24 | reason='pdflatex + pgf is required') |
47 | | -needs_lualatex = pytest.mark.skipif(not check_for('lualatex'), |
| 25 | +needs_lualatex = pytest.mark.skipif(not check_for_pgf('lualatex'), |
48 | 26 | reason='lualatex + pgf is required') |
49 | 27 | needs_ghostscript = pytest.mark.skipif( |
50 | 28 | "eps" not in mpl.testing.compare.converter, |
@@ -338,7 +316,7 @@ def test_unknown_font(caplog): |
338 | 316 | @pytest.mark.parametrize("texsystem", ("pdflatex", "xelatex", "lualatex")) |
339 | 317 | @pytest.mark.backend("pgf") |
340 | 318 | def test_minus_signs_with_tex(fig_test, fig_ref, texsystem): |
341 | | - if not check_for(texsystem): |
| 319 | + if not check_for_pgf(texsystem): |
342 | 320 | pytest.skip(texsystem + ' + pgf is required') |
343 | 321 | mpl.rcParams["pgf.texsystem"] = texsystem |
344 | 322 | fig_test.text(.5, .5, "$-1$") |
|
0 commit comments