Commit 938ccb79 authored by Pierre Dittgen's avatar Pierre Dittgen

Dealing with type-or-format error on boolean

parent 4f37e535
......@@ -13,6 +13,26 @@ def update_msg(err, msg):
err['message'] = msg
return err
def et_join(values):
"""french enum
>>> et_join([])
''
>>> et_join(['a'])
'a'
>>> et_join(['a','b'])
'a et b'
>>> et_join(['a','b','c'])
'a, b et c'
>>> et_join(['a','b','c','d','e'])
'a, b, c, d et e'
"""
if values is None or len(values) == 0:
return ''
if len(values) == 1:
return values[0]
return ' et '.join([', '.join(values[:-1]), values[-1]])
# Core goodtables checks
......@@ -28,9 +48,7 @@ def duplicate_row(err, headers, schema):
if not ',' in row_numbers:
msg = msg_prefix + "à la ligne {}".format(row_numbers)
else:
idx = row_numbers.rfind(',')
param_str = row_numbers[:idx] + ' et' + row_numbers[idx+1:]
msg = msg_prefix + "aux lignes {}".format(param_str)
msg = msg_prefix + "aux lignes {}".format(et_join(row_numbers))
return update_msg(err, msg)
......@@ -41,7 +59,7 @@ def enumerable_constraint(err, headers, schema):
if len(ok_values) == 1:
return update_msg(err, 'Valeur incorrecte. La valeur autorisée est : {}'.format(ok_values[0]))
else:
ok_values_str = ', '.join(ok_values[:-2] + [ok_values[-2] + ' et ' + ok_values[-1]])
ok_values_str = et_join(ok_values)
return update_msg(err, 'Valeur incorrecte. Les valeurs autorisées sont : {}'.format(ok_values_str))
......@@ -105,7 +123,12 @@ def type_or_format_error(err, headers, schema):
return update_msg(err, "Le format du nombre est incorrect.\nLa forme attendue est \"{}\"".format(en_number))
# Boolean
# elif err_type == 'boolean':
elif err_type == 'boolean':
column_number = err['column-number']
field = schema['fields'][column_number]
true_values = field.get('trueValues', ['true'])
false_values = field.get('falseValues', ['false'])
return update_msg(err, "Valeur incorrecte. Les valeurs acceptées sont {} pour 'vrai' et {} pour 'faux'".format(et_join(false_values), et_join(true_values)))
# Default msg
return update_msg(err, 'XXXX {} XXXX'.format(err_type))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment