Exemplo n.º 1
0
    def test_functiondef_fail(self):
        dtypes = self.dtypes
        with raises(NotImplementedError):
            exprify('lambda x, y: x + y', dtypes)

        with raises(SyntaxError):
            exprify('def f(x): return x', dtypes={'x': 'int'})
Exemplo n.º 2
0
    def test_scope(self):
        dtypes = {'sin': 'int'}
        with pytest.raises(ValueError):
            exprify('sin + 1', dtypes)

        with pytest.raises(TypeError):
            sin + 1
Exemplo n.º 3
0
    def test_functiondef_fail(self):
        dtypes = self.dtypes
        with pytest.raises(NotImplementedError):
            exprify("lambda x, y: x + y", dtypes)

        with pytest.raises(SyntaxError):
            exprify("def f(x): return x", dtypes={"x": "int"})
Exemplo n.º 4
0
    def test_scope(self):
        dtypes = {'sin': 'int'}
        with raises(ValueError):
            exprify('sin + 1', dtypes)

        with raises(TypeError):
            sin + 1
Exemplo n.º 5
0
    def test_functiondef_fail(self):
        dtypes = self.dtypes
        with pytest.raises(NotImplementedError):
            exprify('lambda x, y: x + y', dtypes)

        with pytest.raises(SyntaxError):
            exprify('def f(x): return x', dtypes={'x': 'int'})
Exemplo n.º 6
0
    def test_scope(self):
        dtypes = {"sin": "int"}
        with pytest.raises(ValueError):
            exprify("sin + 1", dtypes)

        with pytest.raises(TypeError):
            sin + 1
Exemplo n.º 7
0
    def test_failing_exprify(self):
        dtypes = self.dtypes

        with pytest.raises(AssertionError):
            exprify('x < y < z', dtypes)

        with pytest.raises(NotImplementedError):
            exprify('os.listdir()', {})

        with pytest.raises(NotImplementedError):
            exprify('os.listdir()', {'os': 'int', 'os.listdir': 'real'})

        with pytest.raises(ValueError):
            exprify('__x + __y', {'__x': 'int', '__y': 'real'})

        with pytest.raises(NotImplementedError):
            exprify('y if x else y', dtypes)
Exemplo n.º 8
0
    def test_failing_exprify(self):
        dtypes = self.dtypes

        with raises(AssertionError):
            exprify('x < y < z', dtypes)

        with raises(NotImplementedError):
            exprify('os.listdir()', {})

        with raises(NotImplementedError):
            exprify('os.listdir()', {'os': 'int', 'os.listdir': 'real'})

        with raises(ValueError):
            exprify('__x + __y', {'__x': 'int', '__y': 'real'})

        with raises(NotImplementedError):
            exprify('y if x else y', dtypes)
Exemplo n.º 9
0
    def test_failing_exprify(self):
        dtypes = self.dtypes

        with pytest.raises(AssertionError):
            exprify("x < y < z", dtypes)

        with pytest.raises(NotImplementedError):
            exprify("os.listdir()", {})

        with pytest.raises(NotImplementedError):
            exprify("os.listdir()", {"os": "int", "os.listdir": "real"})

        with pytest.raises(ValueError):
            exprify("__x + __y", {"__x": "int", "__y": "real"})

        with pytest.raises(NotImplementedError):
            exprify("y if x else y", dtypes)
Exemplo n.º 10
0
    def test_boolop_fails(self):
        dtypes = self.dtypes

        with raises(NotImplementedError):
            exprify('x or y', dtypes)

        with raises(NotImplementedError):
            exprify('x and y', dtypes)

        with raises(NotImplementedError):
            exprify('not x', dtypes)
Exemplo n.º 11
0
    def test_boolop_fails(self):
        dtypes = self.dtypes

        with pytest.raises(NotImplementedError):
            exprify('x or y', dtypes)

        with pytest.raises(NotImplementedError):
            exprify('x and y', dtypes)

        with pytest.raises(NotImplementedError):
            exprify('not x', dtypes)
Exemplo n.º 12
0
    def test_boolop_fails(self):
        dtypes = self.dtypes

        with pytest.raises(NotImplementedError):
            exprify("x or y", dtypes)

        with pytest.raises(NotImplementedError):
            exprify("x and y", dtypes)

        with pytest.raises(NotImplementedError):
            exprify("not x", dtypes)
Exemplo n.º 13
0
    def test_comprehensions_fail(self):
        dtypes = self.dtypes

        if sys.version_info < (2, 7):
            # dict and set comprehensions are not implemented in Python < 2.7
            error = SyntaxError
        else:
            # and we don't allow them in versions that do
            error = NotImplementedError

        with raises(error):
            exprify('{x: y for z in y}', dtypes)

        with raises(error):
            exprify('{x for z in y}', dtypes)

        with raises(NotImplementedError):
            exprify('[x for z in y]', dtypes)

        with raises(NotImplementedError):
            exprify('(x for y in z)', dtypes)
Exemplo n.º 14
0
    def test_comprehensions_fail(self):
        dtypes = self.dtypes

        if sys.version_info < (2, 7):
            # dict and set comprehensions are not implemented in Python < 2.7
            error = SyntaxError
        else:
            # and we don't allow them in versions that do
            error = NotImplementedError

        with pytest.raises(error):
            exprify('{x: y for z in y}', dtypes)

        with pytest.raises(error):
            exprify('{x for z in y}', dtypes)

        with pytest.raises(NotImplementedError):
            exprify('[x for z in y]', dtypes)

        with pytest.raises(NotImplementedError):
            exprify('(x for y in z)', dtypes)
