-
Notifications
You must be signed in to change notification settings - Fork 16
Introduce a "validation report" into the validation suite #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
e0a29b8
refactor of validate into a report
sgsmob 3938f85
documentation of report
sgsmob 51840c1
plug report logic into the running
sgsmob 08b8446
adding pylintrc to validator package
sgsmob c7d1872
pylint compliance
sgsmob ec9cc20
Merge branch 'validator' into validation_report
sgsmob c2c89fd
Merge branch 'validator' into validation_report
sgsmob 7296aa8
Merge branch 'main' of github.com:cmu-delphi/covidcast-indicators int…
sgsmob 4409fd8
change name of unsuppressed errors
sgsmob fabb50b
change polarity of if/else to be positive
sgsmob be1750a
Merge branch 'main' of github.com:cmu-delphi/covidcast-indicators int…
sgsmob 27c3a79
add_raised_warning documentation
sgsmob da71d08
duplicate rows to use report
sgsmob a8ca165
tests for reports
sgsmob File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
"""Validation output reports.""" | ||
import sys | ||
from datetime import date, datetime | ||
from typing import List, Tuple | ||
|
||
class ValidationReport: | ||
"""Class for reporting the results of validation.""" | ||
def __init__(self, errors_to_suppress: List[Tuple[str]]): | ||
"""Initialize a ValidationReport. | ||
Parameters | ||
---------- | ||
errors_to_suppress: List[Tuple[str]] | ||
List of error identifications to ignore. | ||
|
||
Attributes | ||
---------- | ||
errors_to_suppress: List[Tuple[str]] | ||
See above | ||
num_suppressed: int | ||
Number of errors suppressed | ||
total_checks: int | ||
Number of validation checks performed | ||
raised_errors: List[Exception] | ||
Errors raised from validation failures | ||
raised_warnings: List[Exception] | ||
Warnings raised from validation execution | ||
unsuppressed_errors: List[Exception] | ||
Errors raised from validation failures not found in `self.errors_to_suppress` | ||
""" | ||
self.errors_to_suppress = errors_to_suppress.copy() | ||
self.num_suppressed = 0 | ||
self.total_checks = 0 | ||
self.raised_errors = [] | ||
self.raised_warnings = [] | ||
self.unsuppressed_errors = [] | ||
|
||
def add_raised_error(self, error): | ||
"""Add an error to the report. | ||
Parameters | ||
---------- | ||
error: Exception | ||
Error raised in validation | ||
|
||
Returns | ||
------- | ||
None | ||
""" | ||
self.raised_errors.append(error) | ||
# Convert any dates in check_data_id to strings for the purpose of comparing | ||
# to manually suppressed errors. | ||
raised_check_id = tuple([ | ||
item.strftime("%Y-%m-%d") if isinstance(item, (date, datetime)) | ||
else item for item in error.check_data_id]) | ||
|
||
if raised_check_id in self.errors_to_suppress: | ||
self.errors_to_suppress.remove(raised_check_id) | ||
self.num_suppressed += 1 | ||
else: | ||
self.unsuppressed_errors.append(error) | ||
|
||
def increment_total_checks(self): | ||
"""Records a check.""" | ||
self.total_checks += 1 | ||
|
||
def add_raised_warning(self, warning): | ||
"""Add a warning to the report. | ||
Parameters | ||
---------- | ||
warning: Warning | ||
Warning raised in validation | ||
|
||
Returns | ||
------- | ||
None | ||
""" | ||
self.raised_warnings.append(warning) | ||
|
||
def __str__(self): | ||
"""String representation of report.""" | ||
out_str = f"{self.total_checks} checks run\n" | ||
out_str += f"{len(self.unsuppressed_errors)} checks failed\n" | ||
out_str += f"{self.num_suppressed} checks suppressed\n" | ||
out_str += f"{len(self.raised_warnings)} warnings\n" | ||
for message in self.unsuppressed_errors: | ||
out_str += f"{message}\n" | ||
for message in self.raised_warnings: | ||
out_str += f"{message}\n" | ||
return out_str | ||
|
||
def print_and_exit(self): | ||
""" | ||
Print results and, if any not-suppressed exceptions were raised, exit with non-zero status. | ||
""" | ||
print(self) | ||
if len(self.unsuppressed_errors) != 0: | ||
sys.exit(1) | ||
else: | ||
sys.exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a test that this formats to what we expect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests for the whole report class