5858MODIFICATION_TIME_PB = timestamp_pb2 .Timestamp (seconds = 1672574400 )
5959ORDER = Order (
6060 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
61- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
61+ delivery_period = DeliveryPeriod (
62+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
63+ ),
6264 type = OrderType .LIMIT ,
6365 side = MarketSide .BUY ,
6466 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
8789 side = MarketSide .BUY ,
8890 execution_time = EXECUTION_TIME ,
8991 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
90- delivery_period = DeliveryPeriod (START_TIME , duration = timedelta ( minutes = 15 ) ),
92+ delivery_period = DeliveryPeriod (START_TIME , duration = DeliveryDuration . MINUTES_15 ),
9193 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
9294 quantity = Power (mw = Decimal ("5.00" )),
9395 state = TradeState .ACTIVE ,
148150 sell_delivery_area = DeliveryArea (
149151 code = "ABC" , code_type = EnergyMarketCodeType .EUROPE_EIC
150152 ),
151- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
153+ delivery_period = DeliveryPeriod (
154+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
155+ ),
152156 execution_time = EXECUTION_TIME ,
153157 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
154158 quantity = Power (mw = Decimal ("5.00" )),
179183PUBLIC_ORDER = PublicOrder (
180184 public_order_id = 42 ,
181185 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
182- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
186+ delivery_period = DeliveryPeriod (
187+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
188+ ),
183189 type = OrderType .LIMIT ,
184190 side = MarketSide .BUY ,
185191 price = Price (amount = Decimal ("100.00" ), currency = Currency .EUR ),
211217)
212218PUBLIC_ORDER_BOOK_FILTER = PublicOrderBookFilter (
213219 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
214- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
220+ delivery_period = DeliveryPeriod (
221+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
222+ ),
215223 side = MarketSide .SELL ,
216224)
217225PUBLIC_ORDER_BOOK_FILTER_PB = electricity_trading_pb2 .PublicOrderBookFilter (
266274 code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC
267275 ),
268276 sell_delivery_area = None ,
269- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
277+ delivery_period = DeliveryPeriod (
278+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
279+ ),
270280)
271281PUBLIC_TRADE_FILTER_PB = electricity_trading_pb2 .PublicTradeFilter (
272282 states = [
@@ -438,7 +448,7 @@ def test_delivery_duration_from_pb() -> None:
438448def test_delivery_period_to_pb () -> None :
439449 """Test the client delivery period type conversions to protobuf."""
440450 assert_conversion_to_pb (
441- original = DeliveryPeriod (start = START_TIME , duration = timedelta ( minutes = 15 ) ),
451+ original = DeliveryPeriod (start = START_TIME , duration = DeliveryDuration . MINUTES_15 ),
442452 expected_pb = delivery_duration_pb2 .DeliveryPeriod (
443453 start = START_TIME_PB ,
444454 duration = delivery_duration_pb2 .DeliveryDuration .DELIVERY_DURATION_15 ,
@@ -454,30 +464,36 @@ def test_delivery_period_from_pb() -> None:
454464 start = START_TIME_PB ,
455465 duration = delivery_duration_pb2 .DeliveryDuration .DELIVERY_DURATION_15 ,
456466 ),
457- expected = DeliveryPeriod (start = START_TIME , duration = timedelta ( minutes = 15 ) ),
467+ expected = DeliveryPeriod (start = START_TIME , duration = DeliveryDuration . MINUTES_15 ),
458468 assert_func = assert_equal ,
459469 )
460470
461471
462472def test_invalid_duration_raises_value_error () -> None :
463473 """Test that an invalid duration raises a ValueError."""
464474 with pytest .raises (ValueError ):
465- DeliveryPeriod (start = datetime .now (timezone .utc ), duration = timedelta (minutes = 10 ))
475+ DeliveryPeriod (
476+ start = datetime .now (timezone .utc ),
477+ duration = DeliveryDuration .from_timedelta (timedelta (minutes = 10 )),
478+ )
466479
467480
468481def test_no_timezone_raises_value_error () -> None :
469482 """Test that a datetime without timezone raises a ValueError."""
470483 with pytest .raises (ValueError ):
471- DeliveryPeriod (start = datetime .now (), duration = timedelta (minutes = 5 ))
484+ DeliveryPeriod (
485+ start = datetime .now (),
486+ duration = DeliveryDuration .MINUTES_5 ,
487+ )
472488
473489
474- def test_invalid_timezone_converted_to_utc () -> None :
490+ def test_invalid_timezone () -> None :
475491 """Test that non-UTC timezones are converted to UTC."""
476- start = datetime . now ( timezone ( timedelta ( hours = 1 )))
477- period = DeliveryPeriod (start = start , duration = timedelta ( minutes = 5 ))
478-
479- assert period . start . tzinfo == timezone . utc
480- assert start . hour == period . start . hour + 1
492+ with pytest . raises ( ValueError ):
493+ DeliveryPeriod (
494+ start = datetime . now ( timezone ( timedelta ( hours = 1 ))),
495+ duration = DeliveryDuration . MINUTES_5 ,
496+ )
481497
482498
483499def test_delivery_area_to_pb () -> None :
0 commit comments