diff --git a/tests/utils/test_datetime.py b/tests/utils/test_datetime.py index e9529b6d3e..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 @@ -123,6 +124,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=re.escape("Invalid timestamp without zone: invalid (must be ISO-8601)")): + timestamp_to_nanos("invalid") + + @pytest.mark.parametrize( "timestamp, nanos", [ @@ -140,6 +146,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=re.escape("Invalid timestamp with zone: invalid (must be ISO-8601)")): + 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)