Ejemplo n.º 1
0
def test_signature_inheritance():
    class IntBinop(Annotable):
        left = Argument(int)
        right = Argument(int)

    class FloatAddRhs(IntBinop):
        right = Argument(float)

    class FloatAddClip(FloatAddRhs):
        left = Argument(float)
        clip_lower = Argument(int, default=0)
        clip_upper = Argument(int, default=10)

    class IntAddClip(FloatAddClip, IntBinop):
        pass

    assert IntBinop.signature == TypeSignature([('left', Argument(int)),
                                                ('right', Argument(int))])
    assert FloatAddRhs.signature == TypeSignature([('left', Argument(int)),
                                                   ('right', Argument(float))])
    assert FloatAddClip.signature == TypeSignature([
        ('left', Argument(float)), ('right', Argument(float)),
        ('clip_lower', Argument(int, default=0)),
        ('clip_upper', Argument(int, default=10))
    ])
    assert IntAddClip.signature == TypeSignature([
        ('left', Argument(int)), ('right', Argument(int)),
        ('clip_lower', Argument(int, default=0)),
        ('clip_upper', Argument(int, default=10))
    ])
Ejemplo n.º 2
0
def test_signature_equals():
    s1 = TypeSignature([
        ('left', Argument(int)),
        ('right', Argument(int))
    ])
    s2 = TypeSignature([
        ('left', Argument(int)),
        ('right', Argument(int))
    ])
    s3 = TypeSignature([
        ('left', Argument(int)),
        ('right', Argument(float))
    ])
    s4 = TypeSignature([
        ('left', Argument(int)),
        ('right', Argument(float))
    ])
    s5 = TypeSignature([
        ('left_one', Argument(int)),
        ('right', Argument(float))
    ])
    s6 = TypeSignature([
        ('left_one', Argument(int)),
        ('right', Argument(int))
    ])
    assert s1 == s2
    assert s3 == s4
    assert s1 != s3
    assert s2 != s4
    assert s1 != s5
    assert s2 != s6
    assert s5 != s6
Ejemplo n.º 3
0
def test_valid_optional(arg, value, expected):
    assert arg(value) == expected


@pytest.mark.parametrize(('arg', 'value', 'expected'), [
    (Argument(int, default=''), None, IbisTypeError),
    (Argument(int), 'lynx', IbisTypeError),
])
def test_invalid_optional(arg, value, expected):
    with pytest.raises(expected):
        arg(value)


between = TypeSignature([
    ('value', Argument(int)),
    ('lower', Argument(int, default=0)),
    ('upper', Argument(int, default=None))
])


@pytest.mark.parametrize(('call', 'expected'), [
    (partial(between, 3), (3, 0, None)),
    (partial(between, 3), (3, 0, None)),
    (partial(between, 3), (3, 0, None)),
    (partial(between, 3, 1), (3, 1, None)),
    (partial(between, 4, 2, 5), (4, 2, 5)),
    (partial(between, 3, lower=1), (3, 1, None)),
    (partial(between, 4, lower=2, upper=5), (4, 2, 5)),
    (partial(between, 4, upper=5), (4, 0, 5)),
    (partial(between, value=4, upper=5), (4, 0, 5)),
])