From ef73a467df9d2d6d0934b10046189664e0f5cd0b Mon Sep 17 00:00:00 2001 From: xuu33030 <268775543+xuu33030@users.noreply.github.com> Date: Wed, 16 Sep 2026 11:22:11 +0800 Subject: [PATCH] test: make datetime compliance expectations independent --- tests/test_toml_tests.py | 19 ++++++++++++++----- tests/test_utils.py | 8 ++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/tests/test_toml_tests.py b/tests/test_toml_tests.py index 667353ee..8d7adddc 100644 --- a/tests/test_toml_tests.py +++ b/tests/test_toml_tests.py @@ -1,6 +1,10 @@ import json import os +import re +from datetime import date +from datetime import datetime +from datetime import time from typing import Any from typing import Callable @@ -9,7 +13,6 @@ from tomlkit import load from tomlkit import parse from tomlkit._compat import decode -from tomlkit._utils import parse_rfc3339 from tomlkit.exceptions import TOMLKitError @@ -23,15 +26,21 @@ def to_bool(s: str) -> bool: return s == "true" +def normalize_isoformat(value: str) -> str: + # Python 3.9/3.10 require three or six fractional digits and a numeric UTC offset. + value = re.sub(r"\.(\d+)", lambda m: "." + m[1][:6].ljust(6, "0"), value) + return value.replace("Z", "+00:00") + + stypes: dict[str, Callable[[str], Any]] = { "string": str, "bool": to_bool, "integer": int, "float": float, - "datetime": parse_rfc3339, - "datetime-local": parse_rfc3339, - "date-local": parse_rfc3339, - "time-local": parse_rfc3339, + "datetime": lambda s: datetime.fromisoformat(normalize_isoformat(s)), + "datetime-local": lambda s: datetime.fromisoformat(normalize_isoformat(s)), + "date-local": date.fromisoformat, + "time-local": lambda s: time.fromisoformat(normalize_isoformat(s)), } diff --git a/tests/test_utils.py b/tests/test_utils.py index c4f96cf1..c0370850 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -20,6 +20,14 @@ "1979-05-27T07:32:00-07:00", dt(1979, 5, 27, 7, 32, 0, tzinfo=tz(td(seconds=-7 * 3600), "-07:00")), ), + ( + "1979-05-27T07:32:00+05:30", + dt(1979, 5, 27, 7, 32, 0, tzinfo=tz(td(hours=5, minutes=30))), + ), + ( + "1979-05-27T07:32:00-03:30", + dt(1979, 5, 27, 7, 32, 0, tzinfo=tz(td(hours=-3, minutes=-30))), + ), ( "1979-05-27T00:32:00.999999-07:00", dt(