From 677df693ce687bbf3185bfd2fdfea715d9916967 Mon Sep 17 00:00:00 2001 From: julien Date: Tue, 18 Feb 2014 15:36:36 +0100 Subject: Raise error when parsing year with wrong number for years Closes #12 --- iso8601/iso8601.py | 36 ++++++++++++++++++++---------------- iso8601/test_iso8601.py | 5 +++-- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/iso8601/iso8601.py b/iso8601/iso8601.py index 35dc31f..4907fbd 100644 --- a/iso8601/iso8601.py +++ b/iso8601/iso8601.py @@ -35,24 +35,28 @@ ISO8601_REGEX = re.compile( (-{0,1}(?P[0-9]{1,2})){1} (-{0,1}(?P[0-9]{1,2})){1} ( - (?P[ T]) - (?P[0-9]{2}) - (:{0,1}(?P[0-9]{2})){0,1} ( - :{0,1}(?P[0-9]{1,2}) - (\.(?P[0-9]+)){0,1} - ){0,1} - (?P - Z - | + (?P[ T]) + (?P[0-9]{2}) + (:{0,1}(?P[0-9]{2})){0,1} ( - (?P[-+]) - (?P[0-9]{2}) - :{0,1} - (?P[0-9]{2}){0,1} - ) - ){0,1} - ){0,1} + :{0,1}(?P[0-9]{1,2}) + (\.(?P[0-9]+)){0,1} + ){0,1} + (?P + Z + | + ( + (?P[-+]) + (?P[0-9]{2}) + :{0,1} + (?P[0-9]{2}){0,1} + ) + ){0,1} + ) + | + $ + ) """, re.VERBOSE ) diff --git a/iso8601/test_iso8601.py b/iso8601/test_iso8601.py index aac68bb..ffff85d 100644 --- a/iso8601/test_iso8601.py +++ b/iso8601/test_iso8601.py @@ -27,15 +27,16 @@ def test_parse_utc_different_default(): assert d == datetime.datetime(2007, 1, 1, 8, 0, 0, 0, iso8601.UTC) @pytest.mark.parametrize("invalid_date, error_string", [ - ("2013-10-", "day is out of range for month"), + ("2013-10-", "Unable to parse date string"), ("2013-", "Unable to parse date string"), ("", "Unable to parse date string"), (None, "Expecting a string"), ("23", "Unable to parse date string"), # ("131015T142533Z", "Unable to parse date string"), FIXME # ("131015", "Unable to parse date string"), FIXME - # ("2007-06-23X06:40:34.00Z", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14 FIXME + ("2007-06-23X06:40:34.00Z", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14 # ("2007-06-23 06:40:34.00Zrubbish", "Unable to parse date string"), # https://code.google.com/p/pyiso8601/issues/detail?id=14 FIXME + ("20114-01-03T01:45:49", "Unable to parse date string"), ]) def test_parse_invalid_date(invalid_date, error_string): with pytest.raises(iso8601.ParseError) as exc: -- cgit v1.2.1