def testEmptyTimepointsStayEmpty(self): self.assertEqual(inferTimezones([], sessionStart), []) self.assertEqual(inferTimezones([], sessionStart, sessionEnd), []) self.assertEqual(inferTimezones([], sessionStart, sessionEnd.astimezone(utcDST)), [])
def testAmbigousChangeToDST(self): timepoints = dateRange(sessionStart + 61 * minute, sessionStart + 65 * minute, minute) +\ dateRange(sessionStart + 126 * minute, sessionStart + 130 * minute, minute) with self.assertRaises( TimezonesInferrer.TooManyIntervalsBigEnoughForTimeAdvance): inferTimezones(timepoints, sessionStart, sessionEnd.astimezone(utcDST))
def testInOpenSessionTimepointsGetSameTimezoneAsStart(self): self.assertEqual(inferTimezones([[2015, 7, 4, 17, 45, 15, 0]], sessionStart, None), [utc]) self.assertEqual(inferTimezones([[2015, 7, 4, 17, 45, 15, 0], [2015, 7, 4, 17, 56, 43, 1]], sessionStart, None), [utc, utc])
def testInOpenSessionTimepointsGetSameTimezoneAsStart(self): self.assertEqual( inferTimezones([[2015, 7, 4, 17, 45, 15, 0]], sessionStart, None), [utc]) self.assertEqual( inferTimezones( [[2015, 7, 4, 17, 45, 15, 0], [2015, 7, 4, 17, 56, 43, 1]], sessionStart, None), [utc, utc])
def testInSessionTimepointsGetSameTimezoneAsBothStartAndEnd(self): self.assertEqual( inferTimezones([[2015, 7, 4, 17, 45, 15, 0]], sessionStart, sessionEnd), [utc]) self.assertEqual( inferTimezones( [[2015, 7, 4, 17, 45, 15, 0], [2015, 7, 4, 17, 56, 43, 1]], sessionStart, sessionEnd), [utc, utc])
def testInSessionTimepointsGetSameTimezoneAsBothStartAndEnd(self): self.assertEqual(inferTimezones([[2015, 7, 4, 17, 45, 15, 0]], sessionStart, sessionEnd), [utc]) self.assertEqual(inferTimezones([[2015, 7, 4, 17, 45, 15, 0], [2015, 7, 4, 17, 56, 43, 1]], sessionStart, sessionEnd), [utc, utc])
def testDetectionOfChangeToDST(self): timepointsUTC, timezonesUTC = makeTestCases(sessionStart, timeChange, minute) timepointsDST, timezonesDST = makeTestCases(timeChange.astimezone(utcDST), sessionEnd.astimezone(utcDST), minute) inferred = inferTimezones(timepointsUTC + timepointsDST, sessionStart, sessionEnd.astimezone(utcDST)) self.assertEqual(inferred, timezonesUTC + timezonesDST) self.assertEqual(inferTimezones(timepointsUTC, sessionStart, sessionEnd.astimezone(utcDST)), timezonesUTC) self.assertEqual(inferTimezones(timepointsDST, sessionStart, sessionEnd.astimezone(utcDST)), timezonesDST)
def testAmbigousChangeFromDST(self): with self.assertRaises(TimezonesInferrer.AmbigousTimezoneChangeError): timepoints = dateRange(likeDST(sessionStart), sessionEnd, minute) inferTimezones(timepoints, sessionStart.astimezone(utcDST), sessionEnd) with self.assertRaises(TimezonesInferrer.AmbigousTimezoneChangeError): timepoints = dateRange(sessionStart - 121 * minute, sessionEnd, minute) inferTimezones(timepoints, sessionStart.astimezone(utcDST), sessionEnd) with self.assertRaises(TimezonesInferrer.AmbigousTimezoneChangeError): timepoints = dateRange(likeDST(sessionStart), sessionEnd + 120 * minute, minute) inferTimezones(timepoints, sessionStart.astimezone(utcDST), sessionEnd) with self.assertRaises(TimezonesInferrer.AmbigousTimezoneChangeError): start = likeDST(sessionStart) timepoints = dateRange(start, start + 90*minute, minute) +\ dateRange(start + 40*minute, start + 110*minute, minute) +\ dateRange(start + 60*minute, sessionEnd, minute) inferTimezones(timepoints, sessionStart.astimezone(utcDST), sessionEnd)
def testDetectionOfChangeToDST(self): timepointsUTC, timezonesUTC = makeTestCases(sessionStart, timeChange, minute) timepointsDST, timezonesDST = makeTestCases( timeChange.astimezone(utcDST), sessionEnd.astimezone(utcDST), minute) inferred = inferTimezones(timepointsUTC + timepointsDST, sessionStart, sessionEnd.astimezone(utcDST)) self.assertEqual(inferred, timezonesUTC + timezonesDST) self.assertEqual( inferTimezones(timepointsUTC, sessionStart, sessionEnd.astimezone(utcDST)), timezonesUTC) self.assertEqual( inferTimezones(timepointsDST, sessionStart, sessionEnd.astimezone(utcDST)), timezonesDST)
def testNoChangeToDST(self): timepoints = dateRange(sessionStart, likeDST(sessionEnd), minute) with self.assertRaises(TimezonesInferrer.NoIntervalsBigEnoughForTimeAdvance): inferTimezones(timepoints, sessionStart, sessionEnd.astimezone(utcDST))
def testAmbigousChangeToDST(self): timepoints = dateRange(sessionStart + 61 * minute, sessionStart + 65 * minute, minute) +\ dateRange(sessionStart + 126 * minute, sessionStart + 130 * minute, minute) with self.assertRaises(TimezonesInferrer.TooManyIntervalsBigEnoughForTimeAdvance): inferTimezones(timepoints, sessionStart, sessionEnd.astimezone(utcDST))
def testEmptyTimepointsStayEmpty(self): self.assertEqual(inferTimezones([], sessionStart), []) self.assertEqual(inferTimezones([], sessionStart, sessionEnd), []) self.assertEqual( inferTimezones([], sessionStart, sessionEnd.astimezone(utcDST)), [])
def testNoChangeToDST(self): timepoints = dateRange(sessionStart, likeDST(sessionEnd), minute) with self.assertRaises( TimezonesInferrer.NoIntervalsBigEnoughForTimeAdvance): inferTimezones(timepoints, sessionStart, sessionEnd.astimezone(utcDST))