Exemple #1
0
    def test_build_datetime(self):
        testtuples = (({
            'date': DateTuple('1', '2', '3', '4', '5', '6'),
            'time': TimeTuple('7', '8', '9', None)
        },
                       DatetimeTuple(DateTuple('1', '2', '3', '4', '5', '6'),
                                     TimeTuple('7', '8', '9', None))),
                      ({
                          'date':
                          DateTuple('1', '2', '3', '4', '5', '6'),
                          'time':
                          TimeTuple(
                              '7', '8', '9',
                              TimezoneTuple(True, False, '10', '11',
                                            'tz name'))
                      },
                       DatetimeTuple(
                           DateTuple('1', '2', '3', '4', '5', '6'),
                           TimeTuple(
                               '7', '8', '9',
                               TimezoneTuple(True, False, '10', '11',
                                             'tz name')))))

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_datetime(**testtuple[0]),
                             testtuple[1])
Exemple #2
0
    def test_build_time(self):
        testtuples = (({}, TimeTuple(None, None, None, None)), ({
            'hh': '1',
            'mm': '2',
            'ss': '3',
            'tz': None
        }, TimeTuple('1', '2', '3',
                     None)), ({
                         'hh':
                         '1',
                         'mm':
                         '2',
                         'ss':
                         '3',
                         'tz':
                         TimezoneTuple(False, False, '4', '5', 'tz name')
                     },
                              TimeTuple(
                                  '1', '2', '3',
                                  TimezoneTuple(False, False, '4', '5',
                                                'tz name'))))

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_time(**testtuple[0]),
                             testtuple[1])
Exemple #3
0
    def test_build_time(self):
        testtuples = (
            ({}, TimeTuple(None, None, None, None)),
            (
                {
                    "hh": "1",
                    "mm": "2",
                    "ss": "3",
                    "tz": None
                },
                TimeTuple("1", "2", "3", None),
            ),
            (
                {
                    "hh": "1",
                    "mm": "2",
                    "ss": "3",
                    "tz": TimezoneTuple(False, False, "4", "5", "tz name"),
                },
                TimeTuple("1", "2", "3",
                          TimezoneTuple(False, False, "4", "5", "tz name")),
            ),
        )

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_time(**testtuple[0]),
                             testtuple[1])
Exemple #4
0
    def test_build_datetime(self):
        testtuples = (
            (
                {
                    "date": DateTuple("1", "2", "3", "4", "5", "6"),
                    "time": TimeTuple("7", "8", "9", None),
                },
                DatetimeTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    TimeTuple("7", "8", "9", None),
                ),
            ),
            (
                {
                    "date":
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    "time":
                    TimeTuple(
                        "7", "8", "9",
                        TimezoneTuple(True, False, "10", "11", "tz name")),
                },
                DatetimeTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    TimeTuple(
                        "7", "8", "9",
                        TimezoneTuple(True, False, "10", "11", "tz name")),
                ),
            ),
        )

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_datetime(**testtuple[0]),
                             testtuple[1])
Exemple #5
0
 def test_get_time_resolution_internal(self):
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh='01', mm='02', ss='03',
                                        tz=None)), TimeResolution.Seconds)
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh='01', mm='02', ss=None,
                                        tz=None)), TimeResolution.Minutes)
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh='01', mm=None, ss=None,
                                        tz=None)), TimeResolution.Hours)
Exemple #6
0
 def test_get_time_resolution_internal(self):
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh="01", mm="02", ss="03", tz=None)),
         TimeResolution.Seconds,
     )
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh="01", mm="02", ss=None, tz=None)),
         TimeResolution.Minutes,
     )
     self.assertEqual(
         _get_time_resolution(TimeTuple(hh="01", mm=None, ss=None, tz=None)),
         TimeResolution.Hours,
     )
Exemple #7
0
    def test_build_repeating_interval(self):
        testtuples = (({}, RepeatingIntervalTuple(
            None, None, None)), ({
                'R':
                True,
                'interval':
                IntervalTuple(DateTuple('1', '2', '3', '4', '5', '6'),
                              DateTuple('7', '8', '9', '10', '11', '12'), None)
            },
                                 RepeatingIntervalTuple(
                                     True, None,
                                     IntervalTuple(
                                         DateTuple('1', '2', '3', '4', '5',
                                                   '6'),
                                         DateTuple('7', '8', '9', '10', '11',
                                                   '12'), None))),
                      ({
                          'R':
                          False,
                          'Rnn':
                          '1',
                          'interval':
                          IntervalTuple(
                              DatetimeTuple(
                                  DateTuple('2', '3', '4', '5', '6', '7'),
                                  TimeTuple('8', '9', '10', None)),
                              DatetimeTuple(
                                  DateTuple('11', '12', '13', '14', '15',
                                            '16'),
                                  TimeTuple('17', '18', '19', None)), None)
                      },
                       RepeatingIntervalTuple(
                           False, '1',
                           IntervalTuple(
                               DatetimeTuple(
                                   DateTuple('2', '3', '4', '5', '6', '7'),
                                   TimeTuple('8', '9', '10', None)),
                               DatetimeTuple(
                                   DateTuple('11', '12', '13', '14', '15',
                                             '16'),
                                   TimeTuple('17', '18', '19', None)), None))))

        for testtuple in testtuples:
            result = TupleBuilder.build_repeating_interval(**testtuple[0])
            self.assertEqual(result, testtuple[1])
