def test_find_time_coverage_not_found(self): """A MetadataNormalizationError must be raised when no time coverage can be extracted """ time_patterns = ((re.compile(r'foo'), None, None), ) with self.assertRaises(errors.MetadataNormalizationError): utils.find_time_coverage(time_patterns, 'bar')
def test_find_time_coverage(self): """find_time_coverage() should extract the time coverage from a URL using the given regexes and functions """ time_patterns = ( (re.compile(rf"dataset_{utils.YEARMONTHDAY_REGEX}.nc$"), utils.create_datetime, lambda time: (time, time + relativedelta(days=1))), (re.compile(rf"dataset_{utils.YEARMONTH_REGEX}.nc$"), utils.create_datetime, lambda time: (time, time + relativedelta(months=1)))) self.assertTupleEqual( utils.find_time_coverage(time_patterns, 'ftp://foo/dataset_20200205.nc'), (datetime(2020, 2, 5, tzinfo=tzutc()), datetime(2020, 2, 6, tzinfo=tzutc()))) self.assertTupleEqual( utils.find_time_coverage(time_patterns, 'ftp://foo/dataset_202002.nc'), (datetime(2020, 2, 1, tzinfo=tzutc()), datetime(2020, 3, 1, tzinfo=tzutc())))
def get_time_coverage_end(self, raw_metadata): return utils.find_time_coverage(self.time_patterns, raw_metadata['url'])[1]