Commit c425a888 authored by Pierre Dittgen's avatar Pierre Dittgen
Browse files

Every custom check carries it own code. It now emits check-errors instead of task-error

parent 6f6dc913
......@@ -11,13 +11,13 @@ from .year_interval_value import YearIntervalValue
# Please keep the below dict up-to-date
available_checks = {
"cohesive-columns-value": CohesiveColumnsValue,
"compare-columns-value": CompareColumnsValue,
"french-siren-value": FrenchSirenValue,
"french-siret-value": FrenchSiretValue,
"nomenclature-actes-value": NomenclatureActesValue,
"opening-hours-value": OpeningHoursValue,
"phone-number-value": PhoneNumberValue,
"sum-columns-value": SumColumnsValue,
"year-interval-value": YearIntervalValue,
CohesiveColumnsValue.code: CohesiveColumnsValue,
CompareColumnsValue.code: CompareColumnsValue,
FrenchSirenValue.code: FrenchSirenValue,
FrenchSiretValue.code: FrenchSiretValue,
NomenclatureActesValue.code: NomenclatureActesValue,
OpeningHoursValue.code: OpeningHoursValue,
PhoneNumberValue.code: PhoneNumberValue,
SumColumnsValue.code: SumColumnsValue,
YearIntervalValue.code: YearIntervalValue,
}
......@@ -18,6 +18,8 @@
"""
from frictionless import Check, errors
from .utils import build_check_error
# Module API
......@@ -36,6 +38,7 @@ class CohesiveColumnsValue(Check):
Cohesive columns value check class
"""
code = "cohesive-columns-value"
possible_Errors = [CohesiveColumnsValueError]
def __init__(self, descriptor=None):
......@@ -48,15 +51,15 @@ class CohesiveColumnsValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
yield build_check_error(CohesiveColumnsValue.code, note)
elif len(self.__other_columns) == 0:
note = "La liste de colonnes à comparer est vide"
yield errors.TaskError(note=note)
yield build_check_error(CohesiveColumnsValue.code, note)
else:
for col in self.__other_columns:
if col not in self.resource.schema.field_names:
note = f"La colonne à comparer {col!r} est manquante"
yield errors.TaskError(note=note)
yield build_check_error(CohesiveColumnsValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
......@@ -35,6 +35,8 @@ import decimal
from frictionless import Check, errors
from simpleeval import simple_eval
from .utils import build_check_error
OP_LABELS = {
">": "supérieure",
">=": "supérieure ou égale",
......@@ -57,6 +59,7 @@ class CompareColumnsValueError(errors.CellError):
class CompareColumnsValue(Check):
"""Compare columns value check class."""
code = "compare-columns-value"
possible_Errors = [CompareColumnsValueError]
def __init__(self, descriptor=None):
......@@ -67,14 +70,14 @@ class CompareColumnsValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(CompareColumnsValue.code, note)
elif self.__column2 not in self.resource.schema.field_names:
note = f"La colonne {self.__column2!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column2!r} n'est pas trouvée."
yield build_check_error(CompareColumnsValue.code, note)
elif self.__op not in OP_LABELS:
note = f"L'opérateur {self.__op!r} n'est pas géré."
yield errors.TaskError(note=note)
yield build_check_error(CompareColumnsValue.code, note)
def validate_row(self, row):
cell_value1 = row[self.__column]
......
import stdnum.fr.siren
from frictionless import Check, errors
from .utils import build_check_error
class FrenchSirenValueError(errors.CellError):
"""Custom error."""
......@@ -18,6 +20,7 @@ class FrenchSirenValueError(errors.CellError):
class FrenchSirenValue(Check):
"""Check french SIREN number validity."""
code = "french-siren-value"
possible_Errors = [FrenchSirenValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -26,8 +29,8 @@ class FrenchSirenValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(FrenchSirenValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
import stdnum.fr.siret
from frictionless import Check, errors
from .utils import build_check_error
class FrenchSiretValueError(errors.CellError):
"""Custom error."""
......@@ -18,6 +20,7 @@ class FrenchSiretValueError(errors.CellError):
class FrenchSiretValue(Check):
"""Check french SIRET number validity."""
code = "french-siret-value"
possible_Errors = [FrenchSiretValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -26,8 +29,8 @@ class FrenchSiretValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(FrenchSiretValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
......@@ -24,6 +24,8 @@ import unicodedata
from frictionless import Check, errors
from .utils import build_check_error
# Module API
AUTHORIZED_VALUES = [
......@@ -54,6 +56,7 @@ class NomenclatureActesValueError(errors.CellError):
class NomenclatureActesValue(Check):
code = "nomenclature-actes-value"
possible_Errors = [NomenclatureActesValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -63,8 +66,8 @@ class NomenclatureActesValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante." ""
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée." ""
yield build_check_error(NomenclatureActesValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
import opening_hours
from frictionless import Check, errors
from .utils import build_check_error
class OpeningHoursValueError(errors.CellError):
"""Custom error."""
......@@ -20,6 +22,7 @@ class OpeningHoursValueError(errors.CellError):
class OpeningHoursValue(Check):
"""Check opening hours validity."""
code = "opening-hours-value"
possible_Errors = [OpeningHoursValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -28,8 +31,8 @@ class OpeningHoursValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(OpeningHoursValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
import phonenumbers
from frictionless import Check, errors
from .utils import build_check_error
def is_valid_number_for_country(phone_number: str, *, country_code=None):
"""Check if a phone number, giving an optional country_code.
......@@ -46,6 +48,7 @@ class PhoneNumberValueError(errors.CellError):
class PhoneNumberValue(Check):
"""Check phone number validity."""
code = "phone-number-value"
possible_Errors = [PhoneNumberValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -54,8 +57,8 @@ class PhoneNumberValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(PhoneNumberValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
......@@ -3,6 +3,8 @@ import re
from frictionless import Check, errors
from .utils import build_check_error
"""
Sum columns value check
......@@ -45,6 +47,7 @@ class SumColumnsValueError(errors.CellError):
class SumColumnsValue(Check):
"""Sum columns value check."""
code = "sum-columns-value"
possible_Errors = [SumColumnsValueError]
def __init__(self, descriptor=None):
......@@ -55,16 +58,16 @@ class SumColumnsValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"la colonne {self.__column!r} est manquante"
yield errors.TaskError(note=note)
note = f"la colonne {self.__column!r} n'est pas trouvée"
yield build_check_error(SumColumnsValue.code, note)
elif len(self.__columns) < 2:
note = "le nombre de colonnes est insuffisant pour l'addition"
yield errors.TaskError(note=note)
yield build_check_error(SumColumnsValue.code, note)
else:
for col in self.__columns:
if col not in self.resource.schema.field_names:
note = f"la colonne {col!r} est manquante."
yield errors.TaskError(note=note)
note = f"la colonne {col!r} n'est pas trouvée."
yield build_check_error(SumColumnsValue.code, note)
def validate_row(self, row):
cell_values = [row[col] for col in self.__all_columns]
......
from frictionless import errors
def build_check_error(custom_check_code: str, note: str):
custom_note = f"{custom_check_code!r}: {note}"
return errors.CheckError(note=custom_note)
......@@ -20,6 +20,8 @@ import re
from frictionless import Check, errors
from .utils import build_check_error
YEAR_INTERVAL_RE = re.compile(r"^(\d{4})/(\d{4})$")
YEAR_RE = re.compile(r"^\d{4}$")
......@@ -39,6 +41,7 @@ class YearIntervalValueError(errors.CellError):
class YearIntervalValue(Check):
"""Year Interval Value check class."""
code = "year-interval-value"
possible_Errors = [YearIntervalValueError] # type: ignore
def __init__(self, descriptor=None):
......@@ -48,8 +51,8 @@ class YearIntervalValue(Check):
def validate_start(self):
if self.__column not in self.resource.schema.field_names:
note = f"La colonne {self.__column!r} est manquante."
yield errors.TaskError(note=note)
note = f"La colonne {self.__column!r} n'est pas trouvée."
yield build_check_error(YearIntervalValue.code, note)
def validate_row(self, row):
cell_value = row[self.__column]
......
Supports Markdown
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