Exemple #8
0
    def test_is_interval_end_concise(self):
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                TimeTuple('1', '2', '3', None)))
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                DateTuple(None, '2', '3', '4', '5', '6')))
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                DatetimeTuple(DateTuple(None, '2', '3', '4', '5', '6'),
                              TimeTuple('7', '8', '9', None))))

        self.assertFalse(
            BaseTimeBuilder._is_interval_end_concise(
                DateTuple('1', '2', '3', '4', '5', '6')))
        self.assertFalse(
            BaseTimeBuilder._is_interval_end_concise(
                DatetimeTuple(DateTuple('1', '2', '3', '4', '5', '6'),
                              TimeTuple('7', '8', '9', None))))
Exemple #9
0
    def test_is_interval_end_concise(self):
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                TimeTuple("1", "2", "3", None)))
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                DateTuple(None, "2", "3", "4", "5", "6")))
        self.assertTrue(
            BaseTimeBuilder._is_interval_end_concise(
                DatetimeTuple(
                    DateTuple(None, "2", "3", "4", "5", "6"),
                    TimeTuple("7", "8", "9", None),
                )))

        self.assertFalse(
            BaseTimeBuilder._is_interval_end_concise(
                DateTuple("1", "2", "3", "4", "5", "6")))
        self.assertFalse(
            BaseTimeBuilder._is_interval_end_concise(
                DatetimeTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    TimeTuple("7", "8", "9", None),
                )))
Exemple #10
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)
Exemple #11
0
    def test_parse_datetime_commadelimited(self):
        expectedargs = (DateTuple('1981', '04', '05', None, None, None),
                        TimeTuple('23', '21', '28.512400',
                                  TimezoneTuple(False, True, None, None, 'Z')))

        with mock.patch.object(aniso8601.time.PythonTimeBuilder,
                               'build_datetime') as mockBuildDateTime:

            mockBuildDateTime.return_value = expectedargs

            result = parse_datetime('1981-04-05,23:21:28,512400Z',
                                    delimiter=',')

        self.assertEqual(result, expectedargs)
        mockBuildDateTime.assert_called_once_with(*expectedargs)
Exemple #12
0
    def test_parse_datetime_spacedelimited(self):
        expectedargs = (DateTuple('2004', None, None, '53', '6', None),
                        TimeTuple(
                            '23', '21', '28.512400',
                            TimezoneTuple(True, None, '12', '34', '-12:34')))

        with mock.patch.object(aniso8601.time.PythonTimeBuilder,
                               'build_datetime') as mockBuildDateTime:

            mockBuildDateTime.return_value = expectedargs

            result = parse_datetime('2004-W53-6 23:21:28.512400-12:34',
                                    delimiter=' ')

        self.assertEqual(result, expectedargs)
        mockBuildDateTime.assert_called_once_with(*expectedargs)
Exemple #13
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)
Exemple #14
0
    def test_parse_datetime_commadelimited(self):
        expectedargs = (
            DateTuple("1981", "04", "05", None, None, None),
            TimeTuple(
                "23", "21", "28.512400", TimezoneTuple(False, True, None, None, "Z")
            ),
        )

        with mock.patch.object(
            aniso8601.time.PythonTimeBuilder, "build_datetime"
        ) as mockBuildDateTime:

            mockBuildDateTime.return_value = expectedargs

            result = parse_datetime("1981-04-05,23:21:28,512400Z", delimiter=",")

        self.assertEqual(result, expectedargs)
        mockBuildDateTime.assert_called_once_with(*expectedargs)
Exemple #15
0
    def test_parse_datetime_spacedelimited(self):
        expectedargs = (
            DateTuple("2004", None, None, "53", "6", None),
            TimeTuple(
                "23", "21", "28.512400", TimezoneTuple(True, None, "12", "34", "-12:34")
            ),
        )

        with mock.patch.object(
            aniso8601.time.PythonTimeBuilder, "build_datetime"
        ) as mockBuildDateTime:

            mockBuildDateTime.return_value = expectedargs

            result = parse_datetime("2004-W53-6 23:21:28.512400-12:34", delimiter=" ")

        self.assertEqual(result, expectedargs)
        mockBuildDateTime.assert_called_once_with(*expectedargs)
