def test_today_datetime(self): frequency = Frequency(4, Frequency.UNIT.HOUR, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.DATETIME) self.assertEqual(type(frequency.today()), type(datetime.datetime.today()))
def test_count_dates(self): frequency = Frequency(1, Frequency.UNIT.MONTH, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.MONTHDAY) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 12, 31) self.assertEqual(frequency.count_dates(from_date, to_date), 12)
def test_get_internet_dates(self): frequency = Frequency(1, Frequency.UNIT.MONTH, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.MONTHDAY) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 12, 31) dates = frequency.get_dates(from_date, to_date) templates = frequency.get_internet_dates( dates, "/Modis_%Y%m/mcd14dl.%Y-%m-%d.tif") self.assertEqual(templates[0], '/Modis_201401/mcd14dl.2014-01-01.tif')
def test_find_gap_dekad_intervals_with_gap(self): frequency = Frequency(value=1, unit=Frequency.UNIT.DEKAD, frequency_type=Frequency.TYPE.EVERY) intervals = find_gaps(self.files_dekad[:10] + self.files_dekad[14:], frequency=frequency, only_intervals=True) self.assertEqual(len(intervals), 3) self.assertEqual(intervals[0][2], INTERVAL_TYPE.PRESENT) self.assertEqual(intervals[1][0], frequency.extract_date(self.files_dekad[10])) self.assertEqual(intervals[1][1], frequency.extract_date(self.files_dekad[13])) self.assertEqual(intervals[2][2], INTERVAL_TYPE.PRESENT)
def test_get_internet_dates_add_days(self): #%{+/-<Nt><strftime>} = +/- N delta days/hours/ frequency = Frequency(1, Frequency.UNIT.DAY, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.DATE) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 1, 31) dates = frequency.get_dates(from_date, to_date) templates = frequency.get_internet_dates( dates, "/Modis_%{+8dY-m-d}_%Y%m/mcd14dl.%Y-%m-%d.tif") self.assertEqual(templates[0], '/Modis_2014-01-09_201401/mcd14dl.2014-01-01.tif') self.assertEqual(templates[1], '/Modis_2014-01-10_201401/mcd14dl.2014-01-02.tif')
def test_get_internet_dates_dekad(self): #%{dkm} frequency = Frequency(1, Frequency.UNIT.DEKAD, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.DATE) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 12, 31) dates = frequency.get_dates(from_date, to_date) templates = frequency.get_internet_dates( dates, "/Modis_%{dkm}_%Y%m%d/mcd14dl.%Y-%m-%d.tif") self.assertEqual(templates[0], '/Modis_1_20140101/mcd14dl.2014-01-01.tif') self.assertEqual(templates[1], '/Modis_2_20140111/mcd14dl.2014-01-11.tif')
def test_find_gap_minutes(self): self.assertEqual([], find_gaps(self.files_15minutes, frequency=Frequency( value=4, unit=Frequency.UNIT.HOUR, frequency_type=Frequency.TYPE.PER)))
def test_find_gap_day(self): gap = find_gaps(self.files_day_gap, frequency=Frequency( value=1, unit=Frequency.UNIT.DAY, frequency_type=Frequency.TYPE.EVERY)) self.assertEqual(len(gap), 19)
def test_find_gap_months_per(self): self.assertEqual([], find_gaps(self.files_months, frequency=Frequency( value=1, unit=Frequency.UNIT.MONTH, frequency_type=Frequency.TYPE.PER)))
def test_find_gap_day_no_gap(self): self.assertEqual([], find_gaps(self.files_day, frequency=Frequency( value=1, unit=Frequency.UNIT.DAY, frequency_type=Frequency.TYPE.EVERY)))
def test_find_gap_day_to(self): gap = find_gaps(self.files_day, frequency=Frequency( value=1, unit=Frequency.UNIT.DAY, frequency_type=Frequency.TYPE.EVERY), to_date=self.to_date) self.assertEqual(len(gap), 3)
def test_find_gap_dekad_with_gap_per(self): gap = find_gaps(self.files_dekad[:10] + self.files_dekad[12:], frequency=Frequency(value=1, unit=Frequency.UNIT.DEKAD, frequency_type=Frequency.TYPE.PER)) self.assertEqual(len(gap), 2) self.assertEqual(gap[0], self.files_dekad[10]) self.assertEqual(gap[1], self.files_dekad[11])
def test_find_gap_minutes_with_gap(self): gap = find_gaps(self.files_15minutes[:3] + self.files_15minutes[5:], frequency=Frequency(value=4, unit=Frequency.UNIT.HOUR, frequency_type=Frequency.TYPE.PER)) self.assertEqual(len(gap), 2) self.assertEqual(gap[0], self.files_15minutes[3]) self.assertEqual(gap[1], self.files_15minutes[4])
def test_find_gap_dekad_no_gap_per(self): self.assertEqual([], find_gaps(self.files_dekad, frequency=Frequency( dateformat='YYYYMMDD', value=1, unit=Frequency.UNIT.DEKAD, frequency_type=Frequency.TYPE.PER)))
def test_wrong_date(self): frequency = Frequency(4, Frequency.UNIT.HOUR, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.MONTHDAY) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 12, 31) self.assertRaises(Exception, frequency.get_dates, *(to_date, from_date))
def test_find_gap_dekad_intervals_no_gap(self): intervals = find_gaps(self.files_dekad, frequency=Frequency( dateformat='YYYYMMDD', value=1, unit=Frequency.UNIT.DEKAD, frequency_type=Frequency.TYPE.EVERY), only_intervals=True) self.assertEqual(len(intervals), 1) self.assertEqual(intervals[0][2], INTERVAL_TYPE.PRESENT)
def test_get_internet_dates_cgl_dekad(self): #%{dkm} frequency = Frequency(1, Frequency.UNIT.CGL_DEKAD, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.DATE) from_date = datetime.date(2014, 1, 1) to_date = datetime.date(2014, 12, 31) dates = frequency.get_dates(from_date, to_date) templates = frequency.get_internet_dates( dates, "/%Y/%m/%d/DMP-RT6_%Y%m%d0000_GLOBE_PROBAV_V2.0/c_gls_DMP-RT6_%Y%m%d0000_GLOBE_PROBAV_V2.0.1.nc" ) self.assertEqual( templates[0], '/2014/01/10/DMP-RT6_201401100000_GLOBE_PROBAV_V2.0/c_gls_DMP-RT6_201401100000_GLOBE_PROBAV_V2.0.1.nc' ) self.assertEqual( templates[1], '/2014/01/20/DMP-RT6_201401200000_GLOBE_PROBAV_V2.0/c_gls_DMP-RT6_201401200000_GLOBE_PROBAV_V2.0.1.nc' )
def test_find_gap_wrong_parameters(self): self.assertRaises( WrongDateParameter, find_gaps, *( [], Frequency(value=1, unit=Frequency.UNIT.DAY, frequency_type=Frequency.TYPE.EVERY), ), **{ 'to_date': datetime.datetime(2014, 10, 10), 'from_date': datetime.datetime(2014, 1, 1) })
def test_find_gap_intervals_day(self): frequency = Frequency(value=1, unit=Frequency.UNIT.DAY, frequency_type=Frequency.TYPE.EVERY) intervals = find_gaps(self.files_day_gap, frequency=frequency, only_intervals=True) self.assertEqual(len(intervals), 5) self.assertEqual(intervals[0][2], INTERVAL_TYPE.PRESENT) self.assertEqual(intervals[0][0], frequency.extract_date(self.files_day_gap[0])) self.assertEqual(intervals[0][1], frequency.extract_date(self.files_day_gap[0])) self.assertEqual(intervals[1][2], INTERVAL_TYPE.MISSING) self.assertEqual(intervals[2][2], INTERVAL_TYPE.PRESENT) self.assertEqual(intervals[3][2], INTERVAL_TYPE.MISSING) self.assertEqual(intervals[4][2], INTERVAL_TYPE.PRESENT) self.assertEqual(intervals[4][0], frequency.extract_date(self.files_day_gap[-1])) self.assertEqual(intervals[4][1], frequency.extract_date(self.files_day_gap[-1]))
def test_frequency_8days(self): freq8 = Frequency(1, '8days', 'e', dateformat=None) print(freq8.today()) print(freq8.get_next_date(freq8.today(), '8days', 1)) self.assertEqual(freq8.dateformat, 'YYYYMMDD')
def test_class(self): self.assertIsInstance( Frequency(1, Frequency.UNIT.DEKAD, Frequency.TYPE.PER), Frequency)
def test_dataformat_default_1(self): frequency = Frequency(1, Frequency.UNIT.DEKAD, Frequency.TYPE.PER) self.assertEqual(frequency.dateformat, Frequency.DATEFORMAT.DATE)
def test_dataformat_default_2(self): frequency = Frequency(4, Frequency.UNIT.HOUR, Frequency.TYPE.PER) self.assertEqual(frequency.dateformat, Frequency.DATEFORMAT.DATETIME)
def test_dataformat_default_3(self): frequency = Frequency(9, Frequency.UNIT.YEAR, Frequency.TYPE.EVERY) self.assertEqual(frequency.dateformat, Frequency.DATEFORMAT.DATE)
def test_today_monthday(self): frequency = Frequency(4, Frequency.UNIT.HOUR, Frequency.TYPE.PER, dateformat=Frequency.DATEFORMAT.MONTHDAY) self.assertEqual(type(frequency.today()), type(datetime.date.today()))