def test_callback(self): # modify local variable via callback self.value = 0 def test():self.value =1 env = {'test':test} safe_eval("test()", env) self.assertEqual(self.value, 1) print 8
def test_code(self): x = {'x':2} env = {'x':x} safe_eval(''' value = 1 x['x'] = value + x['x'] print str(x)+ " <- TA MERE" ''', env) self.assertEqual(x['x'], 3) print 9
def test_timeout_ok(self): # attempt to exectute 'slow' code which finishes within timelimit def test():time.sleep(2) env = {'test':test} safe_eval("test()", env, timeout_secs = 5) print 5