Exemple #16
0
    def test_parse_datetime(self):
        testtuples = (('2019-06-05T01:03:11,858714',
                       (DateTuple('2019', '06', '05', None, None, None),
                        TimeTuple('01', '03', '11.858714',
                                  None))), ('2019-06-05T01:03:11.858714',
                                            (DateTuple('2019', '06', '05',
                                                       None, None, None),
                                             TimeTuple('01', '03', '11.858714',
                                                       None))),
                      ('1981-04-05T23:21:28.512400Z',
                       (DateTuple('1981', '04', '05', None, None, None),
                        TimeTuple('23', '21', '28.512400',
                                  TimezoneTuple(False, True, None, None,
                                                'Z')))),
                      ('1981095T23:21:28.512400-12:34',
                       (DateTuple('1981', None, None, None, None, '095'),
                        TimeTuple(
                            '23', '21', '28.512400',
                            TimezoneTuple(True, None, '12', '34', '-12:34')))),
                      ('19810405T23:21:28+00',
                       (DateTuple('1981', '04', '05', None, None, None),
                        TimeTuple(
                            '23', '21', '28',
                            TimezoneTuple(False, None, '00', None, '+00')))),
                      ('19810405T23:21:28+00:00',
                       (DateTuple('1981', '04', '05', None, None, None),
                        TimeTuple(
                            '23', '21', '28',
                            TimezoneTuple(False, None, '00', '00',
                                          '+00:00')))))

        for testtuple in testtuples:
            with mock.patch.object(aniso8601.time.PythonTimeBuilder,
                                   'build_datetime') as mockBuildDateTime:

                mockBuildDateTime.return_value = testtuple[1]

                result = parse_datetime(testtuple[0])

            self.assertEqual(result, testtuple[1])
            mockBuildDateTime.assert_called_once_with(*testtuple[1])
Exemple #17
0
    def test_combine_concise_interval_tuples(self):
        testtuples = ((DateTuple('2020', '01', '01', None, None, None),
                       DateTuple(None, None, '02', None, None, None),
                       DateTuple('2020', '01', '02', None, None,
                                 None)), (DateTuple('2008', '02', '15', None,
                                                    None, None),
                                          DateTuple(None, '03', '14', None,
                                                    None, None),
                                          DateTuple('2008', '03', '14', None,
                                                    None, None)),
                      (DatetimeTuple(
                          DateTuple('2007', '12', '14', None, None, None),
                          TimeTuple('13', '30', None,
                                    None)), TimeTuple('15', '30', None, None),
                       DatetimeTuple(
                           DateTuple('2007', '12', '14', None, None, None),
                           TimeTuple('15', '30', None, None))),
                      (DatetimeTuple(
                          DateTuple('2007', '11', '13', None, None, None),
                          TimeTuple('09', '00', None, None)),
                       DatetimeTuple(
                           DateTuple(None, None, '15', None, None, None),
                           TimeTuple('17', '00', None, None)),
                       DatetimeTuple(
                           DateTuple('2007', '11', '15', None, None, None),
                           TimeTuple('17', '00', None, None))),
                      (DatetimeTuple(
                          DateTuple('2007', '11', '13', None, None, None),
                          TimeTuple('00', '00', None, None)),
                       DatetimeTuple(
                           DateTuple(None, None, '16', None, None, None),
                           TimeTuple('00', '00', None, None)),
                       DatetimeTuple(
                           DateTuple('2007', '11', '16', None, None, None),
                           TimeTuple('00', '00', None, None))),
                      (DatetimeTuple(
                          DateTuple('2007', '11', '13', None, None, None),
                          TimeTuple(
                              '09', '00', None,
                              TimezoneTuple(False, True, None, None, 'Z'))),
                       DatetimeTuple(
                           DateTuple(None, None, '15', None, None, None),
                           TimeTuple('17', '00', None, None)),
                       DatetimeTuple(
                           DateTuple('2007', '11', '15', None, None, None),
                           TimeTuple(
                               '17', '00', None,
                               TimezoneTuple(False, True, None, None, 'Z')))))

        for testtuple in testtuples:
            result = BaseTimeBuilder._combine_concise_interval_tuples(
                testtuple[0], testtuple[1])
            self.assertEqual(result, testtuple[2])
