From 3210f6af9c9c4b7f38f1bfebae66978fc9c13c92 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 2 Nov 2020 17:23:22 +0100 Subject: [PATCH] Add dependency on ucs for pgf tests using [utf8x]{inputenc}. `ucs` is a dependency of `\usepackage[utf8x]{inputenc}`, but if it is absent we fail later with the slightly confusing error message "Keyboard character used is undefined in inputencoding `utf8x'" (as can be observed by temporarily uninstalling `ucs`). Instead, make the dependency explicit. Also, in test_rcupdate, only one of the two iterations uses `[utf8x]{inputenc}`, so run the other iteration first (giving it a chance to fail) and skip the test only at the second iteration if needed. --- lib/matplotlib/tests/test_backend_pgf.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index e089ab4f9c33..3d488deca15d 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -46,9 +46,9 @@ def check_for(texsystem): reason='lualatex + pgf is required') -def _has_sfmath(): +def _has_tex_package(package): return (shutil.which("kpsewhich") - and subprocess.run(["kpsewhich", "sfmath.sty"], + and subprocess.run(["kpsewhich", f"{package}.sty"], stdout=subprocess.PIPE).returncode == 0) @@ -113,6 +113,7 @@ def test_xelatex(): # test compiling a figure to pdf with pdflatex @needs_pdflatex +@pytest.mark.skipif(not _has_tex_package('ucs'), reason='needs ucs.sty') @pytest.mark.backend('pgf') @image_comparison(['pgf_pdflatex.pdf'], style='default') def test_pdflatex(): @@ -132,7 +133,6 @@ def test_pdflatex(): # test updating the rc parameters for each figure @needs_xelatex @needs_pdflatex -@pytest.mark.skipif(not _has_sfmath(), reason='needs sfmath.sty') @pytest.mark.style('default') @pytest.mark.backend('pgf') def test_rcupdate(): @@ -154,6 +154,10 @@ def test_rcupdate(): tol = [6, 0] for i, rc_set in enumerate(rc_sets): with mpl.rc_context(rc_set): + for substring, pkg in [('sfmath', 'sfmath'), ('utf8x', 'ucs')]: + if (substring in mpl.rcParams['pgf.preamble'] + and not _has_tex_package(pkg)): + pytest.skip(f'needs {pkg}.sty') create_figure() compare_figure('pgf_rcupdate%d.pdf' % (i + 1), tol=tol[i])