Fix unit tests (no code changes, no re-release)

This commit is contained in:
Benjamin Berman 2025-10-29 05:26:10 -07:00
parent 05dd159136
commit 2d2d625ed0
2 changed files with 12 additions and 19 deletions

View File

@ -105,16 +105,8 @@ def test_load_font_with_upath(pkg_fs):
# UPath will use the registered fsspec filesystem for "pkg"
font_path = UPath("pkg://comfy.fonts/Tiny5-Regular.ttf")
# Try to load the font by passing the UPath object directly.
# This is not expected to work for non-local paths unless the consuming
# library (Pillow) has specific support for fsspec/upath.
try:
font = ImageFont.truetype(font_path, 10)
except (TypeError, AttributeError):
# If passing the path directly fails, fall back to opening the file
# and passing the file-like object, which is the standard way.
with font_path.open("rb") as f:
font = ImageFont.truetype(f, 10)
with font_path.open("rb") as f:
font = ImageFont.truetype(f, 10)
assert font is not None
assert isinstance(font, ImageFont.FreeTypeFont)

View File

@ -29,18 +29,19 @@ def test_regex():
n = Regex()
# Basic match test
match, = n.execute(pattern=r"hello", string="hello world")
match, *_ = n.execute(pattern=r"hello", string="hello world")
assert match is not None
assert match.group(0) == "hello"
# Test with flags
match, = n.execute(pattern=r"HELLO", string="hello world", flags=re.IGNORECASE)
match, *_ = n.execute(pattern=r"HELLO", string="hello world", flags=re.IGNORECASE)
assert match is not None
assert match.group(0) == "hello"
# Test no match
match, = n.execute(pattern=r"python", string="hello world")
match, has_match = n.execute(pattern=r"python", string="hello world")
assert match is None
assert not has_match
def test_regex_match_group_by_index():
@ -48,7 +49,7 @@ def test_regex_match_group_by_index():
regex = Regex()
# Test basic group
match, = regex.execute(pattern=r"(hello) (world)", string="hello world")
match, *_ = regex.execute(pattern=r"(hello) (world)", string="hello world")
group, = n.execute(match=match, index=0)
assert group == "hello world"
@ -64,8 +65,8 @@ def test_regex_match_group_by_name():
regex = Regex()
# Test named group
match, = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
string="hello world")
match, *_ = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
string="hello world")
group, = n.execute(match=match, name="greeting")
assert group == "hello"
@ -83,12 +84,12 @@ def test_regex_match_expand():
regex = Regex()
# Test basic expansion
match, = regex.execute(pattern=r"(hello) (world)", string="hello world")
match, *_ = regex.execute(pattern=r"(hello) (world)", string="hello world")
result, = n.execute(match=match, template=r"\2, \1!")
assert result == "world, hello!"
# Test named group expansion
match, = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
string="hello world")
match, *_ = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
string="hello world")
result, = n.execute(match=match, template=r"\g<subject>, \g<greeting>!")
assert result == "world, hello!"