예제 #1
0
 def testEmptyTimepointsStayEmpty(self):
   self.assertEqual(inferTimezones([], sessionStart),
                    [])
   self.assertEqual(inferTimezones([], sessionStart, sessionEnd),
                    [])
   self.assertEqual(inferTimezones([], sessionStart, sessionEnd.astimezone(utcDST)),
                    [])
예제 #2
0
 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))
예제 #3
0
 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])
예제 #4
0
 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])
예제 #5
0
    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])
예제 #6
0
  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])
예제 #7
0
  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)
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
  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)
예제 #11
0
 def testNoChangeToDST(self):
   timepoints = dateRange(sessionStart, likeDST(sessionEnd), minute)
   with self.assertRaises(TimezonesInferrer.NoIntervalsBigEnoughForTimeAdvance):
     inferTimezones(timepoints, sessionStart, sessionEnd.astimezone(utcDST))
예제 #12
0
 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))
예제 #13
0
 def testEmptyTimepointsStayEmpty(self):
     self.assertEqual(inferTimezones([], sessionStart), [])
     self.assertEqual(inferTimezones([], sessionStart, sessionEnd), [])
     self.assertEqual(
         inferTimezones([], sessionStart, sessionEnd.astimezone(utcDST)),
         [])
예제 #14
0
 def testNoChangeToDST(self):
     timepoints = dateRange(sessionStart, likeDST(sessionEnd), minute)
     with self.assertRaises(
             TimezonesInferrer.NoIntervalsBigEnoughForTimeAdvance):
         inferTimezones(timepoints, sessionStart,
                        sessionEnd.astimezone(utcDST))