示例#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']})
示例#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']})
示例#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'])
示例#4
0
def test_default():
    v = V.default("pong")
    assert v(None) == 'pong'
    assert v.__name__ == "default"
示例#5
0
def test_default():
    v = V.default("pong")
    assert v(None) == 'pong'
    assert v.__name__ == "default"
示例#6
0
def test_default():
    v=V.default("pong")
    assert v(None)=='pong'