Commit 49830fce authored by Pierre Dittgen's avatar Pierre Dittgen

fix structure_warnings

parent ff95c92a
Pipeline #2409 failed with stage
in 2 minutes and 17 seconds
......@@ -10,12 +10,13 @@
"""
from dataclasses import dataclass
@dataclass
class StructureWarning:
code: str
name: str
message: str
field_name: str = ""
def structure_warning(code: str, name: str, message: str, field_name: str = ""):
return {
"code": code,
"name": name,
"message": message,
"field_name": field_name
}
def iter_structure_warnings(source_header, required_field_names, schema):
......@@ -26,7 +27,7 @@ def iter_structure_warnings(source_header, required_field_names, schema):
for field_name in schema_field_names:
if field_name not in source_header and field_name not in required_field_names:
# yield MissingHeaderWarning(field_name) # extra fields
yield StructureWarning(
yield structure_warning(
"missing-header-warn",
"colonne manquante",
f"La colonne `{field_name}` est absente du fichier",
......@@ -35,15 +36,15 @@ def iter_structure_warnings(source_header, required_field_names, schema):
for h in source_header:
if h not in schema_field_names:
yield StructureWarning(
yield structure_warning(
"extra-header-warn",
"colonne surnuméraire",
f"La colonne `{field_name}` n'est pas définie dans le schéma",
field_name,
f"La colonne `{h}` n'est pas définie dans le schéma",
h,
)
if set(source_header) == set(schema_field_names) and source_header != schema_field_names:
yield StructureWarning(
yield structure_warning(
"disordered-header-warn",
"colonnes désordonnées",
f"l'ordre des colonnes ne respecte pas celui défini dans le schéma : {schema_field_names!r}",
......
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