def test_schema_with_converters_and_validators(): schema = schematec.schema.dictionary( a=validators.required & converters.string & validators.length(3)) assert schema({'a': 123}) == {'a': '123'}
def test_schema_with_converters_and_validators_fail_on_length(): schema = schematec.schema.dictionary( a=validators.required & converters.string & validators.length(3)) with pytest.raises(exc.ValidationError): schema({'a': '1234'})
def test_bound_validator(): schema = schematec.schema.dictionary(a=validators.length(3)) assert schema({'a': '1'}) == {'a': '1'}
def test_bound_validator_error(): schema = schematec.schema.dictionary(a=validators.length(3)) with pytest.raises(exc.ValidationError): schema({'a': '1234'})
def test_schema_with_converters_and_validators_fail_on_convertation(): schema = schematec.schema.array(converters.string & validators.length(3)) with pytest.raises(exc.ConvertationError): schema([None])
def test_schema_with_converters_and_validators_fail_on_length_for_various_values(): schema = schematec.schema.array(converters.string & validators.length(3)) with pytest.raises(exc.ValidationError): schema(['123', '1234'])
def test_bound_validator_error(): schema = schematec.schema.array(validators.length(3)) with pytest.raises(exc.ValidationError): schema(['1234'])
def test_schema_with_converters_and_validators(): schema = schematec.schema.array(converters.string & validators.length(3)) assert schema([123]) == ['123']
def test_bound_validator_skipped(): schema = schematec.schema.array(validators.length(3)) assert schema([1]) == [1]
def test_bound_validator(): schema = schematec.schema.array(validators.length(3)) assert schema(['1']) == ['1']
def test_string(): validators.length(1)('a')
def test_too_long_string(): with pytest.raises(exc.ValidationError): validators.length(1)('aa')
def test_tuple(): validators.length(1)(('1',))
def test_list(): validators.length(1)(['1'])
def test_empty_list(): validators.length(1)([])