File size: 794 Bytes
5a983c2 | 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 | """Sandboxed executor for the code-verifying verifier (M1c)."""
from mathcompose.common.pyexec import run_python, extract_code_blocks
def test_arithmetic_and_output():
assert run_python("print(sum(range(101)))").as_feedback() == "5050"
assert run_python("print(6*7)").stdout.strip() == "42"
def test_timeout_is_caught():
r = run_python("while True: pass", timeout=1.0)
assert not r.ok and "timeout" in r.stderr
def test_error_is_caught():
r = run_python("print(1/0)")
assert not r.ok and "ZeroDivisionError" in r.as_feedback()
def test_extract_code_blocks():
text = "a\n```python\nprint(1)\n```\nb\n```\nprint(2)\n```"
blocks = extract_code_blocks(text)
assert blocks == ["print(1)", "print(2)"]
assert run_python(blocks[0]).as_feedback() == "1"
|