From 4a3197506b95a2ae79824aa50fc0f9c039d58748 Mon Sep 17 00:00:00 2001 From: Vishnu Prakash Date: Tue, 14 Jul 2026 16:09:13 +0530 Subject: [PATCH 1/2] test(datetime): cover invalid timestamp errors in nanos conversions --- tests/utils/test_datetime.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/utils/test_datetime.py b/tests/utils/test_datetime.py index e9529b6d3e..e83de662f9 100644 --- a/tests/utils/test_datetime.py +++ b/tests/utils/test_datetime.py @@ -123,6 +123,11 @@ def test_timestamp_to_nanos_unexpected_zone_offset() -> None: timestamp_to_nanos("2025-02-23T16:21:44.375612001-04:00") +def test_timestamp_to_nanos_invalid_timestamp() -> None: + with pytest.raises(ValueError, match="Invalid timestamp without zone: invalid"): + timestamp_to_nanos("invalid") + + @pytest.mark.parametrize( "timestamp, nanos", [ @@ -140,6 +145,11 @@ def test_timestamptz_to_nanos_missing_zone_offset() -> None: timestamptz_to_nanos("2025-02-23T20:21:44.375612001") +def test_timestamptz_to_nanos_invalid_timestamp() -> None: + with pytest.raises(ValueError, match="Invalid timestamp with zone: invalid"): + timestamptz_to_nanos("invalid") + + @pytest.mark.parametrize("nanos, micros", [(1510871468000001001, 1510871468000001), (-1510871468000001001, -1510871468000002)]) def test_nanos_to_micros(nanos: int, micros: int) -> None: assert micros == nanos_to_micros(nanos) From ead2f2a1d3799a55ba46671d31dc284cbcaa2aad Mon Sep 17 00:00:00 2001 From: Vishnu Prakash Date: Wed, 15 Jul 2026 11:58:13 +0530 Subject: [PATCH 2/2] test(datetime): assert full error messages --- tests/utils/test_datetime.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/utils/test_datetime.py b/tests/utils/test_datetime.py index e83de662f9..429a2f9629 100644 --- a/tests/utils/test_datetime.py +++ b/tests/utils/test_datetime.py @@ -14,6 +14,7 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +import re from datetime import datetime, time, timezone, tzinfo import pytest @@ -124,7 +125,7 @@ def test_timestamp_to_nanos_unexpected_zone_offset() -> None: def test_timestamp_to_nanos_invalid_timestamp() -> None: - with pytest.raises(ValueError, match="Invalid timestamp without zone: invalid"): + with pytest.raises(ValueError, match=re.escape("Invalid timestamp without zone: invalid (must be ISO-8601)")): timestamp_to_nanos("invalid") @@ -146,7 +147,7 @@ def test_timestamptz_to_nanos_missing_zone_offset() -> None: def test_timestamptz_to_nanos_invalid_timestamp() -> None: - with pytest.raises(ValueError, match="Invalid timestamp with zone: invalid"): + with pytest.raises(ValueError, match=re.escape("Invalid timestamp with zone: invalid (must be ISO-8601)")): timestamptz_to_nanos("invalid")