Exemple #18
0
    def test_combine_concise_interval_tuples(self):
        testtuples = (
            (
                DateTuple("2020", "01", "01", None, None, None),
                DateTuple(None, None, "02", None, None, None),
                DateTuple("2020", "01", "02", None, None, None),
            ),
            (
                DateTuple("2008", "02", "15", None, None, None),
                DateTuple(None, "03", "14", None, None, None),
                DateTuple("2008", "03", "14", None, None, None),
            ),
            (
                DatetimeTuple(
                    DateTuple("2007", "12", "14", None, None, None),
                    TimeTuple("13", "30", None, None),
                ),
                TimeTuple("15", "30", None, None),
                DatetimeTuple(
                    DateTuple("2007", "12", "14", None, None, None),
                    TimeTuple("15", "30", None, None),
                ),
            ),
            (
                DatetimeTuple(
                    DateTuple("2007", "11", "13", None, None, None),
                    TimeTuple("09", "00", None, None),
                ),
                DatetimeTuple(
                    DateTuple(None, None, "15", None, None, None),
                    TimeTuple("17", "00", None, None),
                ),
                DatetimeTuple(
                    DateTuple("2007", "11", "15", None, None, None),
                    TimeTuple("17", "00", None, None),
                ),
            ),
            (
                DatetimeTuple(
                    DateTuple("2007", "11", "13", None, None, None),
                    TimeTuple("00", "00", None, None),
                ),
                DatetimeTuple(
                    DateTuple(None, None, "16", None, None, None),
                    TimeTuple("00", "00", None, None),
                ),
                DatetimeTuple(
                    DateTuple("2007", "11", "16", None, None, None),
                    TimeTuple("00", "00", None, None),
                ),
            ),
            (
                DatetimeTuple(
                    DateTuple("2007", "11", "13", None, None, None),
                    TimeTuple("09", "00", None,
                              TimezoneTuple(False, True, None, None, "Z")),
                ),
                DatetimeTuple(
                    DateTuple(None, None, "15", None, None, None),
                    TimeTuple("17", "00", None, None),
                ),
                DatetimeTuple(
                    DateTuple("2007", "11", "15", None, None, None),
                    TimeTuple("17", "00", None,
                              TimezoneTuple(False, True, None, None, "Z")),
                ),
            ),
        )

        for testtuple in testtuples:
            result = BaseTimeBuilder._combine_concise_interval_tuples(
                testtuple[0], testtuple[1])
            self.assertEqual(result, testtuple[2])
