Skip to content

Commit 0e5802d

Browse files
debug: fix diagnostic expectations
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
1 parent a233004 commit 0e5802d

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

‎diag_test.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
print("codesafe imported:", codesafe.__version__, flush=True)
55
from codesafe import safe_eval, UnsafeExpressionError, EvaluationTimeoutError
66

7+
def _spin():
8+
while True:
9+
pass
10+
711
checks = []
812
def chk(name, fn):
913
t0 = time.perf_counter()
@@ -18,8 +22,15 @@ def chk(name, fn):
1822
chk("container", lambda: safe_eval("[1,2]", allow_objects=True))
1923
chk("float", lambda: safe_eval("1.5"))
2024
chk("bytes", lambda: safe_eval("b'x'"))
21-
chk("timeout", lambda: safe_eval("f()", allowed_vars={"f": lambda: [x for x in iter(int,1)]}, allowed_function_calls=["f"], timeout=0.3))
22-
chk("lambda-reject", lambda: safe_eval("lambda: 1"))
25+
def _expect(exc, fn):
26+
try:
27+
fn()
28+
except exc:
29+
return
30+
raise AssertionError(f"expected {exc.__name__}")
31+
32+
chk("timeout", lambda: _expect(EvaluationTimeoutError, lambda: safe_eval("f()", allowed_vars={"f": _spin}, allowed_function_calls=["f"], timeout=0.3)))
33+
chk("lambda-reject", lambda: _expect(RuntimeError, lambda: safe_eval("lambda: 1")))
2334
for name, status, ms in checks:
2435
print(f"{status:8} {ms:8.1f}ms {name}", flush=True)
2536
sys.exit(0 if all(s == "PASS" for _, s, _ in checks) else 1)

0 commit comments

Comments
 (0)