Example #1
0
 def test_non_numeric_value(self):
     with pytest.raises(TypeError):
         te.eval('a+5', a='not a float')
Example #2
0
 def test_with_vars_missing_var(self):
     with pytest.raises(ValueError, match='position 16'):
         te.eval('(5 + x1) / 3 + f', x1=4)
Example #3
0
 def test_bad_characters_in_varnames(self, vname, exception):
     expr = u'{}+4'.format(vname)
     with pytest.raises(exception):
         te.eval(expr, **{vname: 4.5})
Example #4
0
 def test_bad_characters(self, expr, exception):
     with pytest.raises(exception):
         te.eval(expr)
Example #5
0
 def test_various_inputs(self, expr, variables, result):
     assert te.eval(expr, **variables) == approx(result)
Example #6
0
 def test_non_numbers(self):
     assert te.eval('1/0') == float('inf')
     assert math.isnan(te.eval('0/0'))
     assert math.isnan(te.eval('sqrt(-1)'))
Example #7
0
 def test_parse_error(self):
     with pytest.raises(ValueError, match='position 4'):
         te.eval('(5+5')
Example #8
0
 def test_input_types(self):
     assert te.eval(u'1+1') == 2
     assert te.eval('1+1') == 2
     assert te.eval(te.Expression('3+6')) == 9
Example #9
0
    def test_eval_missing_var(self, expression):
        expr = te.Expression(expression, varnames='beta a')

        with pytest.raises(TypeError, match='"beta"'):
            te.eval(expr, a=4)
Example #10
0
    def test_eval_with_kwargs(self, expression):
        expr = te.Expression(expression, varnames='beta a')

        assert te.eval(expr, a=4, beta=9) == approx(.8888888)
        assert te.eval(expr, a=9, beta=-1) == approx(-13.92839)