From 66d09f85de6491c0b38023d4d11de18c6a6420fb Mon Sep 17 00:00:00 2001 From: Jad Chaar Date: Mon, 19 Aug 2019 16:55:24 +0300 Subject: [PATCH] Reverted version increment; added tests to get coverage to 100% --- arrow/_version.py | 2 +- arrow/parser.py | 10 ++-------- tests/parser_tests.py | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/arrow/_version.py b/arrow/_version.py index 9da2f8fcc..141826d55 100644 --- a/arrow/_version.py +++ b/arrow/_version.py @@ -1 +1 @@ -__version__ = "0.15.0" +__version__ = "0.14.5" diff --git a/arrow/parser.py b/arrow/parser.py index ea3f6c6f4..3ce85f225 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -173,7 +173,6 @@ def parse_iso(self, datetime_string): ) has_tz = len(time_parts) == 2 - has_hours = hours is not None has_minutes = minutes is not None has_seconds = seconds is not None has_subseconds = subseconds is not None @@ -188,12 +187,8 @@ def parse_iso(self, datetime_string): time_string = "HH{time_sep}mm{time_sep}ss".format(time_sep=time_sep) elif has_minutes: time_string = "HH{time_sep}mm".format(time_sep=time_sep) - elif has_hours: - time_string = "HH" else: - raise ParserError( - "Invalid time component provided. Please specify a format or provide a valid time component in the basic or extended ISO 8601 time format." - ) + time_string = "HH" if has_space_divider: formats = ["{} {}".format(f, time_string) for f in formats] @@ -366,8 +361,7 @@ def _build_datetime(parts): timestamp = parts.get("timestamp") if timestamp is not None: - tz_utc = tz.tzutc() - return datetime.fromtimestamp(timestamp, tz=tz_utc) + return datetime.fromtimestamp(timestamp, tz=tz.tzutc()) day_of_year = parts.get("day_of_year") diff --git a/tests/parser_tests.py b/tests/parser_tests.py index bd13b6eb0..7381384c7 100644 --- a/tests/parser_tests.py +++ b/tests/parser_tests.py @@ -212,6 +212,18 @@ def test_parse_timestamp(self): self.parser.parse("{:f}".format(float_timestamp), "X"), self.expected ) + # test handling of ns timestamp (arrow will round to 6 digits regardless) + self.expected = datetime.fromtimestamp(float_timestamp, tz=tz_utc) + self.assertEqual( + self.parser.parse("{:f}123".format(float_timestamp), "X"), self.expected + ) + + # test ps timestamp (arrow will round to 6 digits regardless) + self.expected = datetime.fromtimestamp(float_timestamp, tz=tz_utc) + self.assertEqual( + self.parser.parse("{:f}123456".format(float_timestamp), "X"), self.expected + ) + # NOTE: timestamps cannot be parsed from natural language strings (by removing the ^...$) because it will # break cases like "15 Jul 2000" and a format list (see issue #447) with self.assertRaises(ParserError): @@ -743,6 +755,19 @@ def test_YYYY_MM_DDTHH_mm(self): self.parser.parse_iso("2013-02-03T04:05"), datetime(2013, 2, 3, 4, 5) ) + def test_YYYY_MM_DDTHH(self): + + self.assertEqual( + self.parser.parse_iso("2013-02-03T04"), datetime(2013, 2, 3, 4) + ) + + def test_YYYY_MM_DDTHHZ(self): + + self.assertEqual( + self.parser.parse_iso("2013-02-03T04+01:00"), + datetime(2013, 2, 3, 4, tzinfo=tz.tzoffset(None, 3600)), + ) + def test_YYYY_MM_DDTHH_mm_ssZ(self): self.assertEqual(