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"}
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'}
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"}
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')