Exemple #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'})
Exemple #2
0
    def test_scope(self):
        dtypes = {'sin': 'int'}
        with raises(ValueError):
            exprify('sin + 1', dtypes)

        with raises(TypeError):
            sin + 1
Exemple #3
0
    def test_scope(self):
        dtypes = {'sin': 'int'}
        with raises(ValueError):
            exprify('sin + 1', dtypes)

        with raises(TypeError):
            sin + 1
Exemple #4
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'})
Exemple #5
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)
Exemple #6
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)
Exemple #7
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)
Exemple #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)
Exemple #9
0
def test_scalar_coerce():
    assert scalar_coerce('int', 1) == 1
    assert scalar_coerce('int', '1') == 1
    assert scalar_coerce('{x: int}', '1') == 1
    with raises(TypeError):
        scalar_coerce('{x: int, y: int}', '1')
    with raises(TypeError):
        scalar_coerce('3 * int', '1')

    assert scalar_coerce('date', 'Jan 1st, 2012') == date(2012, 1, 1)

    assert (scalar_coerce('datetime', 'Jan 1st, 2012 12:00:00') ==
            datetime(2012, 1, 1, 12, 0, 0))

    with raises(ValueError):
        scalar_coerce('date', 'Jan 1st, 2012 12:00:00')

    assert scalar_coerce('?date', 'Jan 1st, 2012') == date(2012, 1, 1)
    assert scalar_coerce('?date', '2012-12-01') == date(2012, 12, 1)
    assert scalar_coerce('?date', '') == None
Exemple #10
0
def test_scalar_coerce():
    assert scalar_coerce('int', 1) == 1
    assert scalar_coerce('int', '1') == 1
    assert scalar_coerce('{x: int}', '1') == 1
    with raises(TypeError):
        scalar_coerce('{x: int, y: int}', '1')

    assert scalar_coerce('date', 'Jan 1st, 2012') == date(2012, 1, 1)

    assert (scalar_coerce('datetime', 'Jan 1st, 2012 12:00:00') ==
            datetime(2012, 1, 1, 12, 0, 0))

    with raises(ValueError):
        scalar_coerce('date', 'Jan 1st, 2012 12:00:00')

    assert scalar_coerce('?date', 'Jan 1st, 2012') == date(2012, 1, 1)
    assert scalar_coerce('?date', '2012-12-01') == date(2012, 12, 1)
    assert scalar_coerce('?date', '') == None
    assert scalar_coerce('?int', 0) == 0
    assert scalar_coerce('?int', '0') == 0
Exemple #11
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)
Exemple #12
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)
Exemple #13
0
def test_errors():
    t = symbol('t', 'var * {foo: int}')
    with raises(NotImplementedError):
        compute_up(by(t, count=t.count()), 1)
Exemple #14
0
def test_errors():
    t = Symbol('t', 'var * {foo: int}')
    with raises(NotImplementedError):
        compute_up(by(t, t.count()), 1)
Exemple #15
0
def test_errors():
    t = TableSymbol('t', '{foo: int}')
    with raises(NotImplementedError):
        compute_one(by(t, t.count()), 1)