File size: 1,566 Bytes
ebd2f5a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | import time
from unittest.mock import patch
from math_verify.grader import verify
from math_verify.parser import parse
@patch("math_verify.parser.parse_expr")
def test_timeout_expr(mock_parse_expr):
# Mock the parsing function to simulate a delay
def delayed_parse(*args, **kwargs):
time.sleep(5) # Simulate a delay longer than the timeout
return "parsed_expr"
mock_parse_expr.side_effect = delayed_parse
# Test that the timeout is triggered
x = parse(
"1+1",
parsing_timeout=1,
extraction_mode="first_match",
fallback_mode="no_fallback",
)
assert x == []
@patch("math_verify.parser.latex2sympy")
def test_timeout_latex(mock_parse_latex):
# Mock the parsing function to simulate a delay
def delayed_parse(*args, **kwargs):
time.sleep(5) # Simulate a delay longer than the timeout
return "parsed_expr"
mock_parse_latex.side_effect = delayed_parse
# Test that the timeout is triggered
x = parse(
"$1+1$",
parsing_timeout=1,
extraction_mode="first_match",
fallback_mode="no_fallback",
)
assert x == []
@patch("math_verify.grader.sympy_expr_eq")
def test_timeout_verify(mock_verify):
# Mock the verify function to simulate a delay
def delayed_sympy_expr_eq(*args, **kwargs):
time.sleep(5) # Simulate a delay longer than the timeout
return True
mock_verify.side_effect = delayed_sympy_expr_eq
gold = [parse("1+1")[0]]
assert not verify(gold, gold, timeout_seconds=1)
|