Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 170db62

Browse files
committed
MNT: Move locally defined test decorators
1 parent 07f8987 commit 170db62

File tree

12 files changed

+69
-61
lines changed

12 files changed

+69
-61
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
``checkdep_usetex`` deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
This method was only intended to disable tests in case no latex install was
5+
found. As such, it is considered to be private and for internal use only.
6+
7+
Please vendor the code if you need this.

‎lib/matplotlib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ def impl(args, regex, min_ver=None, ignore_exit_code=False):
434434
raise ValueError("Unknown executable: {!r}".format(name))
435435

436436

437+
@_api.deprecated("3.6", alternative="Vendor the code")
437438
def checkdep_usetex(s):
438439
if not s:
439440
return False

‎lib/matplotlib/testing/decorators.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import contextlib
22
import functools
33
import inspect
4+
import logging
45
import os
56
from pathlib import Path
67
import shutil
@@ -14,11 +15,13 @@
1415
import matplotlib.style
1516
import matplotlib.units
1617
import matplotlib.testing
17-
from matplotlib import (_api, _pylab_helpers, cbook, ft2font, pyplot as plt,
18+
from matplotlib import (_api, _get_executable_info, _pylab_helpers, cbook,
19+
ExecutableNotFoundError, ft2font, pyplot as plt,
1820
ticker)
1921
from .compare import comparable_formats, compare_images, make_test_filename
2022
from .exceptions import ImageComparisonFailure
2123

24+
_log = logging.getLogger(__name__)
2225

2326
@contextlib.contextmanager
2427
def _cleanup_cm():
@@ -518,3 +521,41 @@ def _image_directories(func):
518521
result_dir = Path().resolve() / "result_images" / module_path.stem
519522
result_dir.mkdir(parents=True, exist_ok=True)
520523
return baseline_dir, result_dir
524+
525+
526+
def _checkdep_usetex():
527+
if not shutil.which("tex"):
528+
_log.warning("usetex mode requires TeX.")
529+
return False
530+
try:
531+
_get_executable_info("dvipng")
532+
except ExecutableNotFoundError:
533+
_log.warning("usetex mode requires dvipng.")
534+
return False
535+
try:
536+
_get_executable_info("gs")
537+
except ExecutableNotFoundError:
538+
_log.warning("usetex mode requires ghostscript.")
539+
return False
540+
return True
541+
542+
543+
try:
544+
import pytest
545+
needs_ghostscript = pytest.mark.skipif(
546+
"eps" not in matplotlib.testing.compare.converter,
547+
reason="This test needs a ghostscript installation")
548+
needs_lualatex = pytest.mark.skipif(
549+
not matplotlib.testing._check_for_pgf('lualatex'),
550+
reason='lualatex + pgf is required')
551+
needs_pdflatex = pytest.mark.skipif(
552+
not matplotlib.testing._check_for_pgf('pdflatex'),
553+
reason='pdflatex + pgf is required')
554+
needs_usetex = pytest.mark.skipif(
555+
not _checkdep_usetex(),
556+
reason="This test needs a TeX installation")
557+
needs_xelatex = pytest.mark.skipif(
558+
not matplotlib.testing._check_for_pgf('xelatex'),
559+
reason='xelatex + pgf is required')
560+
except ModuleNotFoundError:
561+
pass

‎lib/matplotlib/tests/test_backend_bases.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import re
22

33
from matplotlib import path, transforms
4-
from matplotlib.testing import _check_for_pgf
54
from matplotlib.backend_bases import (
65
FigureCanvasBase, LocationEvent, MouseButton, MouseEvent,
76
NavigationToolbar2, RendererBase)
87
from matplotlib.figure import Figure
8+
from matplotlib.testing.decorators import needs_xelatex
99
import matplotlib.pyplot as plt
1010

1111
import numpy as np
1212
import pytest
1313

14-
needs_xelatex = pytest.mark.skipif(not _check_for_pgf('xelatex'),
15-
reason='xelatex + pgf is required')
16-
1714

1815
def test_uses_per_path():
1916
id = transforms.Affine2D()

‎lib/matplotlib/tests/test_backend_pdf.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,15 @@
99
import pytest
1010

1111
import matplotlib as mpl
12-
from matplotlib import pyplot as plt, checkdep_usetex, rcParams
12+
from matplotlib import pyplot as plt, rcParams
1313
from matplotlib.cbook import _get_data_path
1414
from matplotlib.ft2font import FT2Font
1515
from matplotlib.font_manager import findfont, FontProperties
1616
from matplotlib.backends._backend_pdf_ps import get_glyphs_subset
1717
from matplotlib.backends.backend_pdf import PdfPages
1818
from matplotlib.patches import Rectangle
19-
from matplotlib.testing.decorators import check_figures_equal, image_comparison
20-
21-
22-
needs_usetex = pytest.mark.skipif(
23-
not checkdep_usetex(True),
24-
reason="This test needs a TeX installation")
19+
from matplotlib.testing.decorators import (
20+
check_figures_equal, image_comparison, needs_usetex)
2521

2622

2723
@image_comparison(['pdf_use14corefonts.pdf'])

‎lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,12 @@
1212
from matplotlib.testing import _has_tex_package, _check_for_pgf
1313
from matplotlib.testing.compare import compare_images, ImageComparisonFailure
1414
from matplotlib.backends.backend_pgf import PdfPages, _tex_escape
15-
from matplotlib.testing.decorators import (_image_directories,
16-
check_figures_equal,
17-
image_comparison)
15+
from matplotlib.testing.decorators import (
16+
_image_directories, check_figures_equal, image_comparison,
17+
needs_ghostscript, needs_lualatex, needs_pdflatex, needs_xelatex)
1818

1919
baseline_dir, result_dir = _image_directories(lambda: 'dummy func')
2020

21-
needs_xelatex = pytest.mark.skipif(not _check_for_pgf('xelatex'),
22-
reason='xelatex + pgf is required')
23-
needs_pdflatex = pytest.mark.skipif(not _check_for_pgf('pdflatex'),
24-
reason='pdflatex + pgf is required')
25-
needs_lualatex = pytest.mark.skipif(not _check_for_pgf('lualatex'),
26-
reason='lualatex + pgf is required')
27-
needs_ghostscript = pytest.mark.skipif(
28-
"eps" not in mpl.testing.compare.converter,
29-
reason="This test needs a ghostscript installation")
30-
3121

3222
def compare_figure(fname, savefig_kwargs={}, tol=0):
3323
actual = os.path.join(result_dir, fname)

‎lib/matplotlib/tests/test_backend_ps.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@
1010
from matplotlib._api import MatplotlibDeprecationWarning
1111
from matplotlib.figure import Figure
1212
from matplotlib.patches import Ellipse
13-
from matplotlib.testing.decorators import check_figures_equal, image_comparison
13+
from matplotlib.testing.decorators import (
14+
check_figures_equal, image_comparison, needs_ghostscript, needs_usetex)
1415
import matplotlib as mpl
1516
import matplotlib.pyplot as plt
1617

17-
needs_ghostscript = pytest.mark.skipif(
18-
"eps" not in mpl.testing.compare.converter,
19-
reason="This test needs a ghostscript installation")
20-
needs_usetex = pytest.mark.skipif(
21-
not mpl.checkdep_usetex(True),
22-
reason="This test needs a TeX installation")
23-
2418

2519
# This tests tends to hit a TeX cache lock on AppVeyor.
2620
@pytest.mark.flaky(reruns=3)

‎lib/matplotlib/tests/test_backend_svg.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@
44
import xml.parsers.expat
55

66
import numpy as np
7-
import pytest
87

98
import matplotlib as mpl
109
from matplotlib.figure import Figure
1110
from matplotlib.text import Text
1211
import matplotlib.pyplot as plt
13-
from matplotlib.testing.decorators import image_comparison, check_figures_equal
14-
15-
16-
needs_usetex = pytest.mark.skipif(
17-
not mpl.checkdep_usetex(True),
18-
reason="This test needs a TeX installation")
12+
from matplotlib.testing.decorators import (
13+
check_figures_equal, image_comparison, needs_usetex)
1914

2015

2116
def test_visibility():

‎lib/matplotlib/tests/test_determinism.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,7 @@
1111
import matplotlib as mpl
1212
import matplotlib.testing.compare
1313
from matplotlib import pyplot as plt
14-
15-
16-
needs_ghostscript = pytest.mark.skipif(
17-
"eps" not in mpl.testing.compare.converter,
18-
reason="This test needs a ghostscript installation")
19-
needs_usetex = pytest.mark.skipif(
20-
not mpl.checkdep_usetex(True),
21-
reason="This test needs a TeX installation")
14+
from matplotlib.testing.decorators import needs_ghostscript, needs_usetex
2215

2316

2417
def _save_figure(objects='mhi', fmt="pdf", usetex=False):

‎lib/matplotlib/tests/test_legend.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy as np
66
import pytest
77

8-
from matplotlib.testing.decorators import image_comparison
8+
from matplotlib.testing.decorators import image_comparison, needs_usetex
99
import matplotlib.pyplot as plt
1010
import matplotlib as mpl
1111
import matplotlib.transforms as mtransforms
@@ -764,9 +764,7 @@ def test_alpha_handles():
764764
assert lh.get_edgecolor()[:-1] == hh[1].get_edgecolor()[:-1]
765765

766766

767-
@pytest.mark.skipif(
768-
not mpl.checkdep_usetex(True),
769-
reason="This test needs a TeX installation")
767+
@needs_usetex
770768
def test_usetex_no_warn(caplog):
771769
mpl.rcParams['font.family'] = 'serif'
772770
mpl.rcParams['font.serif'] = 'Computer Modern'

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /