コード例 #1
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
    def test_attributes(self, expression):
        expr = te.Expression(expression, varnames='beta a')

        assert isinstance(expr, te.Expression)
        assert expr.varnames == ('beta', 'a')
        assert expr.body == expression
        assert str(expr) == expression
        assert repr(expr) == '<Expression: {}>'.format(expr)

        with pytest.raises(AttributeError, match='writable'):
            expr.varnames = ('a', 'b')

        with pytest.raises(AttributeError, match='writable'):
            expr.body = 'x + y'
コード例 #2
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
 def test_null_byte_in_varname(self):
     with pytest.raises(ValueError, match='null byte'):
         te.Expression('1+alpha * b', 'a\x00lpha b')
コード例 #3
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
 def test_null_byte_in_body(self):
     with pytest.raises(ValueError, match='null byte'):
         te.Expression('1\x00+1')
コード例 #4
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
 def test_empty_body(self):
     with pytest.raises(ValueError, match='position 1'):
         te.Expression('')
コード例 #5
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
 def test_parse_error(self):
     with pytest.raises(ValueError, match='position 4'):
         te.Expression('(5+5')
コード例 #6
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
 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
コード例 #7
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
    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)
コード例 #8
0
ファイル: test_tinex.py プロジェクト: ariebovenberg/tinex
    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)