Skip to content

Commit 651c048

Browse files
authored
Merge pull request #1749 from M5Skid/issue1746_validator-no-output
Issue1746 validator no output
2 parents a3b3b7d + 8d5fc6b commit 651c048

File tree

3 files changed

+52
-22
lines changed

3 files changed

+52
-22
lines changed

_delphi_utils_python/delphi_utils/validator/static.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,34 @@ def check_missing_date_files(self, daily_filenames, report):
9090
Returns:
9191
- None
9292
"""
93-
# Create set of all dates seen in CSV names.
94-
unique_dates = {datetime.strptime(
95-
daily_filename[0][0:8], '%Y%m%d').date() for daily_filename in daily_filenames}
96-
97-
# Diff expected and observed dates.
98-
expected_dates = self.params.time_window.date_seq
99-
100-
if len(self.params.max_expected_lag) == 0:
101-
max_expected_lag_overall = 10
102-
else:
103-
max_expected_lag_overall = max(self.params.max_expected_lag.values())
104-
105-
# Only check for date if it should definitely be present,
106-
# i.e if it is more than max_expected_lag since the checking date
107-
expected_dates = [date for date in expected_dates if
108-
((datetime.today().date() - date).days) > max_expected_lag_overall]
109-
check_dateholes = list(set(expected_dates).difference(unique_dates))
110-
check_dateholes.sort()
111-
112-
if check_dateholes:
93+
# Check to see if there are any files in the export directory
94+
# Validator will throw an error if the directory is empty, which can be suppressed
95+
if len(daily_filenames) == 0:
11396
report.add_raised_error(
114-
ValidationFailure("check_missing_date_files",
97+
ValidationFailure("check_empty_filelist",
98+
message="No files found in export directory"))
99+
# Check for missing date only happens when files are found
100+
else:
101+
# Create set of all dates seen in CSV names.
102+
unique_dates = {datetime.strptime(
103+
daily_filename[0][0:8], '%Y%m%d').date() for daily_filename in daily_filenames}
104+
# Diff expected and observed dates.
105+
expected_dates = self.params.time_window.date_seq
106+
if len(self.params.max_expected_lag) == 0:
107+
max_expected_lag_overall = 10
108+
else:
109+
max_expected_lag_overall = max(self.params.max_expected_lag.values())
110+
111+
# Only check for date if it should definitely be present,
112+
# i.e if it is more than max_expected_lag since the checking date
113+
expected_dates = [date for date in expected_dates if
114+
((datetime.today().date() - date).days) > max_expected_lag_overall]
115+
check_dateholes = list(set(expected_dates).difference(unique_dates))
116+
check_dateholes.sort()
117+
118+
if check_dateholes:
119+
report.add_raised_error(
120+
ValidationFailure("check_missing_date_files",
115121
message="Missing dates are observed; if these dates are already "
116122
"in the API they would not be updated"))
117123

_delphi_utils_python/delphi_utils/validator/validate.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ def validate(self):
5858
frames_list = load_all_files(self.export_dir, self.time_window.start_date,
5959
self.time_window.end_date)
6060
self.static_validation.validate(frames_list, report)
61-
all_frames = aggregate_frames(frames_list)
61+
# Check if frames_list is empty before calling aggregate_frames
62+
if len(frames_list) == 0:
63+
all_frames = []
64+
else:
65+
all_frames = aggregate_frames(frames_list)
6266
self.dynamic_validation.validate(all_frames, report)
6367
return report

_delphi_utils_python/tests/validator/test_static.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,29 @@ def test_empty_filelist(self):
2727
filenames = list()
2828
validator.check_missing_date_files(filenames, report)
2929

30+
assert len(report.raised_errors) == 1
31+
assert report.raised_errors[0].check_name == "check_empty_filelist"
32+
33+
def test_missing_date_files(self):
34+
params = {
35+
"common": {
36+
"data_source": "",
37+
"span_length": 5,
38+
"end_date": "2020-09-05",
39+
"max_expected_lag": {"all": "1"}
40+
}
41+
}
42+
validator = StaticValidator(params)
43+
report = ValidationReport([])
44+
filenames = [("20200901_county_signal_signal.csv", "match_obj"),
45+
("20200903_county_signal_signal.csv", "match_obj"),
46+
("20200904_county_signal_signal.csv", "match_obj"),
47+
("20200905_county_signal_signal.csv", "match_obj")]
48+
validator.check_missing_date_files(filenames, report)
3049
assert len(report.raised_errors) == 1
3150
assert report.raised_errors[0].check_name == "check_missing_date_files"
3251

52+
3353
def test_same_day(self):
3454
params = {
3555
"common": {

0 commit comments

Comments
 (0)