Skip to content

MNT: Merge locally defined test marks #23045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/api/next_api_changes/deprecations/23045-OG.rst
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 48 additions & 0 deletions lib/matplotlib/testing/_markers.py
Original file line number Diff line number Diff line change
@@ -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(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oscargus Sorry I missed this before merging, but these names seem not so optimal now? needs_{lua,pdf,xe}latex now check both for the tex engine, and for the presence of pgf (this was less of an issue when the marks were local to test_backend_pgf. Perhaps rename them to needs_{lua,pdf,xe}tex_pgf? (Or just move them back to being local to the pgf backend test suite.)

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')
5 changes: 1 addition & 4 deletions lib/matplotlib/tests/test_backend_bases.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
8 changes: 2 additions & 6 deletions lib/matplotlib/tests/test_backend_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
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
from matplotlib.backends._backend_pdf_ps import get_glyphs_subset
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'])
Expand Down
18 changes: 5 additions & 13 deletions lib/matplotlib/tests/test_backend_pgf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 1 addition & 7 deletions lib/matplotlib/tests/test_backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 2 additions & 7 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
9 changes: 1 addition & 8 deletions lib/matplotlib/tests/test_determinism.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/tests/test_legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
6 changes: 1 addition & 5 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():

Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_usetex.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down