Skip to content

Commit 8b65d1e

Browse files
debug: temporary CI diagnostics (revert after)
Co-authored-by: arena-agent <297053741+arena-agent@users.noreply.github.com>
1 parent 051dc80 commit 8b65d1e

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎diag_test.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys, time, traceback
2+
print("PYTHON:", sys.version, flush=True)
3+
import codesafe
4+
print("codesafe imported:", codesafe.__version__, flush=True)
5+
from codesafe import safe_eval, UnsafeExpressionError, EvaluationTimeoutError
6+
7+
checks = []
8+
def chk(name, fn):
9+
t0 = time.perf_counter()
10+
try:
11+
fn()
12+
checks.append((name, "PASS", (time.perf_counter()-t0)*1000))
13+
except Exception as e:
14+
checks.append((name, f"FAIL {type(e).__name__}: {str(e)[:120]}", (time.perf_counter()-t0)*1000))
15+
16+
chk("basic", lambda: safe_eval("1+1"))
17+
chk("attr", lambda: safe_eval("'hi'.upper()", allow_attributes=True))
18+
chk("container", lambda: safe_eval("[1,2]", allow_objects=True))
19+
chk("float", lambda: safe_eval("1.5"))
20+
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"))
23+
for name, status, ms in checks:
24+
print(f"{status:8} {ms:8.1f}ms {name}", flush=True)
25+
sys.exit(0 if all(s == "PASS" for _, s, _ in checks) else 1)

0 commit comments

Comments
 (0)