Skip to content

Commit

Permalink
[2383] Adding descriptive message to ValueError
Browse files Browse the repository at this point in the history
And added test that explicitely tests the second form of UTC offset.
  • Loading branch information
Ian Murray committed May 28, 2012
1 parent d6c9e48 commit 70e58d4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ckan/lib/helpers.py
Expand Up @@ -616,7 +616,8 @@ def date_str_to_datetime(date_str):
m = re.match('(?P<seconds>\d{2})(\.(?P<microseconds>\d{6}))?$',
time_tuple[5])
if not m:
raise ValueError
raise ValueError('Unable to parse %s as seconds.microseconds' %
time_tuple[5])
seconds = int(m.groupdict().get('seconds'))
microseconds = int(m.groupdict(0).get('microseconds'))
time_tuple = time_tuple[:5] + [seconds, microseconds]
Expand Down
5 changes: 5 additions & 0 deletions ckan/tests/lib/test_helpers.py
Expand Up @@ -56,6 +56,11 @@ def test_date_str_to_datetime_with_timezone(self):
h.date_str_to_datetime,
'2008-04-13T20:40:20-01:30')

def test_date_str_to_datetime_with_timezone_without_colon(self):
assert_raises(ValueError,
h.date_str_to_datetime,
'2008-04-13T20:40:20-0130')

def test_date_str_to_datetime_with_garbage_on_end(self):
assert_raises(ValueError,
h.date_str_to_datetime,
Expand Down

0 comments on commit 70e58d4

Please sign in to comment.