diff --git a/tests/test_download.py b/tests/test_download.py index e947ce92..2621d5ba 100644 --- a/tests/test_download.py +++ b/tests/test_download.py @@ -4,7 +4,11 @@ import pandas as pd -from satip.download import _determine_datetimes_to_download_files, download_eumetsat_data +from satip.download import ( + _determine_datetimes_to_download_files, + _get_missing_datetimes_from_list_of_files, + download_eumetsat_data, +) from satip.utils import format_dt_str @@ -49,3 +53,32 @@ def test_determine_datetime_to_download_files(self): self.assertEqual(datetimes[0][1], pd.to_datetime("2020-03-09 11:58:00")) self.assertEqual(datetimes[1][0], pd.to_datetime("2020-03-09 11:59:00")) self.assertEqual(datetimes[1][1], pd.to_datetime("2020-03-10 11:58:00")) + + def test_get_missing_datetimes_from_list_of_files(self): + """Tests padding of datetimes if files present are missing data for given days.""" + # Assume we only have two files present, as something went very wrong + # with the download. + filenames = [ + "MSG3-SEVI-MSG15-0100-NA-20190308114036.810000000Z-NA.nat", + "MSG3-SEVI-MSG15-0100-NA-20220308133711.810000000Z-NA.nat", + ] + + # We then expect the function to pad this by adding missing timeranges + # to fill up everything from the beginning to the first day to the timestamp + # of the first day (case A), then everything between both files (case B) + # and finally fill up the rest until the end of the second day (case C). + expected_timestamps = [ + (pd.to_datetime("2019-03-08 00:00:00"), pd.to_datetime("2019-03-08 11:40:00")), + (pd.to_datetime("2019-03-08 11:40:00"), pd.to_datetime("2022-03-08 13:37:00")), + (pd.to_datetime("2022-03-08 13:37:00"), pd.to_datetime("2022-03-08 23:58:00")), + ] + + # Generate the list of missing datetime interval boundaries: + res = _get_missing_datetimes_from_list_of_files(filenames) + + for i, interval in enumerate(expected_timestamps): + for b, boundary in enumerate(interval): + # Note that the function returns datetime-objects, but we defined the expected + # values as pd-datetime. Though their str-repr is different, they still pass + # the equality-check when compared for same dates. + self.assertEqual(boundary, res[i][b])