Пример #1
0
    def test_parse_duration_prescribed_time_timeindate(self):
        #Don't allow time components in date half
        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time('P1Y2M3D4HT54M6S', None)

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time('P1Y2M3D6ST4H54M', None)
Пример #2
0
    def test_parse_duration_prescribed_time_dateintime(self):
        #Don't allow date components in time half
        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time('P2M3DT1Y4H54M6S', None)

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time('P1Y2MT3D4H54M6S', None)
Пример #3
0
    def test_parse_duration_prescribed_time(self):
        resultduration = _parse_duration_prescribed_time('P1Y2M3DT4H54M6S')
        self.assertEqual(resultduration, (1, 2, 0, 3, 4, 54, 6))

        resultduration = _parse_duration_prescribed_time('P1Y2M3DT4H54M6.5S')
        self.assertEqual(resultduration, (1, 2, 0, 3, 4, 54, 6.5))

        resultduration = _parse_duration_prescribed_time('P1Y2M3DT4H54M6,5S')
        self.assertEqual(resultduration, (1, 2, 0, 3, 4, 54, 6.5))

        resultduration = _parse_duration_prescribed_time('PT4H54M6.5S')
        self.assertEqual(resultduration, (0, 0, 0, 0, 4, 54, 6.5))

        resultduration = _parse_duration_prescribed_time('PT4H54M6,5S')
        self.assertEqual(resultduration, (0, 0, 0, 0, 4, 54, 6.5))
Пример #4
0
    def test_parse_duration_prescribed_time(self):
        testtuples = (('P1Y2M3DT4H54M6S', {'PnY': '1', 'PnM': '2',
                                           'PnW': None, 'PnD': '3',
                                           'TnH': '4', 'TnM': '54',
                                           'TnS': '6'}),
                      ('P1Y2M3DT4H54M6,5S', {'PnY': '1', 'PnM': '2',
                                             'PnW': None, 'PnD': '3',
                                             'TnH': '4', 'TnM': '54',
                                             'TnS': '6.5'}),
                      ('P1Y2M3DT4H54M6.5S', {'PnY': '1', 'PnM': '2',
                                             'PnW': None, 'PnD': '3',
                                             'TnH': '4', 'TnM': '54',
                                             'TnS': '6.5'}),
                      ('PT4H54M6,5S', {'PnY': None, 'PnM': None,
                                       'PnW': None, 'PnD': None,
                                       'TnH': '4', 'TnM': '54',
                                       'TnS': '6.5'}),
                      ('PT4H54M6.5S', {'PnY': None, 'PnM': None,
                                       'PnW': None, 'PnD': None,
                                       'TnH': '4', 'TnM': '54',
                                       'TnS': '6.5'}))

        for testtuple in testtuples:
            result = _parse_duration_prescribed_time(testtuple[0])

            self.assertEqual(result, testtuple[1])
Пример #5
0
    def test_parse_duration_prescribed_time_outoforder(self):
        # Ensure durations are required to be in the correct order
        # https://bitbucket.org/nielsenb/aniso8601/issues/7/durations-with-time-components-before-t
        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("1Y2M3D1SPT1M")

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("P1Y2M3D2MT1S")

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("P2M3D1ST1Y1M")

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("P1Y2M2MT3D1S")

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("PT1S1H")
Пример #6
0
    def test_parse_duration_prescribed_time(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'
        }))

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

            result = _parse_duration_prescribed_time(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
Пример #7
0
 def test_parse_duration_prescribed_time_negative(self):
     with self.assertRaises(NegativeDurationError):
         _parse_duration_prescribed_time('P-1Y2M3DT4H54M6S', None)
    def test_parse_duration_prescribed_time(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",
                },
            ),
        )

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

            result = _parse_duration_prescribed_time(testtuple[0], mockBuilder)

            self.assertEqual(result, testtuple[1])
            mockBuilder.build_duration.assert_called_once_with(**testtuple[1])
Пример #9
0
    def test_parse_duration_prescribed_time_badstr(self):
        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("P1Y")

        with self.assertRaises(ISOFormatError):
            _parse_duration_prescribed_time("P1Y1M")
Пример #10
0
    def test_parse_duration_prescribed_time(self):
        testtuples = (
            (
                "P1Y2M3DT4H54M6S",
                {
                    "PnY": "1",
                    "PnM": "2",
                    "PnW": None,
                    "PnD": "3",
                    "TnH": "4",
                    "TnM": "54",
                    "TnS": "6",
                },
            ),
            (
                "P1Y2M3DT4H54M6,5S",
                {
                    "PnY": "1",
                    "PnM": "2",
                    "PnW": None,
                    "PnD": "3",
                    "TnH": "4",
                    "TnM": "54",
                    "TnS": "6.5",
                },
            ),
            (
                "P1Y2M3DT4H54M6.5S",
                {
                    "PnY": "1",
                    "PnM": "2",
                    "PnW": None,
                    "PnD": "3",
                    "TnH": "4",
                    "TnM": "54",
                    "TnS": "6.5",
                },
            ),
            (
                "PT4H54M6,5S",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": "4",
                    "TnM": "54",
                    "TnS": "6.5",
                },
            ),
            (
                "PT4H54M6.5S",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": "4",
                    "TnM": "54",
                    "TnS": "6.5",
                },
            ),
            (
                "PT4H",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": "4",
                    "TnM": None,
                    "TnS": None,
                },
            ),
            (
                "PT5M",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": None,
                    "TnM": "5",
                    "TnS": None,
                },
            ),
            (
                "PT6S",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": None,
                    "TnM": None,
                    "TnS": "6",
                },
            ),
            (
                "PT1H2M",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": "1",
                    "TnM": "2",
                    "TnS": None,
                },
            ),
            (
                "PT3H4S",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": "3",
                    "TnM": None,
                    "TnS": "4",
                },
            ),
            (
                "PT5M6S",
                {
                    "PnY": None,
                    "PnM": None,
                    "PnW": None,
                    "PnD": None,
                    "TnH": None,
                    "TnM": "5",
                    "TnS": "6",
                },
            ),
        )

        for testtuple in testtuples:
            result = _parse_duration_prescribed_time(testtuple[0])

            self.assertEqual(result, testtuple[1])