def test_parse_duration_prescribed_notime(self):
        testtuples = (
            ("P1Y2M3D", {"PnY": "1", "PnM": "2", "PnW": None, "PnD": "3"}),
            ("P1Y2M3.5D", {"PnY": "1", "PnM": "2", "PnW": None, "PnD": "3.5"}),
            ("P1Y2M3,5D", {"PnY": "1", "PnM": "2", "PnW": None, "PnD": "3.5"}),
            ("P1Y", {"PnY": "1", "PnM": None, "PnW": None, "PnD": None}),
            ("P1.5Y", {"PnY": "1.5", "PnM": None, "PnW": None, "PnD": None}),
            ("P1,5Y", {"PnY": "1.5", "PnM": None, "PnW": None, "PnD": None}),
            ("P1M", {"PnY": None, "PnM": "1", "PnW": None, "PnD": None}),
            ("P1.5M", {"PnY": None, "PnM": "1.5", "PnW": None, "PnD": None}),
            ("P1,5M", {"PnY": None, "PnM": "1.5", "PnW": None, "PnD": None}),
            ("P1W", {"PnY": None, "PnM": None, "PnW": "1", "PnD": None}),
            ("P1.5W", {"PnY": None, "PnM": None, "PnW": "1.5", "PnD": None}),
            ("P1,5W", {"PnY": None, "PnM": None, "PnW": "1.5", "PnD": None}),
            ("P1D", {"PnY": None, "PnM": None, "PnW": None, "PnD": "1"}),
            ("P1.5D", {"PnY": None, "PnM": None, "PnW": None, "PnD": "1.5"}),
            ("P1,5D", {"PnY": None, "PnM": None, "PnW": None, "PnD": "1.5"}),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_duration.return_value = testtuple[1]

            result = _parse_duration_prescribed_notime(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
Exemplo n.º 2
0
    def test_parse_duration_combined(self):
        testtuples = (('P0003-06-04T12:30:05', {'PnY': '0003', 'PnM': '06',
                                                'PnD': '04', 'TnH': '12',
                                                'TnM': '30', 'TnS': '05'}),
                      ('P0003-06-04T12:30:05,5', {'PnY': '0003', 'PnM': '06',
                                                  'PnD': '04', 'TnH': '12',
                                                  'TnM': '30', 'TnS': '05.5'}),
                      ('P0003-06-04T12:30:05.5', {'PnY': '0003', 'PnM': '06',
                                                  'PnD': '04', 'TnH': '12',
                                                  'TnM': '30', 'TnS': '05.5'}),
                      ('P0001-02-03T14:43:59.9999997', {'PnY': '0001',
                                                        'PnM': '02',
                                                        'PnD': '03',
                                                        'TnH': '14',
                                                        'TnM': '43',
                                                        'TnS':
                                                        '59.9999997'}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_duration.return_value = testtuple[1]

            result = _parse_duration_combined(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
Exemplo n.º 3
0
    def test_parse_hour(self):
        testtuples = (('01', None, {
            'hh': '01',
            'tz': None
        }), ('24', None, {
            'tz': None
        }), ('01.4567', None, {
            'hh': '01.4567',
            'tz': None
        }), ('12.5', None, {
            'hh': '12.5',
            'tz': None
        }), ('08', (True, None, '12', '34', '-12:34', 'timezone'), {
            'hh': '08',
            'tz': (True, None, '12', '34', '-12:34', 'timezone')
        }))

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

            mockBuilder.build_time.return_value = testtuple[2]

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

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
Exemplo n.º 4
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])
Exemplo n.º 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])
Exemplo n.º 6
0
    def test_parse_week(self):
        testtuples = (('2004-W53', {
            'YYYY': '2004',
            'Www': '53'
        }), ('2009-W01', {
            'YYYY': '2009',
            'Www': '01'
        }), ('2009-W53', {
            'YYYY': '2009',
            'Www': '53'
        }), ('2010-W01', {
            'YYYY': '2010',
            'Www': '01'
        }), ('2004W53', {
            'YYYY': '2004',
            'Www': '53'
        }), ('2009W01', {
            'YYYY': '2009',
            'Www': '01'
        }), ('2009W53', {
            'YYYY': '2009',
            'Www': '53'
        }), ('2010W01', {
            'YYYY': '2010',
            'Www': '01'
        }))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_week(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 7
0
    def test_parse_interval_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {'end': (('1981', '04', '05', None, None, None, 'date'),
                                ('01', '01', '00', None, 'time'), 'datetime'),
                        'duration':(None, '1', None, None, None, None, None,
                                    'duration')}

        mockBuilder.build_interval.return_value = expectedargs

        result = parse_interval('P1M/1981-04-05T01:01:00', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_interval.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {'start': ('2014', '11', '12', None, None, None,
                                  'date'),
                        'duration': (None, None, None, None, '1', None, None,
                                     'duration')}

        mockBuilder.build_interval.return_value = expectedargs

        result = parse_interval('2014-11-12/PT1H', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_interval.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {'start': (('1980', '03', '05', None, None, None,
                                   'date'),
                                  ('01', '01', '00', None, 'time'),
                                  'datetime'),
                        'end': (('1981', '04', '05', None, None, None,
                                 'date'),
                                ('01', '01', '00', None, 'time'),
                                'datetime')}

        mockBuilder.build_interval.return_value = expectedargs

        result = parse_interval('1980-03-05T01:01:00/1981-04-05T01:01:00',
                       builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_interval.assert_called_once_with(**expectedargs)
Exemplo n.º 8
0
    def test_parse_duration_combined(self):
        testtuples = (
            (
                "P0003-06-04T12:30:05",
                {
                    "PnY": "0003",
                    "PnM": "06",
                    "PnD": "04",
                    "TnH": "12",
                    "TnM": "30",
                    "TnS": "05",
                },
            ),
            (
                "P0003-06-04T12:30:05,5",
                {
                    "PnY": "0003",
                    "PnM": "06",
                    "PnD": "04",
                    "TnH": "12",
                    "TnM": "30",
                    "TnS": "05.5",
                },
            ),
            (
                "P0003-06-04T12:30:05.5",
                {
                    "PnY": "0003",
                    "PnM": "06",
                    "PnD": "04",
                    "TnH": "12",
                    "TnM": "30",
                    "TnS": "05.5",
                },
            ),
            (
                "P0001-02-03T14:43:59.9999997",
                {
                    "PnY": "0001",
                    "PnM": "02",
                    "PnD": "03",
                    "TnH": "14",
                    "TnM": "43",
                    "TnS": "59.9999997",
                },
            ),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_duration.return_value = testtuple[1]

            result = _parse_duration_combined(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
Exemplo n.º 9
0
    def test_parse_time_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {"hh": "01", "mm": "23", "ss": "45", "tz": None}

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time("01:23:45", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            "hh": "23",
            "mm": "21",
            "ss": "28.512400",
            "tz": (False, None, "00", "00", "+00:00", "timezone"),
        }

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time("232128.512400+00:00", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            "hh": "23",
            "mm": "21",
            "ss": "28.512400",
            "tz": (False, None, "11", "15", "+11:15", "timezone"),
        }

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time("23:21:28.512400+11:15", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)
Exemplo n.º 10
0
    def test_parse_time_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {'hh': '01', 'mm': '23', 'ss': '45', 'tz': None}

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time('01:23:45', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            'hh': '23',
            'mm': '21',
            'ss': '28.512400',
            'tz': (False, None, '00', '00', '+00:00', 'timezone')
        }

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time('232128.512400+00:00', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            'hh': '23',
            'mm': '21',
            'ss': '28.512400',
            'tz': (False, None, '11', '15', '+11:15', 'timezone')
        }

        mockBuilder.build_time.return_value = expectedargs

        result = parse_time('23:21:28.512400+11:15', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_time.assert_called_once_with(**expectedargs)
Exemplo n.º 11
0
    def test_parse_timezone_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {"negative": False, "Z": True, "name": "Z"}

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone("Z", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            "negative": False,
            "hh": "00",
            "mm": "00",
            "name": "+00:00"
        }

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone("+00:00", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            "negative": True,
            "hh": "01",
            "mm": "23",
            "name": "-01:23"
        }

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone("-01:23", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)
Exemplo n.º 12
0
    def test_parse_timezone_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {'negative': False, 'Z': True, 'name': 'Z'}

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone('Z', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            'negative': False,
            'hh': '00',
            'mm': '00',
            'name': '+00:00'
        }

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone('+00:00', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)

        mockBuilder = mock.Mock()

        expectedargs = {
            'negative': True,
            'hh': '01',
            'mm': '23',
            'name': '-01:23'
        }

        mockBuilder.build_timezone.return_value = expectedargs

        result = parse_timezone('-01:23', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_timezone.assert_called_once_with(**expectedargs)
Exemplo n.º 13
0
    def test_parse_date_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {"YYYY": "1981", "MM": "04", "DD": "05"}

        mockBuilder.build_date.return_value = expectedargs

        result = parse_date("1981-04-05", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_date.assert_called_once_with(**expectedargs)
Exemplo n.º 14
0
    def test_parse_date_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {'YYYY': '1981', 'MM': '04', 'DD': '05'}

        mockBuilder.build_date.return_value = expectedargs

        result = parse_date('1981-04-05', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_date.assert_called_once_with(**expectedargs)
Exemplo n.º 15
0
    def test_parse_calendar_month(self):
        testtuples = (('1981-04', {'YYYY': '1981', 'MM': '04'}), )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_calendar_month(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 16
0
    def test_parse_calendar_month(self):
        testtuples = (("1981-04", {"YYYY": "1981", "MM": "04"}),)

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_calendar_month(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 17
0
    def test_parse_duration_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {'PnY': '1', 'PnM': '2', 'PnD': '3',
                        'TnH': '4', 'TnM': '54', 'TnS': '6'}

        mockBuilder.build_duration.return_value = expectedargs

        result = parse_duration('P1Y2M3DT4H54M6S', builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_duration.assert_called_once_with(**expectedargs)
Exemplo n.º 18
0
    def test_parse_duration_prescribed(self):
        testtuples = (('P1Y2M3DT4H54M6S', {'PnY': '1', 'PnM': '2',
                                           'PnD': '3', 'TnH': '4',
                                           'TnM': '54', 'TnS': '6'}),
                      ('P1Y2M3DT4H54M6.5S', {'PnY': '1', 'PnM': '2',
                                             'PnD': '3', 'TnH': '4',
                                             'TnM': '54', 'TnS': '6.5'}),
                      ('P1Y2M3DT4H54M6,5S', {'PnY': '1', 'PnM': '2',
                                             'PnD': '3', 'TnH': '4',
                                             'TnM': '54', 'TnS': '6.5'}),
                      ('PT4H54M6.5S', {'PnY': None, 'PnM': None, 'PnD': None,
                                       'TnH': '4', 'TnM': '54', 'TnS': '6.5'}),
                      ('PT4H54M6,5S', {'PnY': None, 'PnM': None, 'PnD': None,
                                       'TnH': '4', 'TnM': '54', 'TnS': '6.5'}),
                      ('P1Y2M3D', {'PnY': '1', 'PnM': '2',
                                   'PnW': None, 'PnD': '3'}),
                      ('P1Y2M3.5D', {'PnY': '1', 'PnM': '2',
                                     'PnW': None, 'PnD': '3.5'}),
                      ('P1Y2M3,5D', {'PnY': '1', 'PnM': '2',
                                     'PnW': None, 'PnD': '3.5'}),
                      ('P1Y', {'PnY': '1', 'PnM': None,
                               'PnW': None, 'PnD': None}),
                      ('P1.5Y', {'PnY': '1.5', 'PnM': None, 'PnW': None,
                                 'PnD': None}),
                      ('P1,5Y', {'PnY': '1.5', 'PnM': None, 'PnW': None,
                                 'PnD': None}),
                      ('P1M', {'PnY': None, 'PnM': '1', 'PnW': None,
                               'PnD': None}),
                      ('P1.5M', {'PnY': None, 'PnM': '1.5', 'PnW': None,
                                 'PnD': None}),
                      ('P1,5M', {'PnY': None, 'PnM': '1.5', 'PnW': None,
                                 'PnD': None}),
                      ('P1W', {'PnY': None, 'PnM': None, 'PnW': '1',
                               'PnD': None}),
                      ('P1.5W', {'PnY': None, 'PnM': None, 'PnW': '1.5',
                                 'PnD': None}),
                      ('P1,5W', {'PnY': None, 'PnM': None, 'PnW': '1.5',
                                 'PnD': None}),
                      ('P1D', {'PnY': None, 'PnM': None, 'PnW': None,
                               'PnD': '1'}),
                      ('P1.5D', {'PnY': None, 'PnM': None, 'PnW': None,
                                 'PnD': '1.5'}),
                      ('P1,5D', {'PnY': None, 'PnM': None, 'PnW': None,
                                 'PnD': '1.5'}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_duration.return_value = testtuple[1]

            result = _parse_duration_prescribed(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
    def test_parse_ordinal_date(self):
        testtuples = (('1981-095', {'YYYY': '1981', 'DDD': '095'}),
                      ('1981095', {'YYYY': '1981', 'DDD': '095'}),
                      ('1981365', {'YYYY': '1981', 'DDD': '365'}),
                      ('1980366', {'YYYY': '1980', 'DDD': '366'}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_ordinal_date(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
    def test_parse_year(self):
        testtuples = (('2013', {'YYYY': '2013'}),
                      ('0001', {'YYYY': '0001'}),
                      ('1', {'YYYY': '1'}),
                      ('19', {'YYYY': '19'}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_year(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 21
0
    def test_parse_datetime_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = (('1981', None, None, None, None, '095', 'date'),
                        ('23', '21', '28.512400', (True, None, '12', '34',
                                                   '-12:34', 'timezone'),
                         'time'))

        mockBuilder.build_datetime.return_value = expectedargs

        result = parse_datetime('1981095T23:21:28.512400-12:34',
                                builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_datetime.assert_called_once_with(*expectedargs)
Exemplo n.º 22
0
    def test_parse_year(self):
        testtuples = (
            ("2013", {"YYYY": "2013"}),
            ("0001", {"YYYY": "0001"}),
            ("1", {"YYYY": "1"}),
            ("19", {"YYYY": "19"}),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_year(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 23
0
    def test_parse_ordinal_date(self):
        testtuples = (
            ("1981-095", {"YYYY": "1981", "DDD": "095"}),
            ("1981095", {"YYYY": "1981", "DDD": "095"}),
            ("1981365", {"YYYY": "1981", "DDD": "365"}),
            ("1980366", {"YYYY": "1980", "DDD": "366"}),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_ordinal_date(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 24
0
    def test_parse_datetime_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = (
            DateTuple("1981", None, None, None, None, "095"),
            TimeTuple(
                "23", "21", "28.512400", TimezoneTuple(True, None, "12", "34", "-12:34")
            ),
        )

        mockBuilder.build_datetime.return_value = expectedargs

        result = parse_datetime("1981095T23:21:28.512400-12:34", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_datetime.assert_called_once_with(*expectedargs)
Exemplo n.º 25
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])
    def test_parse_duration_mockbuilder(self):
        mockBuilder = mock.Mock()

        expectedargs = {
            "PnY": "1",
            "PnM": "2",
            "PnD": "3",
            "TnH": "4",
            "TnM": "54",
            "TnS": "6",
        }

        mockBuilder.build_duration.return_value = expectedargs

        result = parse_duration("P1Y2M3DT4H54M6S", builder=mockBuilder)

        self.assertEqual(result, expectedargs)
        mockBuilder.build_duration.assert_called_once_with(**expectedargs)
Exemplo n.º 27
0
    def test_parse_week(self):
        testtuples = (
            ("2004-W53", {"YYYY": "2004", "Www": "53"}),
            ("2009-W01", {"YYYY": "2009", "Www": "01"}),
            ("2009-W53", {"YYYY": "2009", "Www": "53"}),
            ("2010-W01", {"YYYY": "2010", "Www": "01"}),
            ("2004W53", {"YYYY": "2004", "Www": "53"}),
            ("2009W01", {"YYYY": "2009", "Www": "01"}),
            ("2009W53", {"YYYY": "2009", "Www": "53"}),
            ("2010W01", {"YYYY": "2010", "Www": "01"}),
        )

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_date.return_value = testtuple[1]

            result = _parse_week(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_date.assert_called_once_with(**testtuple[1])
Exemplo n.º 28
0
    def test_parse_hour(self):
        testtuples = (
            ("01", None, {"hh": "01", "tz": None}),
            ("24", None, {"tz": None}),
            ("01.4567", None, {"hh": "01.4567", "tz": None}),
            ("12.5", None, {"hh": "12.5", "tz": None}),
            (
                "08",
                (True, None, "12", "34", "-12:34", "timezone"),
                {"hh": "08", "tz": (True, None, "12", "34", "-12:34", "timezone")},
            ),
        )

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

            mockBuilder.build_time.return_value = testtuple[2]

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

            self.assertEqual(result, testtuple[2])
            mockBuilder.build_time.assert_called_once_with(**testtuple[2])
Exemplo n.º 29
0
    def test_parse_interval_internal(self):
        #Test the internal _parse_interval function
        testtuples = (('P1M/1981-04-05T01:01:00',
                       {'end': (('1981', '04', '05', None, None, None, 'date'),
                                ('01', '01', '00', None, 'time'), 'datetime'),
                        'duration': (None, '1', None, None, None, None, None,
                                     'duration')}),
                      ('P1M/1981-04-05',
                       {'end': ('1981', '04', '05', None, None, None, 'date'),
                        'duration': (None, '1', None, None, None, None, None,
                                     'duration')}),
                      ('P1,5Y/2018-03-06',
                       {'end': ('2018', '03', '06', None, None, None, 'date'),
                        'duration': ('1.5', None, None, None, None, None, None,
                                     'duration')}),
                      ('P1.5Y/2018-03-06',
                       {'end': ('2018', '03', '06', None, None, None, 'date'),
                        'duration': ('1.5', None, None, None, None, None, None,
                                     'duration')}),
                      ('PT1H/2014-11-12',
                       {'end': ('2014', '11', '12', None, None, None, 'date'),
                        'duration': (None, None, None, None, '1', None, None,
                                     'duration')}),
                      ('PT4H54M6.5S/2014-11-12',
                       {'end': ('2014', '11', '12', None, None, None, 'date'),
                        'duration': (None, None, None, None, '4', '54', '6.5',
                                     'duration')}),
                      #Make sure we truncate, not round
                      #https://bitbucket.org/nielsenb/aniso8601/issues/10/sub-microsecond-precision-in-durations-is
                      ('PT0.0000001S/2018-03-06',
                       {'end': ('2018', '03', '06', None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, None, None,
                                     '0.0000001', 'duration')}),
                      ('PT2.0000048S/2018-03-06',
                       {'end': ('2018', '03', '06', None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, None, None,
                                     '2.0000048', 'duration')}),
                      ('1981-04-05T01:01:00/P1M1DT1M',
                       {'start': (('1981', '04', '05',
                                   None, None, None, 'date'),
                                  ('01', '01', '00', None, 'time'),
                                  'datetime'),
                        'duration': (None, '1', None,
                                     '1', None, '1', None, 'duration')}),
                      ('1981-04-05/P1M1D',
                       {'start': ('1981', '04', '05',
                                  None, None, None, 'date'),
                        'duration': (None, '1', None,
                                     '1', None, None, None, 'duration')}),
                      ('2018-03-06/P2,5M',
                       {'start': ('2018', '03', '06',
                                  None, None, None, 'date'),
                        'duration': (None, '2.5', None,
                                     None, None, None, None, 'duration')}),
                      ('2018-03-06/P2.5M',
                       {'start': ('2018', '03', '06',
                                  None, None, None, 'date'),
                        'duration': (None, '2.5', None,
                                     None, None, None, None, 'duration')}),
                      ('2014-11-12/PT1H',
                       {'start': ('2014', '11', '12',
                                  None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, '1', None, None, 'duration')}),
                      ('2014-11-12/PT4H54M6.5S',
                       {'start': ('2014', '11', '12',
                                  None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, '4', '54', '6.5', 'duration')}),
                      #Make sure we truncate, not round
                      #https://bitbucket.org/nielsenb/aniso8601/issues/10/sub-microsecond-precision-in-durations-is
                      ('2018-03-06/PT0.0000001S',
                       {'start': ('2018', '03', '06',
                                  None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, None, None,
                                     '0.0000001', 'duration')}),
                      ('2018-03-06/PT2.0000048S',
                       {'start': ('2018', '03', '06',
                                  None, None, None, 'date'),
                        'duration': (None, None, None,
                                     None, None, None,
                                     '2.0000048', 'duration')}),
                      ('1980-03-05T01:01:00/1981-04-05T01:01:00',
                       {'start': (('1980', '03', '05',
                                   None, None, None, 'date'),
                                  ('01', '01', '00',
                                   None, 'time'), 'datetime'),
                        'end': (('1981', '04', '05',
                                 None, None, None, 'date'),
                                ('01', '01', '00',
                                 None, 'time'), 'datetime')}),
                      ('1980-03-05T01:01:00/1981-04-05',
                       {'start': (('1980', '03', '05',
                                   None, None, None, 'date'),
                                  ('01', '01', '00',
                                   None, 'time'), 'datetime'),
                        'end': ('1981', '04', '05',
                                None, None, None, 'date')}),
                      ('1980-03-05/1981-04-05T01:01:00',
                       {'start': ('1980', '03', '05',
                                  None, None, None, 'date'),
                        'end': (('1981', '04', '05',
                                 None, None, None, 'date'),
                                ('01', '01', '00',
                                 None, 'time'), 'datetime')}),
                      ('1980-03-05/1981-04-05',
                       {'start': ('1980', '03', '05',
                                  None, None, None, 'date'),
                        'end': ('1981', '04', '05',
                                None, None, None, 'date')}),
                      ('1981-04-05/1980-03-05',
                       {'start': ('1981', '04', '05',
                                  None, None, None, 'date'),
                        'end': ('1980', '03', '05',
                                None, None, None, 'date')}),
                      #Make sure we truncate, not round
                      #https://bitbucket.org/nielsenb/aniso8601/issues/10/sub-microsecond-precision-in-durations-is
                      ('1980-03-05T01:01:00.0000001/'
                       '1981-04-05T14:43:59.9999997',
                       {'start': (('1980', '03', '05',
                                   None, None, None, 'date'),
                                  ('01', '01', '00.0000001',
                                   None, 'time'), 'datetime'),
                        'end': (('1981', '04', '05',
                                 None, None, None, 'date'),
                                ('14', '43', '59.9999997', None, 'time'),
                                'datetime')}))

        for testtuple in testtuples:
            mockBuilder = mock.Mock()
            mockBuilder.build_interval.return_value = testtuple[1]

            result = _parse_interval(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_interval.assert_called_once_with(**testtuple[1])

        #Test different separators
        expectedargs = {'start': (('1980', '03', '05',
                                   None, None, None,
                                   'date'),
                                  ('01', '01', '00',
                                   None, 'time'),
                                  'datetime'),
                        'end': (('1981', '04', '05',
                                 None, None, None,
                                 'date'),
                                ('01', '01', '00',
                                 None, 'time'),
                                'datetime')}

        mockBuilder = mock.Mock()
        mockBuilder.build_interval.return_value = expectedargs

        result = _parse_interval('1980-03-05T01:01:00--1981-04-05T01:01:00',
                                 mockBuilder,
                                 intervaldelimiter='--')

        self.assertEqual(result, expectedargs)
        mockBuilder.build_interval.assert_called_once_with(**expectedargs)

        expectedargs = {'start': (('1980', '03', '05',
                                   None, None, None,
                                   'date'),
                                  ('01', '01', '00',
                                   None, 'time'),
                                  'datetime'),
                        'end': (('1981', '04', '05',
                                 None, None, None,
                                 'date'),
                                ('01', '01', '00',
                                 None, 'time'),
                                'datetime')}

        mockBuilder = mock.Mock()
        mockBuilder.build_interval.return_value = expectedargs

        _parse_interval('1980-03-05 01:01:00/1981-04-05 01:01:00',
                        mockBuilder,
                        datetimedelimiter=' ')

        self.assertEqual(result, expectedargs)
        mockBuilder.build_interval.assert_called_once_with(**expectedargs)
Exemplo n.º 30
0
    def test_parse_repeating_interval_mockbuilder(self):
        mockBuilder = mock.Mock()

        args = {
            'R':
            False,
            'Rnn':
            '3',
            'interval':
            (('1981', '04', '05', None, None, None, 'date'), None,
             (None, None, None, '1', None, None, None, 'duration'), 'interval')
        }

        mockBuilder.build_repeating_interval.return_value = args

        result = parse_repeating_interval('R3/1981-04-05/P1D',
                                          builder=mockBuilder)

        self.assertEqual(result, args)
        mockBuilder.build_repeating_interval.assert_called_once_with(**args)

        mockBuilder = mock.Mock()

        args = {
            'R':
            False,
            'Rnn':
            '11',
            'interval':
            (None, (('1980', '03', '05', None, None, None, 'date'),
                    ('01', '01', '00', None, 'time'), 'datetime'),
             (None, None, None, None, '1', '2', None, 'duration'), 'interval')
        }

        mockBuilder.build_repeating_interval.return_value = args

        result = parse_repeating_interval('R11/PT1H2M/1980-03-05T01:01:00',
                                          builder=mockBuilder)

        self.assertEqual(result, args)
        mockBuilder.build_repeating_interval.assert_called_once_with(**args)

        mockBuilder = mock.Mock()

        args = {
            'R':
            True,
            'Rnn':
            None,
            'interval':
            (None, (('1980', '03', '05', None, None, None, 'date'),
                    ('01', '01', '00', None, 'time'), 'datetime'),
             (None, None, None, None, '1', '2', None, 'duration'), 'interval')
        }

        mockBuilder.build_repeating_interval.return_value = args

        result = parse_repeating_interval('R/PT1H2M/1980-03-05T01:01:00',
                                          builder=mockBuilder)

        self.assertEqual(result, args)
        mockBuilder.build_repeating_interval.assert_called_once_with(**args)