Ejemplo n.º 1
0
def test_pyfunc_works_with_invalid_python_names():
    x = symbol("x-y.z", "int")
    f = lambdify([x], x + 1)
    assert f(1) == 2

    t = symbol("t", '{"x.y": int, "y z": int}')
    f = lambdify([t], t.x_y + t.y_z)
    assert f((1, 2)) == 3
Ejemplo n.º 2
0
def test_pyfunc_works_with_invalid_python_names():
    x = symbol('x-y.z', 'int')
    f = lambdify([x], x + 1)
    assert f(1) == 2

    t = symbol('t', '{"x.y": int, "y z": int}')
    f = lambdify([t], t.x_y + t.y_z)
    assert f((1, 2)) == 3
Ejemplo n.º 3
0
def test_not():
    x = symbol('x', 'bool')
    f = lambdify([x], ~x)
    r = f(True)
    assert isinstance(r, bool) and not r

    r = f(False)
    assert isinstance(r, bool) and r
Ejemplo n.º 4
0
def test_not():
    x = symbol("x", "bool")
    f = lambdify([x], ~x)
    r = f(True)
    assert isinstance(r, bool) and not r

    r = f(False)
    assert isinstance(r, bool) and r
Ejemplo n.º 5
0
def test_datetime_literals():
    f = lambdify([t], t.when > "2000-01-01")
    assert f((1, 0, 3, datetime.datetime(2000, 1, 2))) == True
    assert f((1, 0, 3, datetime.datetime(1999, 1, 2))) == False
Ejemplo n.º 6
0
def test_math():
    f = lambdify([t], abs(t.x) + cos(t.y))
    assert f((-1, 0, 3, 4)) == 1 + math.cos(0.0)
Ejemplo n.º 7
0
def test_map():
    f = lambdify([t], t.x + t.y.map(inc, "int"))
    assert f((1, 2, 3, 4)) == 1 + inc(2)
Ejemplo n.º 8
0
def test_datetime():
    f = lambdify([t], t.x + t.when.year)

    assert f((1, 2, 3, datetime.datetime(2000, 1, 1))) == 1 + 2000
Ejemplo n.º 9
0
def test_simple():
    f = lambdify([t], t.x + t.y)
    assert f((1, 2, 3, 4)) == 1 + 2

    f = lambdify([t.x, t.y], t.x + t.y)
    assert f(1, 2) == 1 + 2
Ejemplo n.º 10
0
def test_map():
    f = lambdify([t], t.x + t.y.map(inc, 'int'))
    assert f((1, 2, 3, 4)) == 1 + inc(2)
Ejemplo n.º 11
0
def test_datetime_literals():
    f = lambdify([t], t.when > '2000-01-01')
    assert f((1, 0, 3, datetime.datetime(2000, 1, 2)))
    assert not f((1, 0, 3, datetime.datetime(1999, 1, 2)))
Ejemplo n.º 12
0
def test_simple():
    f = lambdify([t], t.x + t.y)
    assert f((1, 2, 3, 4)) == 1 + 2

    f = lambdify([t.x, t.y], t.x + t.y)
    assert f(1, 2) == 1 + 2
Ejemplo n.º 13
0
def test_usub():
    x = symbol('x', 'float64')
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Ejemplo n.º 14
0
def test_datetime_literals():
    f = lambdify([t], t.when > '2000-01-01')
    assert f((1, 0, 3, datetime.datetime(2000, 1, 2)))
    assert not f((1, 0, 3, datetime.datetime(1999, 1, 2)))
Ejemplo n.º 15
0
def test_math():
    f = lambdify([t], abs(t.x) + cos(t.y))
    assert f((-1, 0, 3, 4)) == 1 + math.cos(0.0)
Ejemplo n.º 16
0
def test_usub():
    x = symbol("x", "float64")
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Ejemplo n.º 17
0
def test_usub():
    x = symbol('x', 'float64')
    f = lambdify([x], -x)
    assert f(1.0) == -1.0
Ejemplo n.º 18
0
def test_datetime():
    f = lambdify([t], t.x + t.when.year)

    assert f((1, 2, 3, datetime.datetime(2000, 1, 1))) == 1 + 2000