Skip to content

Commit

Permalink
Found bug in get_glyphsets_fulfilled(), added test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanone committed Feb 15, 2024
1 parent 1c29c28 commit 7baeb9d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
9 changes: 6 additions & 3 deletions Lib/glyphsets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,10 @@ def get_glyphsets_fulfilled(ttFont):
res[glyphset]["has"].append(unicode)
else:
res[glyphset]["missing"].append(unicode)
res[glyphset]["percentage"] = len(res[glyphset]["has"]) / len(
unicodes_in_glyphset
)
if unicodes_in_glyphset:
res[glyphset]["percentage"] = len(res[glyphset]["has"]) / len(
unicodes_in_glyphset
)
else:
res[glyphset]["percentage"] = 0
return res
18 changes: 17 additions & 1 deletion tests/test_glyphsets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
from glyphsets import unicodes_per_glyphset, languages_per_glyphset, defined_glyphsets
import os
from glyphsets import (
unicodes_per_glyphset,
languages_per_glyphset,
defined_glyphsets,
get_glyphsets_fulfilled,
)
from glyphsets.definitions import glyphset_definitions

DATA_FP = os.path.join(os.path.dirname(__file__), "data")
FONT_PATH = os.path.join(DATA_FP, "MavenPro[wght].ttf")


def test_definitions():
assert len(unicodes_per_glyphset("GF_Latin_Core")) == 319
Expand All @@ -16,3 +25,10 @@ def test_definitions():
assert len(glyphset_definitions.keys()) == len(set(glyphset_definitions.keys()))

assert "GF_Latin_Core" in defined_glyphsets()


def test_coverage():
from fontTools.ttLib import TTFont

ttFont = TTFont(FONT_PATH)
assert get_glyphsets_fulfilled(ttFont)["GF_Latin_Core"]["percentage"] > 0.99

0 comments on commit 7baeb9d

Please sign in to comment.