mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-11 23:00:51 +08:00
Fix unit tests (no code changes, no re-release)
This commit is contained in:
parent
05dd159136
commit
2d2d625ed0
@ -105,16 +105,8 @@ def test_load_font_with_upath(pkg_fs):
|
|||||||
# UPath will use the registered fsspec filesystem for "pkg"
|
# UPath will use the registered fsspec filesystem for "pkg"
|
||||||
font_path = UPath("pkg://comfy.fonts/Tiny5-Regular.ttf")
|
font_path = UPath("pkg://comfy.fonts/Tiny5-Regular.ttf")
|
||||||
|
|
||||||
# Try to load the font by passing the UPath object directly.
|
with font_path.open("rb") as f:
|
||||||
# This is not expected to work for non-local paths unless the consuming
|
font = ImageFont.truetype(f, 10)
|
||||||
# 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)
|
|
||||||
|
|
||||||
assert font is not None
|
assert font is not None
|
||||||
assert isinstance(font, ImageFont.FreeTypeFont)
|
assert isinstance(font, ImageFont.FreeTypeFont)
|
||||||
|
|||||||
@ -29,18 +29,19 @@ def test_regex():
|
|||||||
n = Regex()
|
n = Regex()
|
||||||
|
|
||||||
# Basic match test
|
# 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 is not None
|
||||||
assert match.group(0) == "hello"
|
assert match.group(0) == "hello"
|
||||||
|
|
||||||
# Test with flags
|
# 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 is not None
|
||||||
assert match.group(0) == "hello"
|
assert match.group(0) == "hello"
|
||||||
|
|
||||||
# Test no match
|
# 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 match is None
|
||||||
|
assert not has_match
|
||||||
|
|
||||||
|
|
||||||
def test_regex_match_group_by_index():
|
def test_regex_match_group_by_index():
|
||||||
@ -48,7 +49,7 @@ def test_regex_match_group_by_index():
|
|||||||
regex = Regex()
|
regex = Regex()
|
||||||
|
|
||||||
# Test basic group
|
# 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)
|
group, = n.execute(match=match, index=0)
|
||||||
assert group == "hello world"
|
assert group == "hello world"
|
||||||
|
|
||||||
@ -64,8 +65,8 @@ def test_regex_match_group_by_name():
|
|||||||
regex = Regex()
|
regex = Regex()
|
||||||
|
|
||||||
# Test named group
|
# Test named group
|
||||||
match, = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
|
match, *_ = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
|
||||||
string="hello world")
|
string="hello world")
|
||||||
|
|
||||||
group, = n.execute(match=match, name="greeting")
|
group, = n.execute(match=match, name="greeting")
|
||||||
assert group == "hello"
|
assert group == "hello"
|
||||||
@ -83,12 +84,12 @@ def test_regex_match_expand():
|
|||||||
regex = Regex()
|
regex = Regex()
|
||||||
|
|
||||||
# Test basic expansion
|
# 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!")
|
result, = n.execute(match=match, template=r"\2, \1!")
|
||||||
assert result == "world, hello!"
|
assert result == "world, hello!"
|
||||||
|
|
||||||
# Test named group expansion
|
# Test named group expansion
|
||||||
match, = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
|
match, *_ = regex.execute(pattern=r"(?P<greeting>hello) (?P<subject>world)",
|
||||||
string="hello world")
|
string="hello world")
|
||||||
result, = n.execute(match=match, template=r"\g<subject>, \g<greeting>!")
|
result, = n.execute(match=match, template=r"\g<subject>, \g<greeting>!")
|
||||||
assert result == "world, hello!"
|
assert result == "world, hello!"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user