Beispiel #1
0
    def test_parse_second_time(self):
        time = _parse_second_time('01:23:45')
        self.assertEqual(time, datetime.time(hour=1, minute=23, second=45))

        time = _parse_second_time('24:00:00')
        self.assertEqual(time, datetime.time(hour=0))

        time = _parse_second_time('23:21:28.512400')
        self.assertEqual(
            time,
            datetime.time(hour=23, minute=21, second=28, microsecond=512400))

        time = _parse_second_time('14:43:59.9999997')
        self.assertEqual(
            time,
            datetime.time(hour=14, minute=43, second=59, microsecond=999999))

        time = _parse_second_time('012345')
        self.assertEqual(time, datetime.time(hour=1, minute=23, second=45))

        time = _parse_second_time('240000')
        self.assertEqual(time, datetime.time(hour=0))

        time = _parse_second_time('232128.512400')
        self.assertEqual(
            time,
            datetime.time(hour=23, minute=21, second=28, microsecond=512400))

        time = _parse_second_time('144359.9999997')
        self.assertEqual(
            time,
            datetime.time(hour=14, minute=43, second=59, microsecond=999999))
    def test_parse_second_time(self):
        testtuples = (('01:23:45', None, {'hh': '01', 'mm': '23',
                                          'ss': '45', 'tz': None}),
                      ('24:00:00', None, {'hh': '24', 'mm': '00',
                                          'ss': '00', 'tz': None}),
                      ('23:21:28.512400', None, {'hh': '23', 'mm': '21',
                                                 'ss': '28.512400',
                                                 'tz': None}),
                      ('14:43:59.9999997', None, {'hh': '14', 'mm': '43',
                                                  'ss': '59.9999997',
                                                  'tz': None}),
                      ('012345', None, {'hh': '01', 'mm': '23',
                                        'ss': '45', 'tz': None}),
                      ('240000', None, {'hh': '24', 'mm': '00',
                                        'ss': '00', 'tz': None}),
                      ('232128.512400', None, {'hh': '23', 'mm': '21',
                                               'ss': '28.512400', 'tz': None}),
                      ('144359.9999997', None, {'hh': '14', 'mm': '43',
                                                'ss': '59.9999997',
                                                'tz': None}),
                      ('08:22:21',
                       (True, None, '12', '34', '-12:34', 'timezone'),
                       {'hh': '08', 'mm': '22', 'ss': '21',
                        'tz': (True, None, '12', '34', '-12:34', 'timezone')}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()

            mockBuilder.build_time.return_value = testtuple[2]

            result = _parse_second_time(testtuple[0], testtuple[1],
                                        mockBuilder)

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
Beispiel #3
0
    def test_parse_second_time(self):
        testtuples = (('01:23:45', None, {'hh': '01', 'mm': '23',
                                          'ss': '45', 'tz': None}),
                      ('24:00:00', None, {'hh': '24', 'mm': '00',
                                          'ss': '00', 'tz': None}),
                      ('23:21:28.512400', None, {'hh': '23', 'mm': '21',
                                                 'ss': '28.512400',
                                                 'tz': None}),
                      ('14:43:59.9999997', None, {'hh': '14', 'mm': '43',
                                                  'ss': '59.9999997',
                                                  'tz': None}),
                      ('012345', None, {'hh': '01', 'mm': '23',
                                        'ss': '45', 'tz': None}),
                      ('240000', None, {'hh': '24', 'mm': '00',
                                        'ss': '00', 'tz': None}),
                      ('232128.512400', None, {'hh': '23', 'mm': '21',
                                               'ss': '28.512400', 'tz': None}),
                      ('144359.9999997', None, {'hh': '14', 'mm': '43',
                                                'ss': '59.9999997',
                                                'tz': None}),
                      ('08:22:21',
                       (True, None, '12', '34', '-12:34', 'timezone'),
                       {'hh': '08', 'mm': '22', 'ss': '21',
                        'tz': (True, None, '12', '34', '-12:34', 'timezone')}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()

            mockBuilder.build_time.return_value = testtuple[2]

            result = _parse_second_time(testtuple[0], testtuple[1],
                                        mockBuilder)

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
Beispiel #4
0
    def test_parse_second_time(self):
        time = _parse_second_time('01:23:45')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('24:00:00')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('23:21:28.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)

        time = _parse_second_time('012345')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('240000')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('232128.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)
    def test_parse_second_time(self):
        time = _parse_second_time('01:23:45')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('24:00:00')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('23:21:28.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)

        time = _parse_second_time('012345')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('240000')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('232128.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)
    def test_parse_second_time(self):
        testtuples = (
            ("01:23:45", None, {"hh": "01", "mm": "23", "ss": "45", "tz": None}),
            ("24:00:00", None, {"hh": "24", "mm": "00", "ss": "00", "tz": None}),
            (
                "23:21:28.512400",
                None,
                {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None},
            ),
            (
                "14:43:59.9999997",
                None,
                {"hh": "14", "mm": "43", "ss": "59.9999997", "tz": None},
            ),
            ("012345", None, {"hh": "01", "mm": "23", "ss": "45", "tz": None}),
            ("240000", None, {"hh": "24", "mm": "00", "ss": "00", "tz": None}),
            (
                "232128.512400",
                None,
                {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None},
            ),
            (
                "144359.9999997",
                None,
                {"hh": "14", "mm": "43", "ss": "59.9999997", "tz": None},
            ),
            (
                "08:22:21",
                (True, None, "12", "34", "-12:34", "timezone"),
                {
                    "hh": "08",
                    "mm": "22",
                    "ss": "21",
                    "tz": (True, None, "12", "34", "-12:34", "timezone"),
                },
            ),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()

            mockBuilder.build_time.return_value = testtuple[2]

            result = _parse_second_time(testtuple[0], testtuple[1], mockBuilder)

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
Beispiel #7
0
    def test_parse_second_time_bounds(self):
        #Leap seconds not supported
        with self.assertRaises(LeapSecondError):
            _parse_second_time('235960')

        with self.assertRaises(LeapSecondError):
            _parse_second_time('23:59:60')

        #Seconds must be less than 60
        #Leap seconds not supported
        with self.assertRaises(SecondsOutOfBoundsError):
            _parse_second_time('000060')

        with self.assertRaises(SecondsOutOfBoundsError):
            _parse_second_time('00:00:60')

        with self.assertRaises(SecondsOutOfBoundsError):
            _parse_second_time('000061')

        with self.assertRaises(SecondsOutOfBoundsError):
            _parse_second_time('00:00:61')

        #Minutes must be less than 60
        with self.assertRaises(MinutesOutOfBoundsError):
            _parse_second_time('006000')

        with self.assertRaises(MinutesOutOfBoundsError):
            _parse_second_time('00:60:00')

        #Hour 24 can only represent midnight
        with self.assertRaises(MidnightBoundsError):
            _parse_second_time('240001')

        with self.assertRaises(MidnightBoundsError):
            _parse_second_time('24:00:01')

        with self.assertRaises(MidnightBoundsError):
            _parse_second_time('240100')

        with self.assertRaises(MidnightBoundsError):
            _parse_second_time('24:01:00')
Beispiel #8
0
    def test_parse_second_time(self):
        time = _parse_second_time('01:23:45')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('24:00:00')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('23:21:28.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)

        time = _parse_second_time('012345')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 45)

        time = _parse_second_time('240000')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)
        self.assertEqual(time.second, 0)

        time = _parse_second_time('232128.512400')
        self.assertEqual(time.hour, 23)
        self.assertEqual(time.minute, 21)
        self.assertEqual(time.second, 28)
        self.assertEqual(time.microsecond, 512400)

        with self.assertRaises(ValueError):
            _parse_second_time('000060')

        with self.assertRaises(ValueError):
            _parse_second_time('00:00:60')

        with self.assertRaises(ValueError):
            _parse_second_time('006100')

        with self.assertRaises(ValueError):
            _parse_second_time('00:61:00')