def test_build_timezone(self): testtuples = (({}, TimezoneTuple(None, None, None, None, '')), ({ 'negative': False, 'Z': True, 'name': 'UTC' }, TimezoneTuple(False, True, None, None, 'UTC')), ({ 'negative': False, 'Z': False, 'hh': '1', 'mm': '2', 'name': '+01:02' }, TimezoneTuple(False, False, '1', '2', '+01:02')), ({ 'negative': True, 'Z': False, 'hh': '1', 'mm': '2', 'name': '-01:02' }, TimezoneTuple(True, False, '1', '2', '-01:02'))) for testtuple in testtuples: result = TupleBuilder.build_timezone(**testtuple[0]) self.assertEqual(result, testtuple[1])
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])
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])
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])
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])
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])
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': TimezoneTuple(False, None, '00', '00', '+00:00') } 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': TimezoneTuple(False, None, '11', '15', '+11:15') } 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)
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": TimezoneTuple(False, None, "00", "00", "+00:00"), } 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": TimezoneTuple(False, None, "11", "15", "+11:15"), } 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)
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])
def test_build_timezone(self): testtuples = ( ({}, TimezoneTuple(None, None, None, None, "")), ( { "negative": False, "Z": True, "name": "UTC" }, TimezoneTuple(False, True, None, None, "UTC"), ), ( { "negative": False, "Z": False, "hh": "1", "mm": "2", "name": "+01:02" }, TimezoneTuple(False, False, "1", "2", "+01:02"), ), ( { "negative": True, "Z": False, "hh": "1", "mm": "2", "name": "-01:02" }, TimezoneTuple(True, False, "1", "2", "-01:02"), ), ) for testtuple in testtuples: result = TupleBuilder.build_timezone(**testtuple[0]) self.assertEqual(result, testtuple[1])
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)
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)
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)
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)
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)
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)
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])
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])
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])
def test_parse_time(self): testtuples = ( ("01:23:45", {"hh": "01", "mm": "23", "ss": "45", "tz": None}), ("24:00:00", {"hh": "24", "mm": "00", "ss": "00", "tz": None}), ( "23:21:28,512400", {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None}, ), ( "23:21:28.512400", {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None}, ), ( "01:03:11.858714", {"hh": "01", "mm": "03", "ss": "11.858714", "tz": None}, ), ( "14:43:59.9999997", {"hh": "14", "mm": "43", "ss": "59.9999997", "tz": None}, ), ("01:23", {"hh": "01", "mm": "23", "ss": None, "tz": None}), ("24:00", {"hh": "24", "mm": "00", "ss": None, "tz": None}), ("01:23,4567", {"hh": "01", "mm": "23.4567", "ss": None, "tz": None}), ("01:23.4567", {"hh": "01", "mm": "23.4567", "ss": None, "tz": None}), ("012345", {"hh": "01", "mm": "23", "ss": "45", "tz": None}), ("240000", {"hh": "24", "mm": "00", "ss": "00", "tz": None}), ("232128,512400", {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None}), ("232128.512400", {"hh": "23", "mm": "21", "ss": "28.512400", "tz": None}), ("010311.858714", {"hh": "01", "mm": "03", "ss": "11.858714", "tz": None}), ( "144359.9999997", {"hh": "14", "mm": "43", "ss": "59.9999997", "tz": None}, ), ("0123", {"hh": "01", "mm": "23", "ss": None, "tz": None}), ("2400", {"hh": "24", "mm": "00", "ss": None, "tz": None}), ("01", {"hh": "01", "mm": None, "ss": None, "tz": None}), ("24", {"hh": "24", "mm": None, "ss": None, "tz": None}), ("12,5", {"hh": "12.5", "mm": None, "ss": None, "tz": None}), ("12.5", {"hh": "12.5", "mm": None, "ss": None, "tz": None}), ( "232128,512400+00:00", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "232128.512400+00:00", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "0123,4567+00:00", { "hh": "01", "mm": "23.4567", "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "0123.4567+00:00", { "hh": "01", "mm": "23.4567", "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "01,4567+00:00", { "hh": "01.4567", "mm": None, "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "01.4567+00:00", { "hh": "01.4567", "mm": None, "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "01:23:45+00:00", { "hh": "01", "mm": "23", "ss": "45", "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "24:00:00+00:00", { "hh": "24", "mm": "00", "ss": "00", "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "23:21:28.512400+00:00", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "01:23+00:00", { "hh": "01", "mm": "23", "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "24:00+00:00", { "hh": "24", "mm": "00", "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "01:23.4567+00:00", { "hh": "01", "mm": "23.4567", "ss": None, "tz": TimezoneTuple(False, None, "00", "00", "+00:00"), }, ), ( "23:21:28.512400+11:15", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(False, None, "11", "15", "+11:15"), }, ), ( "23:21:28.512400-12:34", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(True, None, "12", "34", "-12:34"), }, ), ( "23:21:28.512400Z", { "hh": "23", "mm": "21", "ss": "28.512400", "tz": TimezoneTuple(False, True, None, None, "Z"), }, ), ( "06:14:00.000123Z", { "hh": "06", "mm": "14", "ss": "00.000123", "tz": TimezoneTuple(False, True, None, None, "Z"), }, ), ) for testtuple in testtuples: with mock.patch.object( aniso8601.time.PythonTimeBuilder, "build_time" ) as mockBuildTime: mockBuildTime.return_value = testtuple[1] result = parse_time(testtuple[0]) self.assertEqual(result, testtuple[1]) mockBuildTime.assert_called_once_with(**testtuple[1])
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])
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])
def test_parse_time(self): testtuples = (('01:23:45', { 'hh': '01', 'mm': '23', 'ss': '45', 'tz': None }), ('24:00:00', { 'hh': '24', 'mm': '00', 'ss': '00', 'tz': None }), ('23:21:28,512400', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': None }), ('23:21:28.512400', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': None }), ('01:03:11.858714', { 'hh': '01', 'mm': '03', 'ss': '11.858714', 'tz': None }), ('14:43:59.9999997', { 'hh': '14', 'mm': '43', 'ss': '59.9999997', 'tz': None }), ('01:23', { 'hh': '01', 'mm': '23', 'ss': None, 'tz': None }), ('24:00', { 'hh': '24', 'mm': '00', 'ss': None, 'tz': None }), ('01:23,4567', { 'hh': '01', 'mm': '23.4567', 'ss': None, 'tz': None }), ('01:23.4567', { 'hh': '01', 'mm': '23.4567', 'ss': None, 'tz': None }), ('012345', { 'hh': '01', 'mm': '23', 'ss': '45', 'tz': None }), ('240000', { 'hh': '24', 'mm': '00', 'ss': '00', 'tz': None }), ('232128,512400', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': None }), ('232128.512400', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': None }), ('010311.858714', { 'hh': '01', 'mm': '03', 'ss': '11.858714', 'tz': None }), ('144359.9999997', { 'hh': '14', 'mm': '43', 'ss': '59.9999997', 'tz': None }), ('0123', { 'hh': '01', 'mm': '23', 'ss': None, 'tz': None }), ('2400', { 'hh': '24', 'mm': '00', 'ss': None, 'tz': None }), ('01', { 'hh': '01', 'mm': None, 'ss': None, 'tz': None }), ('24', { 'hh': '24', 'mm': None, 'ss': None, 'tz': None }), ('12,5', { 'hh': '12.5', 'mm': None, 'ss': None, 'tz': None }), ('12.5', { 'hh': '12.5', 'mm': None, 'ss': None, 'tz': None }), ('232128,512400+00:00', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('232128.512400+00:00', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('0123,4567+00:00', { 'hh': '01', 'mm': '23.4567', 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('0123.4567+00:00', { 'hh': '01', 'mm': '23.4567', 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('01,4567+00:00', { 'hh': '01.4567', 'mm': None, 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('01.4567+00:00', { 'hh': '01.4567', 'mm': None, 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('01:23:45+00:00', { 'hh': '01', 'mm': '23', 'ss': '45', 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('24:00:00+00:00', { 'hh': '24', 'mm': '00', 'ss': '00', 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('23:21:28.512400+00:00', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('01:23+00:00', { 'hh': '01', 'mm': '23', 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('24:00+00:00', { 'hh': '24', 'mm': '00', 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('01:23.4567+00:00', { 'hh': '01', 'mm': '23.4567', 'ss': None, 'tz': TimezoneTuple(False, None, '00', '00', '+00:00') }), ('23:21:28.512400+11:15', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(False, None, '11', '15', '+11:15') }), ('23:21:28.512400-12:34', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(True, None, '12', '34', '-12:34') }), ('23:21:28.512400Z', { 'hh': '23', 'mm': '21', 'ss': '28.512400', 'tz': TimezoneTuple(False, True, None, None, 'Z') }), ('06:14:00.000123Z', { 'hh': '06', 'mm': '14', 'ss': '00.000123', 'tz': TimezoneTuple(False, True, None, None, 'Z') })) for testtuple in testtuples: with mock.patch.object(aniso8601.time.PythonTimeBuilder, 'build_time') as mockBuildTime: mockBuildTime.return_value = testtuple[1] result = parse_time(testtuple[0]) self.assertEqual(result, testtuple[1]) mockBuildTime.assert_called_once_with(**testtuple[1])
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])