Movatterモバイル変換


[0]ホーム

URL:


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

Commit81e3c11

Browse files
committed
MNT: hoist latex helpers from pgf tests to matplotlib.testing
Move the marks to skip if various latex installs are missing to bevisible on other modules.
1 parent48bff43 commit81e3c11

File tree

3 files changed

+51
-29
lines changed

3 files changed

+51
-29
lines changed

‎lib/matplotlib/testing/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
importlocale
66
importlogging
7+
importsubprocess
8+
frompathlibimportPath
9+
fromtempfileimportTemporaryDirectory
710

811
importmatplotlibasmpl
912
frommatplotlibimport_api
@@ -44,3 +47,31 @@ def setup():
4447
# are not necessarily the default values as specified in rcsetup.py.
4548
set_font_settings_for_testing()
4649
set_reproducibility_for_testing()
50+
51+
52+
defcheck_for_pgf(texsystem):
53+
"""
54+
Check if a given TeX system + pgf is available
55+
56+
Parameters
57+
----------
58+
texsystem : str
59+
The executable name to check
60+
"""
61+
withTemporaryDirectory()astmpdir:
62+
tex_path=Path(tmpdir,"test.tex")
63+
tex_path.write_text(r"""
64+
\documentclass{minimal}
65+
\usepackage{pgf}
66+
\begin{document}
67+
\typeout{pgfversion=\pgfversion}
68+
\makeatletter
69+
\@@end
70+
""")
71+
try:
72+
subprocess.check_call(
73+
[texsystem,"-halt-on-error",str(tex_path)],cwd=tmpdir,
74+
stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
75+
except (OSError,subprocess.CalledProcessError):
76+
returnFalse
77+
returnTrue

‎lib/matplotlib/tests/test_backend_bases.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
importre
2+
importos
3+
importnumpyasnp
4+
5+
importpytest
6+
7+
frommatplotlib.testingimportcheck_for_pgf
28

39
frommatplotlib.backend_basesimport (
410
FigureCanvasBase,LocationEvent,MouseButton,MouseEvent,
@@ -8,9 +14,10 @@
814
importmatplotlib.pyplotasplt
915
importmatplotlib.transformsastransforms
1016
importmatplotlib.pathaspath
11-
importos
12-
importnumpyasnp
13-
importpytest
17+
18+
19+
needs_xelatex=pytest.mark.skipif(notcheck_for_pgf('xelatex'),
20+
reason='xelatex + pgf is required')
1421

1522

1623
deftest_uses_per_path():
@@ -182,7 +189,10 @@ def test_toolbar_zoompan():
182189
assertax.get_navigate_mode()=="PAN"
183190

184191

185-
@pytest.mark.parametrize("backend", ['svg','pgf','ps','pdf'])
192+
193+
@pytest.mark.parametrize(
194+
"backend", ['svg','ps','pdf',pytest.param('pgf',marks=needs_xelatex)]
195+
)
186196
deftest_draw(backend):
187197
frommatplotlib.figureimportFigure
188198
frommatplotlib.backends.backend_aggimportFigureCanvas

‎lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
importdatetime
22
fromioimportBytesIO
33
importos
4-
frompathlibimportPath
54
importshutil
65
importsubprocess
7-
fromtempfileimportTemporaryDirectory
6+
87

98
importnumpyasnp
109
importpytest
1110

1211
importmatplotlibasmpl
1312
importmatplotlib.pyplotasplt
13+
14+
frommatplotlib.testingimportcheck_for_pgf
1415
frommatplotlib.testing.compareimportcompare_images,ImageComparisonFailure
1516
frommatplotlib.backends.backend_pgfimportPdfPages,common_texification
1617
frommatplotlib.testing.decoratorsimport (_image_directories,
@@ -20,31 +21,11 @@
2021
baseline_dir,result_dir=_image_directories(lambda:'dummy func')
2122

2223

23-
defcheck_for(texsystem):
24-
withTemporaryDirectory()astmpdir:
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-
returnFalse
40-
returnTrue
41-
42-
43-
needs_xelatex=pytest.mark.skipif(notcheck_for('xelatex'),
24+
needs_xelatex=pytest.mark.skipif(notcheck_for_pgf('xelatex'),
4425
reason='xelatex + pgf is required')
45-
needs_pdflatex=pytest.mark.skipif(notcheck_for('pdflatex'),
26+
needs_pdflatex=pytest.mark.skipif(notcheck_for_pgf('pdflatex'),
4627
reason='pdflatex + pgf is required')
47-
needs_lualatex=pytest.mark.skipif(notcheck_for('lualatex'),
28+
needs_lualatex=pytest.mark.skipif(notcheck_for_pgf('lualatex'),
4829
reason='lualatex + pgf is required')
4930
needs_ghostscript=pytest.mark.skipif(
5031
"eps"notinmpl.testing.compare.converter,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp