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

Commitde67704

Browse files
committed
TST: Use placeholders for text in layout tests
1 parent662239c commitde67704

File tree

56 files changed

+3707
-6366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+3707
-6366
lines changed

‎lib/matplotlib/testing/conftest.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,3 +125,39 @@ def test_imshow_xarray(xr):
125125

126126
xr=pytest.importorskip('xarray')
127127
returnxr
128+
129+
130+
def_text_placeholders(monkeypatch):
131+
frommatplotlib.patchesimportRectangle
132+
133+
defpatched_get_text_metrics_with_cache(renderer,text,fontprop,ismath,dpi):
134+
"""
135+
Replace ``_get_text_metrics_with_cache`` with fixed results.
136+
137+
The usual ``renderer.get_text_width_height_descent`` would depend on font
138+
metrics; instead the fixed results are based on font size and the length of the
139+
string only.
140+
"""
141+
height=fontprop.get_size()
142+
width=len(text)*height/1.618# Golden ratio for character size.
143+
returnwidth,height,0
144+
145+
defpatched_text_draw(self,renderer):
146+
"""
147+
Replace ``Text.draw`` with a fixed bounding box Rectangle.
148+
149+
The bounding box corresponds to ``Text.get_window_extent``, which ultimately
150+
depends on the above patched ``_get_text_metrics_with_cache``.
151+
"""
152+
ifrendererisnotNone:
153+
self._renderer=renderer
154+
ifnotself.get_visible():
155+
return
156+
ifself.get_text()=='':
157+
return
158+
bbox=self.get_window_extent()
159+
Rectangle(bbox.p0,bbox.width,bbox.height,color='grey').draw(renderer)
160+
161+
monkeypatch.setattr('matplotlib.text._get_text_metrics_with_cache',
162+
patched_get_text_metrics_with_cache)
163+
monkeypatch.setattr('matplotlib.text.Text.draw',patched_text_draw)

‎lib/matplotlib/testing/conftest.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ def mpl_test_settings(request: pytest.FixtureRequest) -> None: ...
1010
defpd()->ModuleType: ...
1111
@pytest.fixture
1212
defxr()->ModuleType: ...
13+
def_text_placeholders(monkeypatch:pytest.MonkeyPatch)->None: ...
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp