| """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" | |