From 3154eb02293aa34a77008a3c963068826e2db269 Mon Sep 17 00:00:00 2001 From: Oscar Gustafsson Date: Sat, 14 May 2022 11:58:57 +0200 Subject: [PATCH] MNT: Move locally defined test marks --- .../deprecations/23045-OG.rst | 7 +++ lib/matplotlib/__init__.py | 1 + lib/matplotlib/testing/_markers.py | 48 +++++++++++++++++++ lib/matplotlib/tests/test_backend_bases.py | 5 +- lib/matplotlib/tests/test_backend_pdf.py | 8 +--- lib/matplotlib/tests/test_backend_pgf.py | 18 ++----- lib/matplotlib/tests/test_backend_ps.py | 8 +--- lib/matplotlib/tests/test_backend_svg.py | 9 +--- lib/matplotlib/tests/test_determinism.py | 9 +--- lib/matplotlib/tests/test_legend.py | 5 +- lib/matplotlib/tests/test_text.py | 6 +-- lib/matplotlib/tests/test_usetex.py | 4 +- 12 files changed, 73 insertions(+), 55 deletions(-) create mode 100644 doc/api/next_api_changes/deprecations/23045-OG.rst create mode 100644 lib/matplotlib/testing/_markers.py diff --git a/doc/api/next_api_changes/deprecations/23045-OG.rst b/doc/api/next_api_changes/deprecations/23045-OG.rst new file mode 100644 index 000000000000..e10c410999ad --- /dev/null +++ b/doc/api/next_api_changes/deprecations/23045-OG.rst @@ -0,0 +1,7 @@ +``checkdep_usetex`` deprecated +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +This method was only intended to disable tests in case no latex install was +found. As such, it is considered to be private and for internal use only. + +Please vendor the code if you need this. diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 7df511af1e16..7e83e7369b03 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -434,6 +434,7 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False): raise ValueError("Unknown executable: {!r}".format(name)) +@_api.deprecated("3.6", alternative="Vendor the code") def checkdep_usetex(s): if not s: return False diff --git a/lib/matplotlib/testing/_markers.py b/lib/matplotlib/testing/_markers.py new file mode 100644 index 000000000000..fc35df665696 --- /dev/null +++ b/lib/matplotlib/testing/_markers.py @@ -0,0 +1,48 @@ +""" +pytest markers for the internal Matplotlib test suite. +""" + +import logging +import shutil + +import pytest + +import matplotlib.testing +from matplotlib import _get_executable_info, ExecutableNotFoundError + + +_log = logging.getLogger(__name__) + + +def _checkdep_usetex(): + if not shutil.which("tex"): + _log.warning("usetex mode requires TeX.") + return False + try: + _get_executable_info("dvipng") + except ExecutableNotFoundError: + _log.warning("usetex mode requires dvipng.") + return False + try: + _get_executable_info("gs") + except ExecutableNotFoundError: + _log.warning("usetex mode requires ghostscript.") + return False + return True + + +needs_ghostscript = pytest.mark.skipif( + "eps" not in matplotlib.testing.compare.converter, + reason="This test needs a ghostscript installation") +needs_lualatex = pytest.mark.skipif( + not matplotlib.testing._check_for_pgf('lualatex'), + reason='lualatex + pgf is required') +needs_pdflatex = pytest.mark.skipif( + not matplotlib.testing._check_for_pgf('pdflatex'), + reason='pdflatex + pgf is required') +needs_usetex = pytest.mark.skipif( + not _checkdep_usetex(), + reason="This test needs a TeX installation") +needs_xelatex = pytest.mark.skipif( + not matplotlib.testing._check_for_pgf('xelatex'), + reason='xelatex + pgf is required') diff --git a/lib/matplotlib/tests/test_backend_bases.py b/lib/matplotlib/tests/test_backend_bases.py index ed3cc134bfb1..b7e32a19dd18 100644 --- a/lib/matplotlib/tests/test_backend_bases.py +++ b/lib/matplotlib/tests/test_backend_bases.py @@ -1,19 +1,16 @@ import re from matplotlib import path, transforms -from matplotlib.testing import _check_for_pgf from matplotlib.backend_bases import ( FigureCanvasBase, LocationEvent, MouseButton, MouseEvent, NavigationToolbar2, RendererBase) from matplotlib.figure import Figure +from matplotlib.testing._markers import needs_xelatex import matplotlib.pyplot as plt import numpy as np import pytest -needs_xelatex = pytest.mark.skipif(not _check_for_pgf('xelatex'), - reason='xelatex + pgf is required') - def test_uses_per_path(): id = transforms.Affine2D() diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index 71a253a20851..5c77ffa2a740 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -9,7 +9,7 @@ import pytest import matplotlib as mpl -from matplotlib import pyplot as plt, checkdep_usetex, rcParams +from matplotlib import pyplot as plt, rcParams from matplotlib.cbook import _get_data_path from matplotlib.ft2font import FT2Font from matplotlib.font_manager import findfont, FontProperties @@ -17,11 +17,7 @@ from matplotlib.backends.backend_pdf import PdfPages from matplotlib.patches import Rectangle from matplotlib.testing.decorators import check_figures_equal, image_comparison - - -needs_usetex = pytest.mark.skipif( - not checkdep_usetex(True), - reason="This test needs a TeX installation") +from matplotlib.testing._markers import needs_usetex @image_comparison(['pdf_use14corefonts.pdf']) diff --git a/lib/matplotlib/tests/test_backend_pgf.py b/lib/matplotlib/tests/test_backend_pgf.py index dc64eb351c5e..4c1d1763d7a9 100644 --- a/lib/matplotlib/tests/test_backend_pgf.py +++ b/lib/matplotlib/tests/test_backend_pgf.py @@ -12,21 +12,13 @@ from matplotlib.testing import _has_tex_package, _check_for_pgf from matplotlib.testing.compare import compare_images, ImageComparisonFailure from matplotlib.backends.backend_pgf import PdfPages, _tex_escape -from matplotlib.testing.decorators import (_image_directories, - check_figures_equal, - image_comparison) +from matplotlib.testing.decorators import ( + _image_directories, check_figures_equal, image_comparison) +from matplotlib.testing._markers import ( + needs_ghostscript, needs_lualatex, needs_pdflatex, needs_xelatex) -baseline_dir, result_dir = _image_directories(lambda: 'dummy func') -needs_xelatex = pytest.mark.skipif(not _check_for_pgf('xelatex'), - reason='xelatex + pgf is required') -needs_pdflatex = pytest.mark.skipif(not _check_for_pgf('pdflatex'), - reason='pdflatex + pgf is required') -needs_lualatex = pytest.mark.skipif(not _check_for_pgf('lualatex'), - reason='lualatex + pgf is required') -needs_ghostscript = pytest.mark.skipif( - "eps" not in mpl.testing.compare.converter, - reason="This test needs a ghostscript installation") +baseline_dir, result_dir = _image_directories(lambda: 'dummy func') def compare_figure(fname, savefig_kwargs={}, tol=0): diff --git a/lib/matplotlib/tests/test_backend_ps.py b/lib/matplotlib/tests/test_backend_ps.py index 380204b8fa67..5737b6fddbca 100644 --- a/lib/matplotlib/tests/test_backend_ps.py +++ b/lib/matplotlib/tests/test_backend_ps.py @@ -11,16 +11,10 @@ from matplotlib.figure import Figure from matplotlib.patches import Ellipse from matplotlib.testing.decorators import check_figures_equal, image_comparison +from matplotlib.testing._markers import needs_ghostscript, needs_usetex import matplotlib as mpl import matplotlib.pyplot as plt -needs_ghostscript = pytest.mark.skipif( - "eps" not in mpl.testing.compare.converter, - reason="This test needs a ghostscript installation") -needs_usetex = pytest.mark.skipif( - not mpl.checkdep_usetex(True), - reason="This test needs a TeX installation") - # This tests tends to hit a TeX cache lock on AppVeyor. @pytest.mark.flaky(reruns=3) diff --git a/lib/matplotlib/tests/test_backend_svg.py b/lib/matplotlib/tests/test_backend_svg.py index 84b56aea20fa..656758c851e1 100644 --- a/lib/matplotlib/tests/test_backend_svg.py +++ b/lib/matplotlib/tests/test_backend_svg.py @@ -4,18 +4,13 @@ import xml.parsers.expat import numpy as np -import pytest import matplotlib as mpl from matplotlib.figure import Figure from matplotlib.text import Text import matplotlib.pyplot as plt -from matplotlib.testing.decorators import image_comparison, check_figures_equal - - -needs_usetex = pytest.mark.skipif( - not mpl.checkdep_usetex(True), - reason="This test needs a TeX installation") +from matplotlib.testing.decorators import check_figures_equal, image_comparison +from matplotlib.testing._markers import needs_usetex def test_visibility(): diff --git a/lib/matplotlib/tests/test_determinism.py b/lib/matplotlib/tests/test_determinism.py index cce05f12dacd..fe0fb34e128a 100644 --- a/lib/matplotlib/tests/test_determinism.py +++ b/lib/matplotlib/tests/test_determinism.py @@ -11,14 +11,7 @@ import matplotlib as mpl import matplotlib.testing.compare from matplotlib import pyplot as plt - - -needs_ghostscript = pytest.mark.skipif( - "eps" not in mpl.testing.compare.converter, - reason="This test needs a ghostscript installation") -needs_usetex = pytest.mark.skipif( - not mpl.checkdep_usetex(True), - reason="This test needs a TeX installation") +from matplotlib.testing._markers import needs_ghostscript, needs_usetex def _save_figure(objects='mhi', fmt="pdf", usetex=False): diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 629191282175..7946eb3c8ed1 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -6,6 +6,7 @@ import pytest from matplotlib.testing.decorators import image_comparison +from matplotlib.testing._markers import needs_usetex import matplotlib.pyplot as plt import matplotlib as mpl import matplotlib.transforms as mtransforms @@ -764,9 +765,7 @@ def test_alpha_handles(): assert lh.get_edgecolor()[:-1] == hh[1].get_edgecolor()[:-1] -@pytest.mark.skipif( - not mpl.checkdep_usetex(True), - reason="This test needs a TeX installation") +@needs_usetex def test_usetex_no_warn(caplog): mpl.rcParams['font.family'] = 'serif' mpl.rcParams['font.serif'] = 'Computer Modern' diff --git a/lib/matplotlib/tests/test_text.py b/lib/matplotlib/tests/test_text.py index ae8cdd4257d3..2c2fcd7fbafd 100644 --- a/lib/matplotlib/tests/test_text.py +++ b/lib/matplotlib/tests/test_text.py @@ -13,14 +13,10 @@ import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms from matplotlib.testing.decorators import check_figures_equal, image_comparison +from matplotlib.testing._markers import needs_usetex from matplotlib.text import Text -needs_usetex = pytest.mark.skipif( - not mpl.checkdep_usetex(True), - reason="This test needs a TeX installation") - - @image_comparison(['font_styles']) def test_font_styles(): diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index c8bc10e8bcf6..22309afdaf97 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -7,11 +7,11 @@ from matplotlib import dviread from matplotlib.testing import _has_tex_package from matplotlib.testing.decorators import check_figures_equal, image_comparison +from matplotlib.testing._markers import needs_usetex import matplotlib.pyplot as plt -if not mpl.checkdep_usetex(True): - pytestmark = pytest.mark.skip('Missing TeX of Ghostscript or dvipng') +pytestmark = needs_usetex @image_comparison(