Skip to content

Commit 67fb6b9

Browse files
authored
Merge pull request #31343 from QuLogic/test-tolerance
TST: Restore some tolerances for some arch/platform-specific failures
2 parents 3a9a111 + 5e1c1ca commit 67fb6b9

File tree

15 files changed

+74
-30
lines changed

15 files changed

+74
-30
lines changed

.github/workflows/cygwin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ jobs:
182182
export PATH="/usr/local/bin:$PATH"
183183
python -m pip install --no-build-isolation 'contourpy>=1.0.1'
184184
python -m pip install --upgrade cycler fonttools \
185-
packaging pyparsing python-dateutil setuptools-scm \
185+
packaging pyparsing python-dateutil 'setuptools-scm<10' \
186186
-r requirements_test.txt sphinx ipython
187187
python -m pip install --upgrade pycairo 'cairocffi>=0.8' PyGObject &&
188188
python -c 'import gi; gi.require_version("Gtk", "3.0"); from gi.repository import Gtk' &&

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ jobs:
256256
# Preinstall build requirements to enable no-build-isolation builds.
257257
python -m pip install --upgrade $PRE \
258258
'contourpy>=1.0.1' cycler fonttools kiwisolver importlib_resources \
259-
packaging pillow 'pyparsing!=3.1.0' python-dateutil setuptools-scm \
259+
packaging pillow 'pyparsing!=3.1.0' python-dateutil 'setuptools-scm<10' \
260260
'meson-python>=0.13.1' 'pybind11>=2.13.2' \
261261
-r requirements/testing/all.txt \
262262
${{ matrix.extra-requirements }}

lib/matplotlib/_afm.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,18 @@ def get_angle(self) -> float:
478478
"""Return the fontangle as float."""
479479
return self._header['ItalicAngle']
480480

481+
def get_ascender(self) -> float:
482+
"""Return the ascent as float."""
483+
return self._header['Ascender']
484+
481485
def get_capheight(self) -> float:
482486
"""Return the cap height as float."""
483487
return self._header['CapHeight']
484488

489+
def get_descender(self) -> float:
490+
"""Return the descent as float."""
491+
return self._header['Descender']
492+
485493
def get_xheight(self) -> float:
486494
"""Return the xheight as float."""
487495
return self._header['XHeight']

lib/matplotlib/backends/_backend_pdf_ps.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,32 @@ def get_canvas_width_height(self):
348348
# docstring inherited
349349
return self.width * 72.0, self.height * 72.0
350350

351+
def _get_font_height_metrics(self, prop):
352+
"""
353+
Return the ascent, descent, and line gap for font described by *prop*.
354+
355+
TODO: This is a temporary method until we design a proper API for the backends.
356+
357+
Parameters
358+
----------
359+
prop : `.font_manager.FontProperties`
360+
The properties describing the font to measure.
361+
362+
Returns
363+
-------
364+
ascent, descent, line_gap : float or None
365+
The ascent, descent and line gap of the determined font, or None to fall
366+
back to normal measurements.
367+
"""
368+
if not mpl.rcParams[self._use_afm_rc_name]:
369+
return None, None, None
370+
font = self._get_font_afm(prop)
371+
scale = prop.get_size_in_points() / 1000
372+
a = font.get_ascender() * scale
373+
d = -font.get_descender() * scale
374+
g = (a + d) * 0.2 # Preserve previous line spacing of 1.2.
375+
return a, d, g
376+
351377
def get_text_width_height_descent(self, s, prop, ismath):
352378
# docstring inherited
353379
if ismath == "TeX":
Binary file not shown.

lib/matplotlib/tests/test_bbox_tight.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_bbox_inches_tight(text_placeholders):
4747

4848
@image_comparison(['bbox_inches_tight_suptile_legend'],
4949
savefig_kwarg={'bbox_inches': 'tight'},
50-
tol=0 if platform.machine() == 'x86_64' else 0.022)
50+
tol=0 if platform.machine() == 'x86_64' else 0.024)
5151
def test_bbox_inches_tight_suptile_legend():
5252
plt.plot(np.arange(10), label='a straight line')
5353
plt.legend(bbox_to_anchor=(0.9, 1), loc='upper left')

