Skip to content

Commit

Permalink
regex_match: Typecast list and dict input to string
Browse files Browse the repository at this point in the history
  • Loading branch information
refeed authored and arunim2405 committed Nov 10, 2023
1 parent c5f36ce commit baf0a73
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tirith/core/evaluators/regex_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def evaluate(self, evaluator_input, evaluator_data):
evaluation_result = {"passed": False, "message": "Not evaluated"}
try:
match = 0
if type(evaluator_input) == str and type(evaluator_data) == str:
if type(evaluator_input) in (str, list, dict) and type(evaluator_data) == str:
evaluator_input = str(evaluator_input)
match = re.match(evaluator_data, evaluator_input)
if match is None:
evaluation_result = {
Expand Down
10 changes: 10 additions & 0 deletions tests/core/evaluators/test_regex_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,13 @@ def test_regex_passing():
def test_regex_failing():
result = evaluator.evaluate(evaluator_input2, evaluator_data2)
assert result == {"passed": False, "message": f"{evaluator_input2} does not match regex pattern {evaluator_data2}"}


def test_regex_list():
result = evaluator.evaluate(evaluator_input=["something"], evaluator_data=r"\['something'\]")
assert result["passed"] is True


def test_regex_dict():
result = evaluator.evaluate(evaluator_input=dict(a=2), evaluator_data=r"{'a': 2}")
assert result["passed"] is True

0 comments on commit baf0a73

Please sign in to comment.