From 1602de7c1c86c6e5d084cac103631027248e2953 Mon Sep 17 00:00:00 2001 From: mboudet Date: Tue, 13 Aug 2024 17:46:04 +0200 Subject: [PATCH] Various fixes --- checkcel/checkcel.py | 5 ++--- checkcel/checkplate.py | 3 +++ checkcel/validators.py | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/checkcel/checkcel.py b/checkcel/checkcel.py index 0f9b814..04f57e7 100644 --- a/checkcel/checkcel.py +++ b/checkcel/checkcel.py @@ -114,10 +114,9 @@ def validate(self): validator_set = set(self.validators) self.missing_validators = self.column_set - validator_set if self.missing_validators: - self.info("\033[1;33m", "Missing...", "\033[0m") - self._log_missing_validators() - if not self.ignore_missing_validators: + self.info("\033[1;33m", "Missing...", "\033[0m") + self._log_missing_validators() return False self.missing_fields = validator_set - self.column_set diff --git a/checkcel/checkplate.py b/checkcel/checkplate.py index 9f584b7..79af3bb 100644 --- a/checkcel/checkplate.py +++ b/checkcel/checkplate.py @@ -82,6 +82,7 @@ def load_from_python_file(self, file_path): self.ignore_space = getattr(custom_class, 'ignore_space', False) self.expected_rows = getattr(custom_class, 'expected_rows', 0) self.freeze_header = getattr(custom_class, 'freeze_header', False) + self.ignore_missing_validators = getattr(custom_class, 'ignore_missing_validators', False) try: self.expected_rows = int(self.expected_rows) except ValueError: @@ -154,6 +155,8 @@ def _load_from_dict(self, data): self.skip_generation = data.get('skip_generation', False) self.skip_validation = data.get('skip_validation', False) self.freeze_header = data.get('freeze_header', False) + self.ignore_missing_validators = data.get('ignore_missing_validators', False) + try: self.expected_rows = int(self.expected_rows) except ValueError: diff --git a/checkcel/validators.py b/checkcel/validators.py index 96a44e2..95e7b25 100644 --- a/checkcel/validators.py +++ b/checkcel/validators.py @@ -188,6 +188,8 @@ def validate(self, field, row_number, row): if field and self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -252,6 +254,8 @@ def validate(self, field, row_number, row): if field and self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -367,6 +371,8 @@ def validate(self, field, row_number, row): ) if field and self.unique: if str(field) in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(str(field)) @@ -467,6 +473,8 @@ def validate(self, field, row_number, row): if field and self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -578,6 +586,8 @@ def validate(self, field, row_number, row): if field and self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -686,6 +696,8 @@ def validate(self, field, row_number, row): if field and self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -764,6 +776,8 @@ def validate(self, field, row_number, row): raise ValidationException(e) if self.unique: if field in self.unique_values: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException("'{}' is already in the column".format(field)) self.unique_values.add(field) @@ -968,6 +982,8 @@ def validate(self, field, row_number, row): if self._can_be_empty(row): return else: + self.invalid_dict["invalid_set"].add(field) + self.invalid_dict["invalid_rows"].add(row_number) raise ValidationException( "Field cannot be empty" )