Skip to content

Commit 1f8153b

Browse files
authored
Merge pull request #1184 from cmu-delphi/validator-dry-run
Improve validator dry run functionality
2 parents e01ddb1 + 97f738f commit 1f8153b

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

_delphi_utils_python/delphi_utils/validator/report.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
class ValidationReport:
88
"""Class for reporting the results of validation."""
99

10-
def __init__(self, errors_to_suppress: List[ValidationFailure], data_source: str = ""):
10+
# pylint: disable=R0902
11+
def __init__(self, errors_to_suppress: List[ValidationFailure],
12+
data_source: str = "", dry_run: bool = False):
1113
"""Initialize a ValidationReport.
1214
1315
Parameters
@@ -41,6 +43,8 @@ def __init__(self, errors_to_suppress: List[ValidationFailure], data_source: str
4143
self.raised_errors = []
4244
self.raised_warnings = []
4345
self.unsuppressed_errors = []
46+
self.dry_run = dry_run
47+
# pylint: enable=R0902
4448

4549
def add_raised_error(self, error):
4650
"""Add an error to the report.
@@ -120,4 +124,4 @@ def print_and_exit(self, logger=None, die_on_failures=True):
120124

121125
def success(self):
122126
"""Determine if the report corresponds to a successful validation run."""
123-
return len(self.unsuppressed_errors) == 0
127+
return len(self.unsuppressed_errors) == 0 or self.dry_run

_delphi_utils_python/delphi_utils/validator/run.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ def run_module():
1616
" status irrespective of the number of failures")
1717
args = parser.parse_args()
1818
params = read_params()
19+
assert "validation" in params
20+
dry_run_param = params["validation"]["common"].get("dry_run", False)
21+
params["validation"]["common"]["dry_run"] = args.dry_run or dry_run_param
1922
validator = Validator(params)
2023
validator.validate().print_and_exit(
2124
get_structured_logger(__name__,
2225
params["common"].get("log_filename", None)),
23-
not args.dry_run)
26+
not (args.dry_run or dry_run_param))
2427

2528

2629
def validator_from_params(params):

_delphi_utils_python/delphi_utils/validator/validate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def __init__(self, params):
3939
self.time_window = TimeWindow.from_params(validation_params["common"]["end_date"],
4040
validation_params["common"]["span_length"])
4141
self.data_source = validation_params["common"].get("data_source", "")
42+
self.dry_run = validation_params["common"].get("dry_run", False)
4243

4344
self.static_validation = StaticValidator(validation_params)
4445
self.dynamic_validation = DynamicValidator(validation_params)
@@ -53,7 +54,7 @@ def validate(self):
5354
Returns:
5455
- ValidationReport collating the validation outcomes
5556
"""
56-
report = ValidationReport(self.suppressed_errors, self.data_source)
57+
report = ValidationReport(self.suppressed_errors, self.data_source, self.dry_run)
5758
frames_list = load_all_files(self.export_dir, self.time_window.start_date,
5859
self.time_window.end_date)
5960
self.static_validation.validate(frames_list, report)

0 commit comments

Comments
 (0)