Example #1
0
def test_all_of_2():
    messages = dict(to_integer='not an integer',
                  belongs='invalid choice',
                  min='too small',
                  max='too big')
    v = V.all_of(V.default(40),
                V.strip,
                V.to_integer(msg=messages),
                V.belongs(range(4, 100, 4), messages),
                V.clamp(min=20, max=50, msg=messages))
    assert v(None) == 40
    assert v('40') == 40
    assert v('44  ') == 44
    assert_invalid(
        lambda: v(' prick '),
        {None: messages['to_integer']})
    assert_invalid(
        lambda: v(' 41  '),
        {None: messages['belongs']})
    assert_invalid(
        lambda: v('96'),
        {None: messages['max']})
    assert_invalid(
        lambda: v('8'),
        {None: messages['min']})
Example #2
0
def test_all_of_2():
    messages = dict(to_integer='not an integer',
                    belongs='invalid choice',
                    min='too small',
                    max='too big')
    v = V.all_of(V.default(40), V.strip, V.to_integer(msg=messages),
                 V.belongs(range(4, 100, 4), messages),
                 V.clamp(min=20, max=50, msg=messages))
    assert v(None) == 40
    assert v('40') == 40
    assert v('44  ') == 44
    assert_invalid(lambda: v(' prick '), {None: messages['to_integer']})
    assert_invalid(lambda: v(' 41  '), {None: messages['belongs']})
    assert_invalid(lambda: v('96'), {None: messages['max']})
    assert_invalid(lambda: v('8'), {None: messages['min']})
Example #3
0
def test_compose():
    messages=dict(integer='please enter an integer',
                  belongs='invalid choice',
                  min='too small',
                  max='too big')
    v=V.compose(V.default(40),
                V.strip,
                V.integer(msg=messages),
                V.belongs(range(4, 100, 4), messages),
                V.clamp(min=20, max=50, msg=messages))
    assert v(None)==40
    assert v('40')==40
    assert v('44  ')==44
    assert_invalid(lambda: v(' prick '), messages['integer'])
    assert_invalid(lambda: v(' 41  '), messages['belongs'])
    assert_invalid(lambda: v('96'), messages['max'])
    assert_invalid(lambda: v('8'), messages['min'])
Example #4
0
def test_default():
    v = V.default("pong")
    assert v(None) == 'pong'
    assert v.__name__ == "default"
Example #5
0
def test_default():
    v = V.default("pong")
    assert v(None) == 'pong'
    assert v.__name__ == "default"
Example #6
0
def test_default():
    v=V.default("pong")
    assert v(None)=='pong'