def test_day_of_month(self): ts = TimeScale(day_of_month=(1,8,15,22)) start = DTS(2005,3,12) end = DTS(2005,5,3) desired = list(starmap(DTS, ((2005,3,15), (2005,3,22), (2005,4,1), (2005,4,8), (2005,4,15), (2005,4,22), (2005,5,1)))) self.check_ticks(ts.ticks(start,end), desired) # test adjacent months start = DTS(2005, 3, 12) end = DTS(2005, 4, 10) desired = list(starmap(DTS, ((2005,3,15), (2005,3,22), (2005,4,1), (2005,4,8)))) self.check_ticks(ts.ticks(start,end), desired)
def test_hourly(self): ts = TimeScale(hours=1) start = DTS(2005, 3, 15, 10, 30) end = DTS(2005, 3, 15, 16, 59) desired_start = DTS(2005, 3, 15) desired = [desired_start + i*3600 for i in (11, 12, 13, 14, 15, 16)] self.check_ticks(ts.ticks(start, end), desired)
def test_minutes(self): ts = TimeScale(minutes=15) start = DTS(2005, 3, 15, 10, 20) end = DTS(2005, 3, 15, 11, 55) dstart = DTS(2005, 3, 15) desired = ((10, 30), (10, 45), (11, 00), (11, 15), (11, 30), (11, 45)) self.check_ticks(ts.ticks(start, end), sec_from_hms(dstart, *desired))
def test_minutes(self): ts = TimeScale(minutes=15) start = DTS(2005, 3, 15, 10, 20) end = DTS(2005, 3, 15, 11, 55) dstart = DTS(2005, 3, 15) desired = ((10,30), (10,45), (11,00), (11,15), (11,30), (11,45)) self.check_ticks(ts.ticks(start, end), sec_from_hms(dstart, *desired))
def test_month_of_year(self): ts = TimeScale(month_of_year=(1, 4, 8)) start = DTS(2005, 1, 1) end = DTS(2006, 5, 1) desired = list( starmap(DTS, ((2005, 1, 1), (2005, 4, 1), (2005, 8, 1), (2006, 1, 1), (2006, 4, 1)))) self.check_ticks(ts.ticks(start, end), desired)
def test_microsecond(self): # This test is dicey, because the values being tested are close to # machine precision. See the comment in TRangeTestCase.test_microseconds(). ts = TimeScale(microseconds=1) base = DTS(1975, 3, 15, 10, 45, 10) start = base + 2.8e-6 end = base + 9.2e-6 ticks = ts.ticks(start, end) desired = [base+i for i in (3e-6, 4e-6, 5e-6, 6e-6, 7e-6, 8e-6, 9e-6)] print "ticks: ", ticks print "desired: ", desired self.check_ticks(ticks, desired)
def test_month_of_year(self): ts = TimeScale(month_of_year=(1,4,8)) start = DTS(2005,1,1) end = DTS(2006,5,1) desired = list(starmap(DTS, ((2005,1,1), (2005,4,1), (2005,8,1), (2006,1,1), (2006,4,1)))) self.check_ticks(ts.ticks(start,end), desired)