示例#1
0
def test_reverse_add():

    y = 1 + var('x')

    assert y.params == (1, var('x'))
    assert y == ast('add', 1, var('x'))
    assert repr(y) == "1 + var('x')"
示例#2
0
def test_add():

    y = var('x') + 5

    assert y.params == (var('x'), 5)
    assert y == ast('add', var('x'), 5)
    assert repr(y) == "var('x') + 5"
示例#3
0
def test_with_parameter():
    @func
    def my_func(x, y=2):
        return arr([1, 2, 3, 4]) + x + y

    assert my_func.ast == arr([1, 2, 3, 4]) + var('x') + var('y')
    assert my_func.ast == add(arr([1, 2, 3, 4]), var('x'), var('y'))
    assert repr(my_func) == (
        "def my_func(x, y=2): return arr([1, 2, 3, 4]) + var('x') + var('y')")

    with pytest.raises(NotImplementedError):
        my_func(5)
示例#4
0
def test_var():

    x = var('x')

    assert x.params == ('x',)
    assert x.params.name == 'x'
    assert x == ast('var', 'x')
    assert repr(x) == "var('x')"