lib/matplotlib/tests/test_mathtext.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,11 @@ def baseline_images(request, fontset, index, text):
224224
@pytest.mark.parametrize(
225225
'fontset', ['cm', 'stix', 'stixsans', 'dejavusans', 'dejavuserif'])
226226
@pytest.mark.parametrize('baseline_images', ['mathtext'], indirect=True)
227-
@image_comparison(baseline_images=None, style='mpl20',
228-
tol=0.011 if platform.machine() in ('ppc64le', 's390x') else 0)
227+
@image_comparison(
228+
baseline_images=None, style='mpl20',
229+
tol=(0.013
230+
if platform.machine() in ('ppc64le', 's390x') or platform.system() == 'Windows'
231+
else 0))
229232
def test_mathtext_rendering(baseline_images, fontset, index, text):
230233
mpl.rcParams['mathtext.fontset'] = fontset
231234
fig = plt.figure(figsize=(5.25, 0.75))

lib/matplotlib/tests/test_patheffects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def test_SimplePatchShadow_offset():
120120
assert pe._offset == (4, 5)
121121

122122

123-
@image_comparison(['collection'], tol=0.03, style='mpl20')
123+
@image_comparison(['collection'], tol=0.032, style='mpl20')
124124
def test_collection():
125125
x, y = np.meshgrid(np.linspace(0, 10, 150), np.linspace(-5, 5, 100))
126126
data = np.sin(x) + np.cos(y)

lib/matplotlib/text.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -437,22 +437,29 @@ def _get_layout(self, renderer):
437437
dpi = self.get_figure(root=True).dpi
438438
# Determine full vertical extent of font, including ascenders and descenders:
439439
if not self.get_usetex():
440-
font = get_font(fontManager._find_fonts_by_props(self._fontproperties))
441-
possible_metrics = [
442-
('OS/2', 'sTypoLineGap', 'sTypoAscender', 'sTypoDescender'),
443-
('hhea', 'lineGap', 'ascent', 'descent')
444-
]
445-
for table_name, linegap_key, ascent_key, descent_key in possible_metrics:
446-
table = font.get_sfnt_table(table_name)
447-
if table is None:
448-
continue
449-
# Rescale to font size/DPI if the metrics were available.
450-
fontsize = self._fontproperties.get_size_in_points()
451-
units_per_em = font.get_sfnt_table('head')['unitsPerEm']
452-
line_gap = table[linegap_key] / units_per_em * fontsize * dpi / 72
453-
min_ascent = table[ascent_key] / units_per_em * fontsize * dpi / 72
454-
min_descent = -table[descent_key] / units_per_em * fontsize * dpi / 72
455-
break
440+
if hasattr(renderer, '_get_font_height_metrics'):
441+
# TODO: This is a temporary internal method call (for _backend_pdf_ps to
442+
# support AFM files) until we design a proper API for the backends.
443+
min_ascent, min_descent, line_gap = renderer._get_font_height_metrics(
444+
self._fontproperties)
445+
if min_ascent is None:
446+
font = get_font(fontManager._find_fonts_by_props(self._fontproperties))
447+
possible = [
448+
('OS/2', 'sTypoLineGap', 'sTypoAscender', 'sTypoDescender'),
449+
('hhea', 'lineGap', 'ascent', 'descent')
450+
]
451+
for table_name, linegap_key, ascent_key, descent_key in possible:
452+
table = font.get_sfnt_table(table_name)
453+
if table is None:
454+
continue
455+
# Rescale to font size/DPI if the metrics were available.
456+
fontsize = self._fontproperties.get_size_in_points()
457+
units_per_em = font.get_sfnt_table('head')['unitsPerEm']
458+
scale = 1 / units_per_em * fontsize * dpi / 72
459+
line_gap = table[linegap_key] * scale
460+
min_ascent = table[ascent_key] * scale
461+
min_descent = -table[descent_key] * scale
462+
break
456463
if None in (min_ascent, min_descent):
457464
# Fallback to font measurement.
458465
_, h, min_descent = _get_text_metrics_with_cache(

lib/mpl_toolkits/axisartist/tests/test_floating_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def test_curvelinear3():
6363
l.set_clip_path(ax1.patch)
6464

6565

66-
@image_comparison(['curvelinear4.png'], style='mpl20')
66+
@image_comparison(['curvelinear4.png'], style='mpl20', tol=0.04)
6767
def test_curvelinear4():
6868
fig = plt.figure(figsize=(5, 5))
6969

0 commit comments

Comments
 (0)