Exemplo n.º 1
0
 def _operator_helper(self, other, op, reversed=False, isSop=False):
     if isSop:
         # single operand operators
         return self.map(lambda x: op(x))
     elif not isinstance(other, ptype.PType):
         if reversed:
             return self.map(lambda x: op(other, x))
         else:
             return self.map(lambda x: op(x, other))
     else:
         return self.map(lambda x, other: op(x, other), other)
Exemplo n.º 2
0
 def _operator_helper(self, other, op, reversed=False, isSop=False):
     if isSop:
         # single operand operators
         return self.map(lambda x: op(x))
     elif not isinstance(other, ptype.PType):
         if reversed:
             return self.map(lambda x: op(other, x))
         else:
             return self.map(lambda x: op(x, other))
     else:
         return self.map(lambda x, other: op(x, other), other)
Exemplo n.º 3
0
def test_scalar_ops(data):
    from operator import add, sub, mul, truediv

    for op in (add, sub, mul, truediv):
        assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10))
        assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id']))
        assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount']))
        assert eq(compute(op(10, t.amount), data), op(10, x['amount']))
Exemplo n.º 4
0
def test_scalar_ops(data):
    from operator import add, sub, mul, truediv

    for op in (add, sub, mul, truediv):
        assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10))
        assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id']))
        assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount']))
        assert eq(compute(op(10, t.amount), data), op(10, x['amount']))
Exemplo n.º 5
0
def test_failing_floordiv(data):
    from operator import floordiv as op

    with pytest.raises(TypeError):
        assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10))

    with pytest.raises(TypeError):
        assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id']))

    with pytest.raises(TypeError):
        assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount']))

    with pytest.raises(TypeError):
        assert eq(compute(op(10, t.amount), data), op(10, x['amount']))
Exemplo n.º 6
0
def test_failing_floordiv(data):
    from operator import floordiv as op

    with pytest.raises(TypeError):
        assert eq(compute(op(t.amount, 10), data), op(x['amount'], 10))

    with pytest.raises(TypeError):
        assert eq(compute(op(t.amount, t.id), data), op(x['amount'], x['id']))

    with pytest.raises(TypeError):
        assert eq(compute(op(10.0, t.amount), data), op(10.0, x['amount']))

    with pytest.raises(TypeError):
        assert eq(compute(op(10, t.amount), data), op(10, x['amount']))