Fix tests to work with the new directory structure

This commit is contained in:
nyshadhr9 2026-09-17 18:58:14 +00:00
parent 1ffdd21391
commit baf3d1ab25
2 changed files with 60 additions and 55 deletions

View file

@ -13,8 +13,12 @@ def name(font, name_id):
def main(): def main():
font_files = sorted(p for p in (Path(__file__).parent / "fonts").iterdir() if p.suffix == ".ttf") font_files = []
max_name_len = max(len(p.name) for p in font_files) for sub_dir in [Path(__file__).parent / "2D" / "fonts", Path(__file__).parent / "3D" / "fonts"]:
if sub_dir.is_dir():
font_files.extend(sub_dir.rglob("*.ttf"))
font_files.sort(key=lambda p: p.name)
max_name_len = max(len(p.name) for p in font_files) if font_files else 0
for font_file in font_files: for font_file in font_files:
font = ttLib.TTFont(font_file) font = ttLib.TTFont(font_file)

View file

@ -11,53 +11,51 @@ NAME_ID_POSTSCRIPT_NAME = 6
def test_consistent_version(): def test_consistent_version():
fonts_dir = Path("fonts") for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
assert fonts_dir.is_dir() assert sub_dir.is_dir()
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$") name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$")
debug_versions = [] debug_versions = []
versions = set() versions = set()
for font_file in fonts_dir.rglob("*.ttf"): for font_file in sub_dir.rglob("*.ttf"):
font = ttLib.TTFont(font_file) font = ttLib.TTFont(font_file)
head_ver = f"{font['head'].fontRevision:.03f}" head_ver = f"{font['head'].fontRevision:.03f}"
versions.add(head_ver) versions.add(head_ver)
debug_versions.append(f"{font_file.name} head {head_ver}") debug_versions.append(f"{font_file.name} head {head_ver}")
for name in font["name"].names: for name in font["name"].names:
# name 5 is version # name 5 is version
if name.nameID != 5: if name.nameID != 5:
continue continue
if not name.isUnicode(): if not name.isUnicode():
continue continue
match = name5_re.match(name.toUnicode()) match = name5_re.match(name.toUnicode())
assert match is not None, f"{name.toUnicode()} is malformed" assert match is not None, f"{name.toUnicode()} is malformed in {font_file.name}"
versions.add(match.group(1)) versions.add(match.group(1))
debug_versions.append(f"{font_file.name} name {match.group(1)}") debug_versions.append(f"{font_file.name} name {match.group(1)}")
debug_versions = "\n".join(debug_versions) debug_versions_str = "\n".join(debug_versions)
assert ( assert (
len(versions) == 1 len(versions) == 1
), f"Should have a consistent version, found\n{debug_versions}" ), f"Should have a consistent version under {sub_dir}, found\n{debug_versions_str}"
def test_consistent_fstype(): def test_consistent_fstype():
fonts_dir = Path("fonts") for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
assert fonts_dir.is_dir() assert sub_dir.is_dir()
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$") debug_fstypes = []
fstypes = set()
debug_fstypes = [] for font_file in sub_dir.rglob("*.ttf"):
fstypes = set() font = ttLib.TTFont(font_file)
for font_file in fonts_dir.rglob("*.ttf"): fstype = font["OS/2"].fsType
font = ttLib.TTFont(font_file) fstypes.add(fstype)
fstype = font["OS/2"].fsType debug_fstypes.append(f"{font_file.name} fsType {fstype}")
fstypes.add(fstype) debug_fstypes_str = "\n".join(debug_fstypes)
debug_fstypes.append(f"{font_file.name} fsType {fstype}") assert fstypes == {0}, f"All fsType's should be 0 under {sub_dir}, found\n{debug_fstypes_str}"
debug_fstypes = "\n".join(debug_fstypes)
assert fstypes == {0}, f"All fsType's should be 0, found\n{debug_fstypes}"
def test_has_emojicompat(): def test_has_emojicompat():
fonts_dir = Path("fonts") fonts_dir = Path("2D/fonts")
assert fonts_dir.is_dir() assert fonts_dir.is_dir()
ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf")) ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf"))
@ -84,18 +82,21 @@ def name(font, name_id):
def test_flagsonly_name(): def test_flagsonly_name():
fonts_dir = Path("fonts") found = False
assert fonts_dir.is_dir() for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
font_file = fonts_dir / "NotoColorEmoji-flagsonly.ttf" assert sub_dir.is_dir()
font = ttLib.TTFont(font_file) for font_file in sub_dir.rglob("*flagsonly.ttf"):
assert [ found = True
"Noto Color Emoji Flags", font = ttLib.TTFont(font_file)
"Noto Color Emoji Flags", assert [
"Noto Color Emoji Flags", "Noto Color Emoji Flags",
"NotoColorEmojiFlags", "Noto Color Emoji Flags",
] == [ "Noto Color Emoji Flags",
name(font, NAME_ID_FAMILY), "NotoColorEmojiFlags",
name(font, NAME_ID_FULLNAME), ] == [
name(font, NAME_ID_UNIQUE_ID), name(font, NAME_ID_FAMILY),
name(font, NAME_ID_POSTSCRIPT_NAME), name(font, NAME_ID_FULLNAME),
] name(font, NAME_ID_UNIQUE_ID),
name(font, NAME_ID_POSTSCRIPT_NAME),
]
assert found, "Should find at least one flagsonly font to test"