def test_non_numeric_value(self): with pytest.raises(TypeError): te.eval('a+5', a='not a float')
def test_with_vars_missing_var(self): with pytest.raises(ValueError, match='position 16'): te.eval('(5 + x1) / 3 + f', x1=4)
def test_bad_characters_in_varnames(self, vname, exception): expr = u'{}+4'.format(vname) with pytest.raises(exception): te.eval(expr, **{vname: 4.5})
def test_bad_characters(self, expr, exception): with pytest.raises(exception): te.eval(expr)
def test_various_inputs(self, expr, variables, result): assert te.eval(expr, **variables) == approx(result)
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)'))
def test_parse_error(self): with pytest.raises(ValueError, match='position 4'): te.eval('(5+5')
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
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)
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)