Skip to content

Commit 995d9b4

Browse files
Fix: Attach event hooks to proper classes (#56)
1 parent d3206bb commit 995d9b4

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

data_validation_framework/task.py

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -216,16 +216,6 @@ def inputs(self):
216216
def __init__(self, *args, **kwargs):
217217
warnings.filterwarnings("ignore", module="numpy", category=VisibleDeprecationWarning)
218218
warnings.filterwarnings("ignore", module="luigi.task", category=DeprecationWarning)
219-
event_handler = super().event_handler
220-
221-
# pylint: disable=unused-variable
222-
@event_handler(luigi.Event.SUCCESS)
223-
def success_summary(self):
224-
"""Summary report of the task."""
225-
L.info("==========================================")
226-
task_summary = f"SUMMARY {self.task_name}: {self.nb_valid} / {self.nb_total} passed"
227-
L.info(task_summary)
228-
L.info("==========================================")
229219

230220
super().__init__(*args, **kwargs)
231221

@@ -646,6 +636,15 @@ def __specifications__(self):
646636
return self.__doc__
647637

648638

639+
@BaseValidationTask.event_handler(luigi.Event.SUCCESS)
640+
def success_summary(self):
641+
"""Hook to log a summary report of the task."""
642+
L.info("==========================================")
643+
task_summary = f"SUMMARY {self.task_name}: {self.nb_valid} / {self.nb_total} passed"
644+
L.info(task_summary)
645+
L.info("==========================================")
646+
647+
649648
class ElementValidationTask(BaseValidationTask):
650649
"""A class to validate each element of a data set without considering the other elements.
651650
@@ -733,23 +732,6 @@ class ValidationWorkflow(SetValidationTask, luigi.WrapperTask):
733732
gather_inputs = True
734733

735734
def __init__(self, *args, **kwargs):
736-
event_handler = super().event_handler
737-
738-
# pylint: disable=unused-variable
739-
@event_handler(luigi.Event.SUCCESS)
740-
def spec_report(current_task):
741-
"""Hook to create a specification report."""
742-
L.debug("Generating report of %s", current_task)
743-
if current_task.generate_report:
744-
try:
745-
make_report(current_task, config=self.report_config)
746-
# pylint: disable=broad-except
747-
except Exception as e: # pragma: no cover
748-
L.error(
749-
"The report could not be generated because of the following exception: %s",
750-
e,
751-
)
752-
753735
super().__init__(*args, **kwargs)
754736

755737
if self.specifications_only:
@@ -768,6 +750,21 @@ def validation_function(*args, **kwargs):
768750
"""
769751

770752

753+
@ValidationWorkflow.event_handler(luigi.Event.SUCCESS)
754+
def spec_report(current_task):
755+
"""Hook to create a specification report."""
756+
L.debug("Generating report of %s", current_task)
757+
if current_task.generate_report:
758+
try:
759+
make_report(current_task, config=current_task.report_config)
760+
# pylint: disable=broad-except
761+
except Exception as e: # pragma: no cover
762+
L.error(
763+
"The report could not be generated because of the following exception: %s",
764+
e,
765+
)
766+
767+
771768
def _skippable_element_validation_function(validation_function, skip, *args, **kwargs):
772769
"""Skipping wrapper for an element validation function."""
773770
if skip:

0 commit comments

Comments
 (0)