Skip to content

Commit b9fc5fa

Browse files
committed
Fix new failing datetime lint checks
We now require using timezone-aware datetime objects, so we can't use a plain `.now()` which is timezone-naive. Instead we build the object from a ISO string, which is also closer to a real use case, where we receive an external timestamp. Signed-off-by: Leandro Lucarella <luca-frequenz@llucax.com>
1 parent 81940ad commit b9fc5fa

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tests/test_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
# Set up some constants for reusability
5151
START_TIME = datetime.fromisoformat("2023-01-01T12:00:00+00:00")
52+
START_TIME_NO_TZ = datetime.fromisoformat("2023-01-01T12:00:00")
5253
START_TIME_PB = timestamp_pb2.Timestamp(seconds=1672574400)
5354
EXECUTION_TIME = datetime.fromisoformat("2024-01-03T10:00:00+00:00")
5455
EXECUTION_TIME_PB = timestamp_pb2.Timestamp(seconds=1704276000)
@@ -482,7 +483,7 @@ def test_no_timezone_raises_value_error() -> None:
482483
"""Test that a datetime without timezone raises a ValueError."""
483484
with pytest.raises(ValueError):
484485
DeliveryPeriod(
485-
start=datetime.now(),
486+
start=START_TIME_NO_TZ,
486487
duration=DeliveryDuration.MINUTES_5,
487488
)
488489

@@ -615,8 +616,8 @@ def test_order_detail_no_timezone_error() -> None:
615616
),
616617
open_quantity=Power(mw=Decimal("5.00")),
617618
filled_quantity=Power(mw=Decimal("0.00")),
618-
create_time=datetime.now(),
619-
modification_time=datetime.now(),
619+
create_time=START_TIME_NO_TZ,
620+
modification_time=START_TIME_NO_TZ,
620621
)
621622

622623

0 commit comments

Comments
 (0)