Exemple #19
0
    def test_build_object(self):
        datetest = (
            DateTuple("1", "2", "3", "4", "5", "6"),
            {
                "YYYY": "1",
                "MM": "2",
                "DD": "3",
                "Www": "4",
                "D": "5",
                "DDD": "6"
            },
        )

        timetest = (
            TimeTuple("1", "2", "3",
                      TimezoneTuple(False, False, "4", "5", "tz name")),
            {
                "hh": "1",
                "mm": "2",
                "ss": "3",
                "tz": TimezoneTuple(False, False, "4", "5", "tz name"),
            },
        )

        datetimetest = (
            DatetimeTuple(
                DateTuple("1", "2", "3", "4", "5", "6"),
                TimeTuple("7", "8", "9",
                          TimezoneTuple(True, False, "10", "11", "tz name")),
            ),
            (
                DateTuple("1", "2", "3", "4", "5", "6"),
                TimeTuple("7", "8", "9",
                          TimezoneTuple(True, False, "10", "11", "tz name")),
            ),
        )

        durationtest = (
            DurationTuple("1", "2", "3", "4", "5", "6", "7"),
            {
                "PnY": "1",
                "PnM": "2",
                "PnW": "3",
                "PnD": "4",
                "TnH": "5",
                "TnM": "6",
                "TnS": "7",
            },
        )

        intervaltests = (
            (
                IntervalTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    DateTuple("7", "8", "9", "10", "11", "12"),
                    None,
                ),
                {
                    "start": DateTuple("1", "2", "3", "4", "5", "6"),
                    "end": DateTuple("7", "8", "9", "10", "11", "12"),
                    "duration": None,
                },
            ),
            (
                IntervalTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    None,
                    DurationTuple("7", "8", "9", "10", "11", "12", "13"),
                ),
                {
                    "start":
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    "end":
                    None,
                    "duration":
                    DurationTuple("7", "8", "9", "10", "11", "12", "13"),
                },
            ),
            (
                IntervalTuple(
                    None,
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "4", "5", "tz name")),
                    DurationTuple("6", "7", "8", "9", "10", "11", "12"),
                ),
                {
                    "start":
                    None,
                    "end":
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "4", "5", "tz name")),
                    "duration":
                    DurationTuple("6", "7", "8", "9", "10", "11", "12"),
                },
            ),
        )

        repeatingintervaltests = (
            (
                RepeatingIntervalTuple(
                    True,
                    None,
                    IntervalTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        DateTuple("7", "8", "9", "10", "11", "12"),
                        None,
                    ),
                ),
                {
                    "R":
                    True,
                    "Rnn":
                    None,
                    "interval":
                    IntervalTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        DateTuple("7", "8", "9", "10", "11", "12"),
                        None,
                    ),
                },
            ),
            (
                RepeatingIntervalTuple(
                    False,
                    "1",
                    IntervalTuple(
                        DatetimeTuple(
                            DateTuple("2", "3", "4", "5", "6", "7"),
                            TimeTuple("8", "9", "10", None),
                        ),
                        DatetimeTuple(
                            DateTuple("11", "12", "13", "14", "15", "16"),
                            TimeTuple("17", "18", "19", None),
                        ),
                        None,
                    ),
                ),
                {
                    "R":
                    False,
                    "Rnn":
                    "1",
                    "interval":
                    IntervalTuple(
                        DatetimeTuple(
                            DateTuple("2", "3", "4", "5", "6", "7"),
                            TimeTuple("8", "9", "10", None),
                        ),
                        DatetimeTuple(
                            DateTuple("11", "12", "13", "14", "15", "16"),
                            TimeTuple("17", "18", "19", None),
                        ),
                        None,
                    ),
                },
            ),
        )

        timezonetest = (
            TimezoneTuple(False, False, "1", "2", "+01:02"),
            {
                "negative": False,
                "Z": False,
                "hh": "1",
                "mm": "2",
                "name": "+01:02"
            },
        )

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               "build_date") as mock_build:
            mock_build.return_value = datetest[0]

            result = BaseTimeBuilder._build_object(datetest[0])

            self.assertEqual(result, datetest[0])
            mock_build.assert_called_once_with(**datetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               "build_time") as mock_build:
            mock_build.return_value = timetest[0]

            result = BaseTimeBuilder._build_object(timetest[0])

            self.assertEqual(result, timetest[0])
            mock_build.assert_called_once_with(**timetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               "build_datetime") as mock_build:
            mock_build.return_value = datetimetest[0]

            result = BaseTimeBuilder._build_object(datetimetest[0])

            self.assertEqual(result, datetimetest[0])
            mock_build.assert_called_once_with(*datetimetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               "build_duration") as mock_build:
            mock_build.return_value = durationtest[0]

            result = BaseTimeBuilder._build_object(durationtest[0])

            self.assertEqual(result, durationtest[0])
            mock_build.assert_called_once_with(**durationtest[1])

        for intervaltest in intervaltests:
            with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                                   "build_interval") as mock_build:
                mock_build.return_value = intervaltest[0]

                result = BaseTimeBuilder._build_object(intervaltest[0])

                self.assertEqual(result, intervaltest[0])
                mock_build.assert_called_once_with(**intervaltest[1])

        for repeatingintervaltest in repeatingintervaltests:
            with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                                   "build_repeating_interval") as mock_build:
                mock_build.return_value = repeatingintervaltest[0]

                result = BaseTimeBuilder._build_object(
                    repeatingintervaltest[0])

                self.assertEqual(result, repeatingintervaltest[0])
                mock_build.assert_called_once_with(**repeatingintervaltest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               "build_timezone") as mock_build:
            mock_build.return_value = timezonetest[0]

            result = BaseTimeBuilder._build_object(timezonetest[0])

            self.assertEqual(result, timezonetest[0])
            mock_build.assert_called_once_with(**timezonetest[1])
Exemple #20
0
    def test_build_interval(self):
        testtuples = (({}, IntervalTuple(
            None, None,
            None)), ({
                'start': DateTuple('1', '2', '3', '4', '5', '6'),
                'end': DateTuple('7', '8', '9', '10', '11', '12')
            },
                     IntervalTuple(DateTuple('1', '2', '3', '4', '5', '6'),
                                   DateTuple('7', '8', '9', '10', '11', '12'),
                                   None)),
                      ({
                          'start':
                          TimeTuple(
                              '1',
                              '2',
                              '3',
                              TimezoneTuple(True, False, '7', '8', 'tz name')),
                          'end':
                          TimeTuple(
                              '4',
                              '5',
                              '6',
                              TimezoneTuple(False, False, '9', '10',
                                            'tz name'))
                      },
                       IntervalTuple(
                           TimeTuple(
                               '1', '2', '3',
                               TimezoneTuple(True, False, '7', '8',
                                             'tz name')),
                           TimeTuple(
                               '4', '5', '6',
                               TimezoneTuple(False, False, '9', '10',
                                             'tz name')), None)),
                      ({
                          'start':
                          DatetimeTuple(
                              DateTuple('1', '2', '3', '4', '5',
                                        '6'),
                              TimeTuple(
                                  '7',
                                  '8',
                                  '9',
                                  TimezoneTuple(True, False, '10', '11',
                                                'tz name'))),
                          'end':
                          DatetimeTuple(
                              DateTuple('12', '13', '14', '15', '16', '17'),
                              TimeTuple(
                                  '18', '19', '20',
                                  TimezoneTuple(False, False, '21', '22',
                                                'tz name')))
                      },
                       IntervalTuple(
                           DatetimeTuple(
                               DateTuple('1', '2', '3', '4', '5', '6'),
                               TimeTuple(
                                   '7', '8', '9',
                                   TimezoneTuple(True, False, '10', '11',
                                                 'tz name'))),
                           DatetimeTuple(
                               DateTuple('12', '13', '14', '15', '16', '17'),
                               TimeTuple(
                                   '18', '19', '20',
                                   TimezoneTuple(False, False, '21', '22',
                                                 'tz name'))),
                           None)), ({
                               'start':
                               DateTuple('1', '2', '3', '4', '5', '6'),
                               'end':
                               None,
                               'duration':
                               DurationTuple('7', '8', '9', '10', '11', '12',
                                             '13')
                           },
                                    IntervalTuple(
                                        DateTuple('1', '2', '3', '4', '5',
                                                  '6'), None,
                                        DurationTuple('7', '8', '9', '10',
                                                      '11', '12', '13'))),
                      ({
                          'start':
                          None,
                          'end':
                          TimeTuple(
                              '1', '2', '3',
                              TimezoneTuple(True, False, '4', '5', 'tz name')),
                          'duration':
                          DurationTuple('6', '7', '8', '9', '10', '11', '12')
                      },
                       IntervalTuple(
                           None,
                           TimeTuple(
                               '1', '2', '3',
                               TimezoneTuple(True, False, '4', '5',
                                             'tz name')),
                           DurationTuple('6', '7', '8', '9', '10', '11',
                                         '12'))))

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_interval(**testtuple[0]),
                             testtuple[1])
Exemple #21
0
    def test_build_interval(self):
        testtuples = (
            ({}, IntervalTuple(None, None, None)),
            (
                {
                    "start": DateTuple("1", "2", "3", "4", "5", "6"),
                    "end": DateTuple("7", "8", "9", "10", "11", "12"),
                },
                IntervalTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    DateTuple("7", "8", "9", "10", "11", "12"),
                    None,
                ),
            ),
            (
                {
                    "start":
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "7", "8", "tz name")),
                    "end":
                    TimeTuple(
                        "4", "5", "6",
                        TimezoneTuple(False, False, "9", "10", "tz name")),
                },
                IntervalTuple(
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "7", "8", "tz name")),
                    TimeTuple(
                        "4", "5", "6",
                        TimezoneTuple(False, False, "9", "10", "tz name")),
                    None,
                ),
            ),
            (
                {
                    "start":
                    DatetimeTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        TimeTuple(
                            "7",
                            "8",
                            "9",
                            TimezoneTuple(True, False, "10", "11", "tz name"),
                        ),
                    ),
                    "end":
                    DatetimeTuple(
                        DateTuple("12", "13", "14", "15", "16", "17"),
                        TimeTuple(
                            "18",
                            "19",
                            "20",
                            TimezoneTuple(False, False, "21", "22", "tz name"),
                        ),
                    ),
                },
                IntervalTuple(
                    DatetimeTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        TimeTuple(
                            "7",
                            "8",
                            "9",
                            TimezoneTuple(True, False, "10", "11", "tz name"),
                        ),
                    ),
                    DatetimeTuple(
                        DateTuple("12", "13", "14", "15", "16", "17"),
                        TimeTuple(
                            "18",
                            "19",
                            "20",
                            TimezoneTuple(False, False, "21", "22", "tz name"),
                        ),
                    ),
                    None,
                ),
            ),
            (
                {
                    "start":
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    "end":
                    None,
                    "duration":
                    DurationTuple("7", "8", "9", "10", "11", "12", "13"),
                },
                IntervalTuple(
                    DateTuple("1", "2", "3", "4", "5", "6"),
                    None,
                    DurationTuple("7", "8", "9", "10", "11", "12", "13"),
                ),
            ),
            (
                {
                    "start":
                    None,
                    "end":
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "4", "5", "tz name")),
                    "duration":
                    DurationTuple("6", "7", "8", "9", "10", "11", "12"),
                },
                IntervalTuple(
                    None,
                    TimeTuple("1", "2", "3",
                              TimezoneTuple(True, False, "4", "5", "tz name")),
                    DurationTuple("6", "7", "8", "9", "10", "11", "12"),
                ),
            ),
        )

        for testtuple in testtuples:
            self.assertEqual(TupleBuilder.build_interval(**testtuple[0]),
                             testtuple[1])
Exemple #22
0
    def test_parse_datetime(self):
        testtuples = (
            (
                "2019-06-05T01:03:11,858714",
                (
                    DateTuple("2019", "06", "05", None, None, None),
                    TimeTuple("01", "03", "11.858714", None),
                ),
            ),
            (
                "2019-06-05T01:03:11.858714",
                (
                    DateTuple("2019", "06", "05", None, None, None),
                    TimeTuple("01", "03", "11.858714", None),
                ),
            ),
            (
                "1981-04-05T23:21:28.512400Z",
                (
                    DateTuple("1981", "04", "05", None, None, None),
                    TimeTuple(
                        "23",
                        "21",
                        "28.512400",
                        TimezoneTuple(False, True, None, None, "Z"),
                    ),
                ),
            ),
            (
                "1981095T23:21:28.512400-12:34",
                (
                    DateTuple("1981", None, None, None, None, "095"),
                    TimeTuple(
                        "23",
                        "21",
                        "28.512400",
                        TimezoneTuple(True, None, "12", "34", "-12:34"),
                    ),
                ),
            ),
            (
                "19810405T23:21:28+00",
                (
                    DateTuple("1981", "04", "05", None, None, None),
                    TimeTuple(
                        "23", "21", "28", TimezoneTuple(False, None, "00", None, "+00")
                    ),
                ),
            ),
            (
                "19810405T23:21:28+00:00",
                (
                    DateTuple("1981", "04", "05", None, None, None),
                    TimeTuple(
                        "23",
                        "21",
                        "28",
                        TimezoneTuple(False, None, "00", "00", "+00:00"),
                    ),
                ),
            ),
        )

        for testtuple in testtuples:
            with mock.patch.object(
                aniso8601.time.PythonTimeBuilder, "build_datetime"
            ) as mockBuildDateTime:

                mockBuildDateTime.return_value = testtuple[1]

                result = parse_datetime(testtuple[0])

            self.assertEqual(result, testtuple[1])
            mockBuildDateTime.assert_called_once_with(*testtuple[1])
Exemple #23
0
    def test_build_repeating_interval(self):
        testtuples = (
            ({}, RepeatingIntervalTuple(None, None, None)),
            (
                {
                    "R":
                    True,
                    "interval":
                    IntervalTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        DateTuple("7", "8", "9", "10", "11", "12"),
                        None,
                    ),
                },
                RepeatingIntervalTuple(
                    True,
                    None,
                    IntervalTuple(
                        DateTuple("1", "2", "3", "4", "5", "6"),
                        DateTuple("7", "8", "9", "10", "11", "12"),
                        None,
                    ),
                ),
            ),
            (
                {
                    "R":
                    False,
                    "Rnn":
                    "1",
                    "interval":
                    IntervalTuple(
                        DatetimeTuple(
                            DateTuple("2", "3", "4", "5", "6", "7"),
                            TimeTuple("8", "9", "10", None),
                        ),
                        DatetimeTuple(
                            DateTuple("11", "12", "13", "14", "15", "16"),
                            TimeTuple("17", "18", "19", None),
                        ),
                        None,
                    ),
                },
                RepeatingIntervalTuple(
                    False,
                    "1",
                    IntervalTuple(
                        DatetimeTuple(
                            DateTuple("2", "3", "4", "5", "6", "7"),
                            TimeTuple("8", "9", "10", None),
                        ),
                        DatetimeTuple(
                            DateTuple("11", "12", "13", "14", "15", "16"),
                            TimeTuple("17", "18", "19", None),
                        ),
                        None,
                    ),
                ),
            ),
        )

        for testtuple in testtuples:
            result = TupleBuilder.build_repeating_interval(**testtuple[0])
            self.assertEqual(result, testtuple[1])
Exemple #24
0
    def test_build_object(self):
        datetest = (DateTuple('1', '2', '3', '4', '5', '6'), {
            'YYYY': '1',
            'MM': '2',
            'DD': '3',
            'Www': '4',
            'D': '5',
            'DDD': '6'
        })

        timetest = (TimeTuple('1', '2', '3',
                              TimezoneTuple(False, False, '4', '5',
                                            'tz name')),
                    {
                        'hh': '1',
                        'mm': '2',
                        'ss': '3',
                        'tz': TimezoneTuple(False, False, '4', '5', 'tz name')
                    })

        datetimetest = (DatetimeTuple(
            DateTuple('1', '2', '3', '4', '5', '6'),
            TimeTuple('7', '8', '9',
                      TimezoneTuple(True, False, '10', '11', 'tz name'))),
                        (DateTuple('1', '2', '3', '4', '5', '6'),
                         TimeTuple(
                             '7', '8', '9',
                             TimezoneTuple(True, False, '10', '11',
                                           'tz name'))))

        durationtest = (DurationTuple('1', '2', '3', '4', '5', '6', '7'), {
            'PnY': '1',
            'PnM': '2',
            'PnW': '3',
            'PnD': '4',
            'TnH': '5',
            'TnM': '6',
            'TnS': '7'
        })

        intervaltests = ((IntervalTuple(
            DateTuple('1', '2', '3', '4', '5', '6'),
            DateTuple('7', '8', '9', '10', '11', '12'), None), {
                'start': DateTuple('1', '2', '3', '4', '5', '6'),
                'end': DateTuple('7', '8', '9', '10', '11', '12'),
                'duration': None
            }), (IntervalTuple(
                DateTuple('1', '2', '3', '4', '5', '6'), None,
                DurationTuple('7', '8', '9', '10', '11', '12', '13')), {
                    'start':
                    DateTuple('1', '2', '3', '4', '5', '6'),
                    'end':
                    None,
                    'duration':
                    DurationTuple('7', '8', '9', '10', '11', '12', '13')
                }), (IntervalTuple(
                    None,
                    TimeTuple('1', '2', '3',
                              TimezoneTuple(True, False, '4', '5', 'tz name')),
                    DurationTuple('6', '7', '8', '9', '10', '11', '12')), {
                        'start':
                        None,
                        'end':
                        TimeTuple(
                            '1', '2', '3',
                            TimezoneTuple(True, False, '4', '5', 'tz name')),
                        'duration':
                        DurationTuple('6', '7', '8', '9', '10', '11', '12')
                    }))

        repeatingintervaltests = ((RepeatingIntervalTuple(
            True, None,
            IntervalTuple(
                DateTuple('1', '2', '3', '4', '5', '6'),
                DateTuple('7', '8', '9', '10', '11', '12'), None)), {
                    'R':
                    True,
                    'Rnn':
                    None,
                    'interval':
                    IntervalTuple(DateTuple('1', '2', '3', '4', '5', '6'),
                                  DateTuple('7', '8', '9', '10', '11', '12'),
                                  None)
                }), (RepeatingIntervalTuple(
                    False, '1',
                    IntervalTuple(
                        DatetimeTuple(DateTuple('2', '3', '4', '5', '6', '7'),
                                      TimeTuple('8', '9', '10', None)),
                        DatetimeTuple(
                            DateTuple('11', '12', '13', '14', '15', '16'),
                            TimeTuple('17', '18', '19', None)),
                        None)), {
                            'R':
                            False,
                            'Rnn':
                            '1',
                            'interval':
                            IntervalTuple(
                                DatetimeTuple(
                                    DateTuple('2', '3', '4', '5', '6', '7'),
                                    TimeTuple('8', '9', '10', None)),
                                DatetimeTuple(
                                    DateTuple('11', '12', '13', '14', '15',
                                              '16'),
                                    TimeTuple('17', '18', '19', None)), None)
                        }))

        timezonetest = (TimezoneTuple(False, False, '1', '2', '+01:02'), {
            'negative': False,
            'Z': False,
            'hh': '1',
            'mm': '2',
            'name': '+01:02'
        })

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               'build_date') as mock_build:
            mock_build.return_value = datetest[0]

            result = BaseTimeBuilder._build_object(datetest[0])

            self.assertEqual(result, datetest[0])
            mock_build.assert_called_once_with(**datetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               'build_time') as mock_build:
            mock_build.return_value = timetest[0]

            result = BaseTimeBuilder._build_object(timetest[0])

            self.assertEqual(result, timetest[0])
            mock_build.assert_called_once_with(**timetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               'build_datetime') as mock_build:
            mock_build.return_value = datetimetest[0]

            result = BaseTimeBuilder._build_object(datetimetest[0])

            self.assertEqual(result, datetimetest[0])
            mock_build.assert_called_once_with(*datetimetest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               'build_duration') as mock_build:
            mock_build.return_value = durationtest[0]

            result = BaseTimeBuilder._build_object(durationtest[0])

            self.assertEqual(result, durationtest[0])
            mock_build.assert_called_once_with(**durationtest[1])

        for intervaltest in intervaltests:
            with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                                   'build_interval') as mock_build:
                mock_build.return_value = intervaltest[0]

                result = BaseTimeBuilder._build_object(intervaltest[0])

                self.assertEqual(result, intervaltest[0])
                mock_build.assert_called_once_with(**intervaltest[1])

        for repeatingintervaltest in repeatingintervaltests:
            with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                                   'build_repeating_interval') as mock_build:
                mock_build.return_value = repeatingintervaltest[0]

                result = BaseTimeBuilder._build_object(
                    repeatingintervaltest[0])

                self.assertEqual(result, repeatingintervaltest[0])
                mock_build.assert_called_once_with(**repeatingintervaltest[1])

        with mock.patch.object(aniso8601.builders.BaseTimeBuilder,
                               'build_timezone') as mock_build:
            mock_build.return_value = timezonetest[0]

            result = BaseTimeBuilder._build_object(timezonetest[0])

            self.assertEqual(result, timezonetest[0])
            mock_build.assert_called_once_with(**timezonetest[1])