Exemplo n.º 15
0
 def test_simple_boolean_not(self):
     other = ~self.x
     assert exprify('~x', {'x': 'bool'}).isidentical(other)
Exemplo n.º 16
0
 def test_simple_boolean_not(self):
     other = ~self.x
     assert exprify('~x', {'x': 'bool'}).isidentical(other)
Exemplo n.º 17
0
 def test_comparison(self):
     other = (self.x == 1) | (self.x == 2)
     assert exprify('(x == 1) | (x == 2)', self.dtypes).isidentical(other)
Exemplo n.º 18
0
    def test_basic_arithmetic(self):
        assert exprify('x + y', self.dtypes).isidentical(self.x + self.y)

        expected = isnan(sin(x) + y)
        result = exprify('isnan(sin(x) + y)', self.dtypes)
        assert str(expected) == str(result)

        # parsed as a Num in Python 2 and a UnaryOp in Python 3
        assert exprify('-1', {}) == -1

        # parsed as UnaryOp(op=USub(), operand=1)
        assert exprify('-x', self.dtypes).isidentical(-self.x)

        assert exprify('-x + y', self.dtypes).isidentical(-self.x + self.y)

        other = self.x * self.y + self.z
        assert exprify('x * y + z', self.dtypes).isidentical(other)
        assert exprify('x ** y', self.dtypes).isidentical(self.x ** self.y)

        other = self.x / self.y / self.z + 1
        assert exprify('x / y / z + 1', self.dtypes).isidentical(other)

        other = self.x / self.y % self.z + 2 ** self.y
        assert exprify('x / y % z + 2 ** y', self.dtypes).isidentical(other)

        assert exprify('x // y', self.dtypes).isidentical(self.x // self.y)
        assert exprify('1 // y // x', self.dtypes).isidentical(
            1 // self.y // self.x)
Exemplo n.º 19
0
 def test_literal_int_compare(self):
     other = self.x == 1
     result = exprify('x == 1', self.dtypes)
     assert isinstance(result.rhs, int)
     assert result.isidentical(other)
Exemplo n.º 20
0
 def test_literal_float_compare(self):
     other = self.y == 1.0
     result = exprify('y == 1.0', self.dtypes)
     assert isinstance(result.rhs, float)
     assert result.isidentical(other)
Exemplo n.º 21
0
 def test_simple_boolean_not(self):
     x = symbol('x', 'bool')
     assert exprify('~x', {'x': 'bool'}).isidentical(~x)
Exemplo n.º 22
0
 def test_literal_string_compare(self):
     other = self.name == "Alice"
     result = exprify('name == "Alice"', {'name': 'string'})
     assert isinstance(result.rhs, basestring)
     assert result.isidentical(other)
Exemplo n.º 23
0
    def test_basic_arithmetic(self):
        assert exprify('x + y', self.dtypes).isidentical(self.x + self.y)

        expected = isnan(sin(x) + y)
        result = exprify('isnan(sin(x) + y)', self.dtypes)
        assert str(expected) == str(result)

        # parsed as a Num in Python 2 and a UnaryOp in Python 3
        assert exprify('-1', {}) == -1

        # parsed as UnaryOp(op=USub(), operand=1)
        assert exprify('-x', self.dtypes).isidentical(-self.x)

        assert exprify('-x + y', self.dtypes).isidentical(-self.x + self.y)

        other = self.x * self.y + self.z
        assert exprify('x * y + z', self.dtypes).isidentical(other)
        assert exprify('x ** y', self.dtypes).isidentical(self.x ** self.y)

        other = self.x / self.y / self.z + 1
        assert exprify('x / y / z + 1', self.dtypes).isidentical(other)

        other = self.x / self.y % self.z + 2 ** self.y
        assert exprify('x / y % z + 2 ** y', self.dtypes).isidentical(other)

        assert exprify('x // y', self.dtypes).isidentical(self.x // self.y)
        assert exprify('1 // y // x', self.dtypes).isidentical(
            1 // self.y // self.x)
Exemplo n.º 24
0
 def test_comparison(self):
     other = (self.x == 1) | (self.x == 2)
     assert exprify('(x == 1) | (x == 2)', self.dtypes).isidentical(other)
Exemplo n.º 25
0
 def test_simple_boolean_not(self):
     x = symbol('x', 'bool')
     assert exprify('~x', {'x': 'bool'}).isidentical(~x)
Exemplo n.º 26
0
 def test_literal_string_compare(self):
     other = self.name == "Alice"
     result = exprify('name == "Alice"', {'name': 'string'})
     assert isinstance(result.rhs, basestring)
     assert result.isidentical(other)
Exemplo n.º 27
0
 def test_literal_int_compare(self):
     other = self.x == 1
     result = exprify('x == 1', self.dtypes)
     assert isinstance(result.rhs, int)
     assert result.isidentical(other)
Exemplo n.º 28
0
 def test_simple_boolean_not(self):
     x = symbol("x", "bool")
     assert exprify("~x", {"x": "bool"}).isidentical(~x)
Exemplo n.º 29
0
 def test_literal_float_compare(self):
     other = self.y == 1.0
     result = exprify('y == 1.0', self.dtypes)
     assert isinstance(result.rhs, float)
     assert result.isidentical(other)