예제 #1
0
    def test_parse_minute_time(self):
        testtuples = (
            ("01:23", None, {"hh": "01", "mm": "23", "tz": None}),
            ("24:00", None, {"hh": "24", "mm": "00", "tz": None}),
            ("01:23.4567", None, {"hh": "01", "mm": "23.4567", "tz": None}),
            ("0123", None, {"hh": "01", "mm": "23", "tz": None}),
            ("2400", None, {"hh": "24", "mm": "00", "tz": None}),
            ("0123.4567", None, {"hh": "01", "mm": "23.4567", "tz": None}),
            (
                "08:13",
                (True, None, "12", "34", "-12:34", "timezone"),
                {
                    "hh": "08",
                    "mm": "13",
                    "tz": (True, None, "12", "34", "-12:34", "timezone"),
                },
            ),
        )

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

            mockBuilder.build_time.return_value = testtuple[2]

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

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
예제 #2
0
    def test_parse_minute_time(self):
        time = _parse_minute_time('01:23')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

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

        time = _parse_minute_time('01:23.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)

        time = _parse_minute_time('0123')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

        time = _parse_minute_time('2400')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)

        time = _parse_minute_time('0123.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)
    def test_parse_minute_time(self):
        time = _parse_minute_time('01:23')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

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

        time = _parse_minute_time('01:23.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)

        time = _parse_minute_time('0123')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

        time = _parse_minute_time('2400')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)

        time = _parse_minute_time('0123.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)
예제 #4
0
    def test_parse_minute_time(self):
        testtuples = (('01:23', None, {
            'hh': '01',
            'mm': '23',
            'tz': None
        }), ('24:00', None, {
            'hh': '24',
            'mm': '00',
            'tz': None
        }), ('01:23.4567', None, {
            'hh': '01',
            'mm': '23.4567',
            'tz': None
        }), ('0123', None, {
            'hh': '01',
            'mm': '23',
            'tz': None
        }), ('2400', None, {
            'hh': '24',
            'mm': '00',
            'tz': None
        }), ('0123.4567', None, {
            'hh': '01',
            'mm': '23.4567',
            'tz': None
        }), ('08:13', (True, None, '12', '34', '-12:34', 'timezone'), {
            'hh': '08',
            'mm': '13',
            'tz': (True, None, '12', '34', '-12:34', 'timezone')
        }))

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

            mockBuilder.build_time.return_value = testtuple[2]

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

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
예제 #5
0
    def test_parse_minute_time(self):
        testtuples = (('01:23', None, {'hh': '01', 'mm': '23', 'tz': None}),
                      ('24:00', None, {'hh': '24', 'mm': '00', 'tz': None}),
                      ('01:23.4567', None, {'hh': '01', 'mm': '23.4567',
                                            'tz': None}),
                      ('0123', None, {'hh': '01', 'mm': '23', 'tz': None}),
                      ('2400', None, {'hh': '24', 'mm': '00', 'tz': None}),
                      ('0123.4567', None, {'hh': '01', 'mm': '23.4567',
                                           'tz': None}),
                      ('08:13', (True, None, '12', '34', '-12:34', 'timezone'),
                       {'hh': '08', 'mm': '13',
                        'tz': (True, None, '12', '34', '-12:34', 'timezone')}))

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

            mockBuilder.build_time.return_value = testtuple[2]

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

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
예제 #6
0
    def test_parse_minute_time(self):
        time = _parse_minute_time('01:23')
        self.assertEqual(time, datetime.time(hour=1, minute=23))

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

        time = _parse_minute_time('01:23.4567')
        self.assertEqual(
            time,
            datetime.time(hour=1, minute=23, second=27, microsecond=402000))

        time = _parse_minute_time('0123')
        self.assertEqual(time, datetime.time(hour=1, minute=23))

        time = _parse_minute_time('2400')
        self.assertEqual(time, datetime.time(hour=0))

        time = _parse_minute_time('0123.4567')
        self.assertEqual(
            time,
            datetime.time(hour=1, minute=23, second=27, microsecond=402000))
예제 #7
0
    def test_parse_minute_time_bounds(self):
        #Minutes cannot be greater than 60
        with self.assertRaises(MinutesOutOfBoundsError):
            _parse_minute_time('0060')

        with self.assertRaises(MinutesOutOfBoundsError):
            _parse_minute_time('0060.1')

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

        with self.assertRaises(MinutesOutOfBoundsError):
            _parse_minute_time('00:60.1')

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

        with self.assertRaises(MidnightBoundsError):
            _parse_minute_time('2400.1')

        with self.assertRaises(MidnightBoundsError):
            _parse_minute_time('24:01')

        with self.assertRaises(MidnightBoundsError):
            _parse_minute_time('24:00.1')
예제 #8
0
    def test_parse_minute_time(self):
        time = _parse_minute_time('01:23')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

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

        time = _parse_minute_time('01:23.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)

        time = _parse_minute_time('0123')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)

        time = _parse_minute_time('2400')
        self.assertEqual(time.hour, 0)
        self.assertEqual(time.minute, 0)

        time = _parse_minute_time('0123.4567')
        self.assertEqual(time.hour, 1)
        self.assertEqual(time.minute, 23)
        self.assertEqual(time.second, 27)
        self.assertEqual(time.microsecond, 402000)

        with self.assertRaises(ValueError):
            _parse_minute_time('0061')

        with self.assertRaises(ValueError):
            _parse_minute_time('0060.1')

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

        with self.assertRaises(ValueError):
            _parse_minute_time('00:60.1')