Files
AI/참고/guardrails-main/tests/unit_tests/test_merge.py

60 lines
2.1 KiB
Python
Raw Normal View History

2026-05-12 19:40:31 +09:00
import pytest
from guardrails.validator_service import SequentialValidatorService
validator_service = SequentialValidatorService()
@pytest.mark.parametrize(
"original, new_values, expected",
[
# test behavior on blank fixes
("hello world", ["", "hello nick"], "nick"),
("hello world", ["", "hello world"], ""),
# test behavior on non overlapping replacements
(
"""John is a shitty person who works at Anthropic on Claude,
and lives in San Francisco""",
[
"""<PERSON> is a shitty person who works at Anthropic on <PERSON>,
and lives in <LOCATION>""",
"""John is a ****** person who works at Anthropic on Claude,
and lives in San Francisco""",
],
"""<PERSON> is a ****** person who works at Anthropic on <PERSON>,
and lives in <LOCATION>""",
),
# test behavior with lowercase
(
"""JOE is FUNNY and LIVES in NEW york""",
[
"""<PERSON> is FUNNY and lives in <LOCATION>""",
"""joe is funny and lives in new york""",
],
"""<PERSON> is funny and lives in <LOCATION>""",
),
(
"""JOHN lives IN SAN francisco""",
[
"""<PERSON> lives in <LOCATION>""",
"""john lives in san francisco""",
],
"""<PERSON> lives in <LOCATION>""",
),
# (broken) test behavior with a word close to PERSON - seems to work!?
(
"""Parson is FUNNY and LIVES in NEW york""",
[
"""<PERSON> is FUNNY and lives in <LOCATION>""",
"""parson is funny and lives in new york""",
],
"""<PERSON> is funny and lives in <LOCATION>""",
),
],
)
def test_merge(original, new_values, expected):
print("testing", original, new_values, expected)
res = validator_service.multi_merge(original, new_values)
print("res", res)
assert res == expected