@@ -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
0 commit comments