示例#1
0
def test_fields_equal():
    values = ("pong", "pong")
    v = V.fields_equal('hog')
    assert v.__name__ == "fields_equal"
    assert values == v(values)
    values = ('tim', 'worthy')
    assert_invalid(lambda: v(values), {None: 'hog'})
    s = V.Schema({
        'foo': V.to_integer(),
        ('foo', 'bar'): V.fields_equal(u"foo and bar don't match")
    })
    d = dict(foo='1', bar=1)
    expected = dict(foo=1, bar=1)
    assert s(d) == expected
    # Check field=None
    s = V.Schema({
        'foo':
        V.to_integer(),
        ('foo', 'bar'):
        V.fields_equal(u"foo and bar don't match", field=None)
    })
    d = dict(foo='1', bar=2)
    with py.test.raises(V.Invalid) as e:
        s(d)
    errors = e.value.unpack_errors()
    assert errors == {None: u"foo and bar don't match"}
示例#2
0
def test_schema_4():
    s = V.Schema(
        {
            'foo': V.is_integer(),
            'bar': V.is_integer(),
            ('foo', 'bar'): V.fields_equal(msg='flam', field=None)
        },
        msg="flibble")
    d = dict(foo=1, bar=2)
    with py.test.raises(V.Invalid) as e:
        s(d)
    errors = e.value.unpack_errors()
    assert errors == {None: 'flam'}
示例#3
0
def test_schema_4():
    s = V.Schema(
        {
            'foo': V.is_integer(),
            'bar': V.is_integer(),
            ('foo', 'bar'): V.fields_equal(msg='flam', field=None)
        },
        msg="flibble")
    d = dict(foo=1, bar=2)
    with py.test.raises(V.Invalid) as e:
        s(d)
    errors = e.value.unpack_errors()
    assert errors == {None: 'flam'}
示例#4
0
def test_fields_equal():
    values = ("pong", "pong")
    v = V.fields_equal('hog')
    assert v.__name__ == "fields_equal"
    assert values == v(values)
    values = ('tim', 'worthy')
    assert_invalid(
        lambda: v(values),
        {None: 'hog'})
    s = V.Schema({
        'foo': V.to_integer(),
        ('foo', 'bar'): V.fields_equal(u"foo and bar don't match")})
    d = dict(foo='1', bar=1)
    expected = dict(foo=1, bar=1)
    assert s(d) == expected
    # Check field=None
    s = V.Schema({
        'foo': V.to_integer(),
        ('foo', 'bar'): V.fields_equal(u"foo and bar don't match", field=None)})
    d = dict(foo='1', bar=2)
    with py.test.raises(V.Invalid) as e:
        s(d)
    errors = e.value.unpack_errors()
    assert errors == {None: u"foo and bar don't match"}
示例#5
0
def test_fields_equal():
    values=("pong", "pong")
    v=V.fields_equal('hog')
    assert values==v(values)
    values=('tim', 'worthy')
    assert_invalid(lambda: v(values), 'hog')