Beispiel #1
0
def test_Eval__RestictionCapableEval__eval_1():
    """It does not add names from the mapping to the
    global scope which are already there."""
    ob = RestrictionCapableEval("a + b + c")
    ob.globals['c'] = 8
    result = ob.eval(dict(a=1, b=2, c=4))
    assert result == 11
def test_Eval__RestictionCapableEval__eval_1():
    """It does not add names from the mapping to the
    global scope which are already there."""
    ob = RestrictionCapableEval("a + b + c")
    ob.globals['c'] = 8
    result = ob.eval(dict(a=1, b=2, c=4))
    assert result == 11
 def checkUnrestrictedEval(self):
     expr = RestrictionCapableEval("{'a':[m.pop()]}['a'] + [m[0]]")
     v = [12, 34]
     expect = v[:]
     expect.reverse()
     res = expr.eval({'m':v})
     self.assertEqual(res, expect)
     v = [12, 34]
     res = expr(m=v)
     self.assertEqual(res, expect)
 def checkUnrestrictedEval(self):
     expr = RestrictionCapableEval("{'a':[m.pop()]}['a'] + [m[0]]")
     v = [12, 34]
     expect = v[:]
     expect.reverse()
     res = expr.eval({'m': v})
     self.assertEqual(res, expect)
     v = [12, 34]
     res = expr(m=v)
     self.assertEqual(res, expect)
Beispiel #5
0
def test_Eval__RestictionCapableEval__eval__2():
    """It allows to use list comprehensions."""
    ob = RestrictionCapableEval("[item for item in (1, 2)]")
    result = ob.eval({})
    assert result == [1, 2]
Beispiel #6
0
def test_eval():
    ob = RestrictionCapableEval(exp)
    ret = ob.eval({'m': [1, 2]})
    assert ret == [2, 1]
def test_Eval__RestictionCapableEval__eval__2():
    """It allows to use list comprehensions."""
    ob = RestrictionCapableEval("[item for item in (1, 2)]")
    result = ob.eval({})
    assert result == [1, 2]
def test_eval():
    ob = RestrictionCapableEval(exp)
    ret = ob.eval({'m': [1, 2]})
    assert ret == [2, 1]