5757MODIFICATION_TIME_PB = timestamp_pb2 .Timestamp (seconds = 1672574400 )
5858ORDER = Order (
5959 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
60- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
60+ delivery_period = DeliveryPeriod (
61+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
62+ ),
6163 type = OrderType .LIMIT ,
6264 side = MarketSide .BUY ,
6365 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
8688 side = MarketSide .BUY ,
8789 execution_time = EXECUTION_TIME ,
8890 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
89- delivery_period = DeliveryPeriod (START_TIME , duration = timedelta ( minutes = 15 ) ),
91+ delivery_period = DeliveryPeriod (START_TIME , duration = DeliveryDuration . MINUTES_15 ),
9092 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
9193 quantity = Power (mw = Decimal ("5.00" )),
9294 state = TradeState .ACTIVE ,
147149 sell_delivery_area = DeliveryArea (
148150 code = "ABC" , code_type = EnergyMarketCodeType .EUROPE_EIC
149151 ),
150- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
152+ delivery_period = DeliveryPeriod (
153+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
154+ ),
151155 execution_time = EXECUTION_TIME ,
152156 price = Price (amount = Decimal ("100.00" ), currency = Currency .USD ),
153157 quantity = Power (mw = Decimal ("5.00" )),
178182PUBLIC_ORDER = PublicOrder (
179183 public_order_id = 42 ,
180184 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
181- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
185+ delivery_period = DeliveryPeriod (
186+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
187+ ),
182188 type = OrderType .LIMIT ,
183189 side = MarketSide .BUY ,
184190 price = Price (amount = Decimal ("100.00" ), currency = Currency .EUR ),
210216)
211217PUBLIC_ORDER_BOOK_FILTER = PublicOrderBookFilter (
212218 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
213- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
219+ delivery_period = DeliveryPeriod (
220+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
221+ ),
214222 side = MarketSide .SELL ,
215223)
216224PUBLIC_ORDER_BOOK_FILTER_PB = electricity_trading_pb2 .PublicOrderBookFilter (
227235GRIDPOOL_ORDER_FILTER = GridpoolOrderFilter (
228236 order_states = [OrderState .ACTIVE , OrderState .CANCELED ],
229237 side = MarketSide .BUY ,
230- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
238+ delivery_period = DeliveryPeriod (
239+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
240+ ),
231241 delivery_area = DeliveryArea (code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC ),
232242 tag = "test" ,
233243)
257267 code = "XYZ" , code_type = EnergyMarketCodeType .EUROPE_EIC
258268 ),
259269 sell_delivery_area = None ,
260- delivery_period = DeliveryPeriod (start = START_TIME , duration = timedelta (minutes = 15 )),
270+ delivery_period = DeliveryPeriod (
271+ start = START_TIME , duration = DeliveryDuration .MINUTES_15
272+ ),
261273)
262274PUBLIC_TRADE_FILTER_PB = electricity_trading_pb2 .PublicTradeFilter (
263275 states = [
@@ -429,7 +441,7 @@ def test_delivery_duration_from_pb() -> None:
429441def test_delivery_period_to_pb () -> None :
430442 """Test the client delivery period type conversions to protobuf."""
431443 assert_conversion_to_pb (
432- original = DeliveryPeriod (start = START_TIME , duration = timedelta ( minutes = 15 ) ),
444+ original = DeliveryPeriod (start = START_TIME , duration = DeliveryDuration . MINUTES_15 ),
433445 expected_pb = delivery_duration_pb2 .DeliveryPeriod (
434446 start = START_TIME_PB ,
435447 duration = delivery_duration_pb2 .DeliveryDuration .DELIVERY_DURATION_15 ,
@@ -445,30 +457,36 @@ def test_delivery_period_from_pb() -> None:
445457 start = START_TIME_PB ,
446458 duration = delivery_duration_pb2 .DeliveryDuration .DELIVERY_DURATION_15 ,
447459 ),
448- expected = DeliveryPeriod (start = START_TIME , duration = timedelta ( minutes = 15 ) ),
460+ expected = DeliveryPeriod (start = START_TIME , duration = DeliveryDuration . MINUTES_15 ),
449461 assert_func = assert_equal ,
450462 )
451463
452464
453465def test_invalid_duration_raises_value_error () -> None :
454466 """Test that an invalid duration raises a ValueError."""
455467 with pytest .raises (ValueError ):
456- DeliveryPeriod (start = datetime .now (timezone .utc ), duration = timedelta (minutes = 10 ))
468+ DeliveryPeriod (
469+ start = datetime .now (timezone .utc ),
470+ duration = DeliveryDuration .from_timedelta (timedelta (minutes = 10 )),
471+ )
457472
458473
459474def test_no_timezone_raises_value_error () -> None :
460475 """Test that a datetime without timezone raises a ValueError."""
461476 with pytest .raises (ValueError ):
462- DeliveryPeriod (start = datetime .now (), duration = timedelta (minutes = 5 ))
477+ DeliveryPeriod (
478+ start = datetime .now (),
479+ duration = DeliveryDuration .MINUTES_5 ,
480+ )
463481
464482
465- def test_invalid_timezone_converted_to_utc () -> None :
483+ def test_invalid_timezone () -> None :
466484 """Test that non-UTC timezones are converted to UTC."""
467- start = datetime . now ( timezone ( timedelta ( hours = 1 )))
468- period = DeliveryPeriod (start = start , duration = timedelta ( minutes = 5 ))
469-
470- assert period . start . tzinfo == timezone . utc
471- assert start . hour == period . start . hour + 1
485+ with pytest . raises ( ValueError ):
486+ DeliveryPeriod (
487+ start = datetime . now ( timezone ( timedelta ( hours = 1 ))),
488+ duration = DeliveryDuration . MINUTES_5 ,
489+ )
472490
473491
474492def test_delivery_area_to_pb () -> None :
0 commit comments