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

Commit68fd2fe

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 parente7f01a4 commit68fd2fe

File tree

8 files changed

+51
-42
lines changed

8 files changed

+51
-42
lines changed

‎lib/matplotlib/backend_bases.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ def _draw(renderer): raise Done(renderer)
15871587
figure.canvas=orig_canvas
15881588

15891589

1590-
def_no_op_draw(figure):
1590+
def_no_output_draw(figure):
15911591
renderer=_get_renderer(figure)
15921592
withrenderer._draw_disabled():
15931593
figure.draw(renderer)
@@ -1630,7 +1630,7 @@ def _check_savefig_extra_args(func=None, extra_kwargs=()):
16301630
@functools.wraps(func)
16311631
defwrapper(*args,**kwargs):
16321632
name='savefig'# Reasonable default guess.
1633-
public_api=re.compile(r'^savefig|print_[A-Za-z0-9]+|_no_op_draw$')
1633+
public_api=re.compile(r'^savefig|print_[A-Za-z0-9]+|_no_output_draw$')
16341634
seen_print_figure=False
16351635
forframe,lineintraceback.walk_stack(None):
16361636
ifframeisNone:
@@ -1641,7 +1641,7 @@ def wrapper(*args, **kwargs):
16411641
frame.f_globals.get('__name__','')):
16421642
ifpublic_api.match(frame.f_code.co_name):
16431643
name=frame.f_code.co_name
1644-
ifnamein ('print_figure','_no_op_draw'):
1644+
ifnamein ('print_figure','_no_output_draw'):
16451645
seen_print_figure=True
16461646

16471647
else:

‎lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
frommatplotlib._pylab_helpersimportGcf
2929
frommatplotlib.backend_basesimport (
3030
_Backend,_check_savefig_extra_args,FigureCanvasBase,FigureManagerBase,
31-
GraphicsContextBase,RendererBase,_no_op_draw)
31+
GraphicsContextBase,RendererBase,_no_output_draw)
3232
frommatplotlib.backends.backend_mixedimportMixedModeRenderer
3333
frommatplotlib.figureimportFigure
3434
frommatplotlib.font_managerimportfindfont,is_opentype_cff_font,get_font
@@ -2708,7 +2708,7 @@ def print_pdf(self, filename, *,
27082708
file.close()
27092709

27102710
defdraw(self,*args,**kwargs):
2711-
_no_op_draw(self.figure)
2711+
_no_output_draw(self.figure)
27122712
returnsuper().draw(*args,**kwargs)
27132713

27142714
FigureManagerPdf=FigureManagerBase

‎lib/matplotlib/backends/backend_pgf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
frommatplotlibimportcbook,font_managerasfm
2020
frommatplotlib.backend_basesimport (
2121
_Backend,_check_savefig_extra_args,FigureCanvasBase,FigureManagerBase,
22-
GraphicsContextBase,RendererBase,_no_op_draw
22+
GraphicsContextBase,RendererBase,_no_output_draw
2323
)
2424
frommatplotlib.backends.backend_mixedimportMixedModeRenderer
2525
frommatplotlib.backends.backend_pdfimport (
@@ -972,7 +972,7 @@ def get_renderer(self):
972972
returnRendererPgf(self.figure,None)
973973

974974
defdraw(self,*args,**kwargs):
975-
_no_op_draw(self.figure)
975+
_no_output_draw(self.figure)
976976
returnsuper().draw()
977977

978978

‎lib/matplotlib/backends/backend_ps.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
frommatplotlib.afmimportAFM
2424
frommatplotlib.backend_basesimport (
2525
_Backend,_check_savefig_extra_args,FigureCanvasBase,FigureManagerBase,
26-
GraphicsContextBase,RendererBase,_no_op_draw)
26+
GraphicsContextBase,RendererBase,_no_output_draw)
2727
frommatplotlib.cbookimportis_writable_file_like,file_requires_unicode
2828
frommatplotlib.font_managerimportis_opentype_cff_font,get_font
2929
frommatplotlib.ft2fontimportLOAD_NO_HINTING
@@ -1112,7 +1112,7 @@ def write(self, *args, **kwargs):
11121112
_move_path_to_path_or_stream(tmpfile,outfile)
11131113

11141114
defdraw(self,*args,**kwargs):
1115-
_no_op_draw(self.figure)
1115+
_no_output_draw(self.figure)
11161116
returnsuper().draw()
11171117

11181118
defconvert_psfrags(tmpfile,psfrags,font_preamble,custom_preamble,

‎lib/matplotlib/backends/backend_svg.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
frommatplotlibimportcbook
1818
frommatplotlib.backend_basesimport (
1919
_Backend,_check_savefig_extra_args,FigureCanvasBase,FigureManagerBase,
20-
RendererBase,_no_op_draw)
20+
RendererBase,_no_output_draw)
2121
frommatplotlib.backends.backend_mixedimportMixedModeRenderer
2222
frommatplotlib.colorsimportrgb2hex
2323
frommatplotlib.datesimportUTC
@@ -1361,7 +1361,7 @@ def get_default_filetype(self):
13611361
return'svg'
13621362

13631363
defdraw(self,*args,**kwargs):
1364-
_no_op_draw(self.figure)
1364+
_no_output_draw(self.figure)
13651365
returnsuper().draw()
13661366

13671367
FigureManagerSVG=FigureManagerBase

‎lib/matplotlib/testing/__init__.py

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

55
importlocale
66
importlogging
7+
importsubprocess
8+
frompathlibimportPath
9+
fromtempfileimportTemporaryDirectory
10+
11+
importpytest
712

813
importmatplotlibasmpl
914
frommatplotlibimportcbook
@@ -44,3 +49,31 @@ def setup():
4449
# are not necessarily the default values as specified in rcsetup.py.
4550
set_font_settings_for_testing()
4651
set_reproducibility_for_testing()
52+
53+
54+
defcheck_for(texsystem):
55+
withTemporaryDirectory()astmpdir:
56+
tex_path=Path(tmpdir,"test.tex")
57+
tex_path.write_text(r"""
58+
\documentclass{minimal}
59+
\usepackage{pgf}
60+
\begin{document}
61+
\typeout{pgfversion=\pgfversion}
62+
\makeatletter
63+
\@@end
64+
""")
65+
try:
66+
subprocess.check_call(
67+
[texsystem,"-halt-on-error",str(tex_path)],cwd=tmpdir,
68+
stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
69+
except (OSError,subprocess.CalledProcessError):
70+
returnFalse
71+
returnTrue
72+
73+
74+
needs_xelatex=pytest.mark.skipif(notcheck_for('xelatex'),
75+
reason='xelatex + pgf is required')
76+
needs_pdflatex=pytest.mark.skipif(notcheck_for('pdflatex'),
77+
reason='pdflatex + pgf is required')
78+
needs_lualatex=pytest.mark.skipif(notcheck_for('lualatex'),
79+
reason='lualatex + pgf is required')

‎lib/matplotlib/tests/test_backend_bases.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
importre
22

3+
frommatplotlib.testingimportneeds_xelatex
4+
35
frommatplotlib.backend_basesimport (
46
FigureCanvasBase,LocationEvent,MouseButton,MouseEvent,
57
NavigationToolbar2,RendererBase)
@@ -159,7 +161,9 @@ def test_interactive_zoom():
159161
assertax.get_navigate_mode()isNone
160162

161163

162-
@pytest.mark.parametrize("backend", ['svg','pgf','ps','pdf'])
164+
@pytest.mark.parametrize(
165+
"backend", ['svg','ps','pdf',pytest.param('pgf',marks=needs_xelatex)]
166+
)
163167
deftest_draw(backend):
164168
frommatplotlib.figureimportFigure
165169
frommatplotlib.backends.backend_aggimportFigureCanvas

‎lib/matplotlib/tests/test_backend_pgf.py

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,23 @@
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+
frommatplotlib.testingimportneeds_xelatex,needs_pdflatex,needs_lualatex
1414
frommatplotlib.testing.compareimportcompare_images,ImageComparisonFailure
1515
frommatplotlib.testing.decoratorsimportimage_comparison,_image_directories
1616
frommatplotlib.backends.backend_pgfimportPdfPages,common_texification
1717

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

2020

21-
defcheck_for(texsystem):
22-
withTemporaryDirectory()astmpdir:
23-
tex_path=Path(tmpdir,"test.tex")
24-
tex_path.write_text(r"""
25-
\documentclass{minimal}
26-
\usepackage{pgf}
27-
\begin{document}
28-
\typeout{pgfversion=\pgfversion}
29-
\makeatletter
30-
\@@end
31-
""")
32-
try:
33-
subprocess.check_call(
34-
[texsystem,"-halt-on-error",str(tex_path)],cwd=tmpdir,
35-
stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
36-
except (OSError,subprocess.CalledProcessError):
37-
returnFalse
38-
returnTrue
39-
40-
41-
needs_xelatex=pytest.mark.skipif(notcheck_for('xelatex'),
42-
reason='xelatex + pgf is required')
43-
needs_pdflatex=pytest.mark.skipif(notcheck_for('pdflatex'),
44-
reason='pdflatex + pgf is required')
45-
needs_lualatex=pytest.mark.skipif(notcheck_for('lualatex'),
46-
reason='lualatex + pgf is required')
47-
48-
4921
def_has_sfmath():
5022
return (shutil.which("kpsewhich")
5123
andsubprocess.run(["kpsewhich","sfmath.sty"],

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp