7
7
class ValidationReport :
8
8
"""Class for reporting the results of validation."""
9
9
10
- def __init__ (self , errors_to_suppress : List [ValidationFailure ]):
10
+ def __init__ (self , errors_to_suppress : List [ValidationFailure ], data_source : str = "" ):
11
11
"""Initialize a ValidationReport.
12
12
13
13
Parameters
14
14
----------
15
15
errors_to_suppress: List[ValidationFailure]
16
16
List of ValidationFailures to ignore.
17
+ data_source: str
18
+ Name of data source as obtained from params
17
19
18
20
Attributes
19
21
----------
20
22
errors_to_suppress: List[ValidationFailure]
21
23
See above
24
+ data_source: str
25
+ See above
22
26
num_suppressed: int
23
27
Number of errors suppressed
24
28
total_checks: int
@@ -31,12 +35,12 @@ def __init__(self, errors_to_suppress: List[ValidationFailure]):
31
35
Errors raised from validation failures not found in `self.errors_to_suppress`
32
36
"""
33
37
self .errors_to_suppress = errors_to_suppress
38
+ self .data_source = data_source
34
39
self .num_suppressed = 0
35
40
self .total_checks = 0
36
41
self .raised_errors = []
37
42
self .raised_warnings = []
38
43
self .unsuppressed_errors = []
39
- self .summary = ""
40
44
41
45
def add_raised_error (self , error ):
42
46
"""Add an error to the report.
@@ -74,21 +78,25 @@ def add_raised_warning(self, warning):
74
78
"""
75
79
self .raised_warnings .append (warning )
76
80
77
- def set_summary (self ):
78
- """Represent summary of report as a string."""
79
- out_str = f"{ self .total_checks } checks run\n "
80
- out_str += f"{ len (self .unsuppressed_errors )} checks failed\n "
81
- out_str += f"{ self .num_suppressed } checks suppressed\n "
82
- out_str += f"{ len (self .raised_warnings )} warnings\n "
83
- self .summary = out_str
84
-
85
81
def log (self , logger = None ):
86
82
"""Log errors and warnings."""
87
83
if logger is None :
88
84
logger = get_structured_logger (__name__ )
89
85
90
- self .set_summary ()
91
- logger .info (self .summary )
86
+ if self .success ():
87
+ logger .info ("Validation run successful" ,
88
+ data_source = self .data_source ,
89
+ checks_run = self .total_checks ,
90
+ checks_failed = len (self .unsuppressed_errors ),
91
+ checks_suppressed = self .num_suppressed ,
92
+ warnings = len (self .raised_warnings ))
93
+ else :
94
+ logger .info ("Validation run unsuccessful" ,
95
+ data_source = self .data_source ,
96
+ checks_run = self .total_checks ,
97
+ checks_failed = len (self .unsuppressed_errors ),
98
+ checks_suppressed = self .num_suppressed ,
99
+ warnings = len (self .raised_warnings ))
92
100
for error in self .unsuppressed_errors :
93
101
logger .critical (str (error ))
94
102
for warning in self .raised_warnings :
0 commit comments