From 400fdab9652dbea0096547709a0cc5322785b578 Mon Sep 17 00:00:00 2001 From: Harry Dalton Date: Tue, 17 Sep 2024 10:39:07 +0100 Subject: [PATCH] Fix mock glyph removal now that check no longer mutates TTFont The previous approach relied on the `glyphOrder` property being populated as a side-effect of the "unreachable-glyphs" check, but this no longer happens now that the accidental mutation in the check has been removed. This commit avoids using the internal property entirely by using the `setGlyphOrder()` function, and ensuring that the font is fully loaded prior to this to avoid the glyph being referenced during a later load after it has already been removed from the order. If this causes issues again, it may be more resilient for us to use fontTools' subsetter library to implement this pytest. (PR #4835) --- tests/test_checks_universal.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_checks_universal.py b/tests/test_checks_universal.py index a66e5d7348..0e9a222173 100644 --- a/tests/test_checks_universal.py +++ b/tests/test_checks_universal.py @@ -1053,15 +1053,20 @@ def test_check_unreachable_glyphs(): assert glyph not in message ttFont = TTFont(TEST_FILE("notosansmath/NotoSansMath-Regular.ttf")) + ttFont.ensureDecompiled() # (required for mock glyph removal below) + glyph_order = ttFont.getGlyphOrder() + # upWhiteMediumTriangle is used as a component in circledTriangle, # since CFF does not have composites it became unused. # So that is a build tooling issue. message = assert_results_contain(check(ttFont), WARN, "unreachable-glyphs") assert "upWhiteMediumTriangle" in message - assert "upWhiteMediumTriangle" in ttFont.glyphOrder + assert "upWhiteMediumTriangle" in glyph_order - # Other than that problem, no other glyphs are unreachable: - ttFont.glyphOrder.remove("upWhiteMediumTriangle") + # Other than that problem, no other glyphs are unreachable; + # Remove the glyph and then try again. + glyph_order.remove("upWhiteMediumTriangle") + ttFont.setGlyphOrder(glyph_order) assert "upWhiteMediumTriangle" not in ttFont.glyphOrder assert_PASS(check(ttFont))