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():
font_files = sorted(p for p in (Path(__file__).parent / "fonts").iterdir() if p.suffix == ".ttf")
max_name_len = max(len(p.name) for p in font_files)
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:
font = ttLib.TTFont(font_file)

View file

@ -11,14 +11,14 @@ NAME_ID_POSTSCRIPT_NAME = 6
def test_consistent_version():
fonts_dir = Path("fonts")
assert fonts_dir.is_dir()
for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
assert sub_dir.is_dir()
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$")
debug_versions = []
versions = set()
for font_file in fonts_dir.rglob("*.ttf"):
for font_file in sub_dir.rglob("*.ttf"):
font = ttLib.TTFont(font_file)
head_ver = f"{font['head'].fontRevision:.03f}"
versions.add(head_ver)
@ -30,34 +30,32 @@ def test_consistent_version():
if not name.isUnicode():
continue
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))
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 (
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():
fonts_dir = Path("fonts")
assert fonts_dir.is_dir()
name5_re = re.compile(r"^Version (\d+.\d+);GOOG;noto-emoji:\d+:[a-z0-9]+$")
for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
assert sub_dir.is_dir()
debug_fstypes = []
fstypes = set()
for font_file in fonts_dir.rglob("*.ttf"):
for font_file in sub_dir.rglob("*.ttf"):
font = ttLib.TTFont(font_file)
fstype = font["OS/2"].fsType
fstypes.add(fstype)
debug_fstypes.append(f"{font_file.name} fsType {fstype}")
debug_fstypes = "\n".join(debug_fstypes)
assert fstypes == {0}, f"All fsType's should be 0, found\n{debug_fstypes}"
debug_fstypes_str = "\n".join(debug_fstypes)
assert fstypes == {0}, f"All fsType's should be 0 under {sub_dir}, found\n{debug_fstypes_str}"
def test_has_emojicompat():
fonts_dir = Path("fonts")
fonts_dir = Path("2D/fonts")
assert fonts_dir.is_dir()
ec_fonts = set(fonts_dir.rglob("*-emojicompat.ttf"))
@ -84,9 +82,11 @@ def name(font, name_id):
def test_flagsonly_name():
fonts_dir = Path("fonts")
assert fonts_dir.is_dir()
font_file = fonts_dir / "NotoColorEmoji-flagsonly.ttf"
found = False
for sub_dir in [Path("2D/fonts"), Path("3D/fonts")]:
assert sub_dir.is_dir()
for font_file in sub_dir.rglob("*flagsonly.ttf"):
found = True
font = ttLib.TTFont(font_file)
assert [
"Noto Color Emoji Flags",
@ -99,3 +99,4 @@ def test_flagsonly_name():
name(font, NAME_ID_UNIQUE_ID),
name(font, NAME_ID_POSTSCRIPT_NAME),
]
assert found, "Should find at least one flagsonly font to test"