diff options
-rw-r--r-- | fastimport/dates.py | 9 | ||||
-rw-r--r-- | fastimport/parser.py | 8 | ||||
-rw-r--r-- | fastimport/tests/__init__.py | 1 | ||||
-rw-r--r-- | fastimport/tests/test_dates.py | 31 |
4 files changed, 43 insertions, 6 deletions
diff --git a/fastimport/dates.py b/fastimport/dates.py index c467ff7..c0cf400 100644 --- a/fastimport/dates.py +++ b/fastimport/dates.py @@ -35,18 +35,21 @@ def parse_raw(s, lineno=0): """ timestamp_str, timezone_str = s.split(' ', 1) timestamp = float(timestamp_str) - timezone = _parse_tz(timezone_str, lineno) + try: + timezone = parse_tz(timezone_str) + except ValueError: + raise errors.InvalidTimezone(lineno, timezone_str) return timestamp, timezone -def _parse_tz(tz, lineno): +def parse_tz(tz): """Parse a timezone specification in the [+|-]HHMM format. :return: the timezone offset in seconds. """ # from git_repository.py in bzr-git if len(tz) != 5: - raise errors.InvalidTimezone(lineno, tz) + raise ValueError(tz) sign = {'+': +1, '-': -1}[tz[0]] hours = int(tz[1:3]) minutes = int(tz[3:]) diff --git a/fastimport/parser.py b/fastimport/parser.py index ca8e294..88eecfa 100644 --- a/fastimport/parser.py +++ b/fastimport/parser.py @@ -162,9 +162,11 @@ The grammar is: import re import sys -import commands -import dates -import errors +from fastimport import ( + commands, + dates, + errors, + ) ## Stream parsing ## diff --git a/fastimport/tests/__init__.py b/fastimport/tests/__init__.py index 49fbbac..1d3a09e 100644 --- a/fastimport/tests/__init__.py +++ b/fastimport/tests/__init__.py @@ -23,6 +23,7 @@ import unittest def test_suite(): names = [ 'test_commands', + 'test_dates', 'test_errors', 'test_filter_processor', 'test_helpers', diff --git a/fastimport/tests/test_dates.py b/fastimport/tests/test_dates.py new file mode 100644 index 0000000..109318c --- /dev/null +++ b/fastimport/tests/test_dates.py @@ -0,0 +1,31 @@ +# Copyright (C) 2012 Canonical Ltd +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +"""Test parsing of dates.""" + +from testtools import TestCase + +from fastimport import ( + dates, + ) + +class ParseTzTests(TestCase): + + def test_parse_tz_utc(self): + self.assertEquals(0, dates.parse_tz("+0000")) + self.assertEquals(0, dates.parse_tz("-0000")) + + def test_parse_tz_cet(self): + self.assertEquals(3600, dates.parse_tz("+0100")) |