Skip to content

Commit db23e32

Browse files
committed
Support exclusion bounds in power distribution tests
This just updates the tests to use data structures that support exclusion bounds, so that once support is implemented in the actor, it would be easy to add incremental tests. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent d430343 commit db23e32

File tree

2 files changed

+143
-137
lines changed

2 files changed

+143
-137
lines changed

tests/actor/test_power_distributing.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from frequenz.sdk.actor.power_distributing.result import (
2727
Error,
2828
OutOfBound,
29+
PowerBounds,
2930
Result,
3031
Success,
3132
)
@@ -92,7 +93,7 @@ async def init_component_data(self, mockgrid: MockMicrogrid) -> None:
9293
battery.component_id,
9394
capacity=Metric(98000),
9495
soc=Metric(40, Bound(20, 80)),
95-
power=Bound(-1000, 1000),
96+
power=PowerBounds(-1000, 0, 0, 1000),
9697
)
9798
)
9899

@@ -101,7 +102,7 @@ async def init_component_data(self, mockgrid: MockMicrogrid) -> None:
101102
await mockgrid.mock_client.send(
102103
inverter_msg(
103104
inverter.component_id,
104-
power=Bound(-500, 500),
105+
power=PowerBounds(-500, 0, 0, 500),
105106
)
106107
)
107108

@@ -166,7 +167,7 @@ async def test_battery_soc_nan(self, mocker: MockerFixture) -> None:
166167
9,
167168
soc=Metric(math.nan, Bound(20, 80)),
168169
capacity=Metric(98000),
169-
power=Bound(-1000, 1000),
170+
power=PowerBounds(-1000, 0, 0, 1000),
170171
)
171172
)
172173

@@ -231,7 +232,7 @@ async def test_battery_capacity_nan(self, mocker: MockerFixture) -> None:
231232
9,
232233
soc=Metric(40, Bound(20, 80)),
233234
capacity=Metric(math.nan),
234-
power=Bound(-1000, 1000),
235+
power=PowerBounds(-1000, 0, 0, 1000),
235236
)
236237
)
237238

@@ -288,15 +289,15 @@ async def test_battery_power_bounds_nan(self, mocker: MockerFixture) -> None:
288289
await mockgrid.mock_client.send(
289290
inverter_msg(
290291
18,
291-
power=Bound(math.nan, math.nan),
292+
power=PowerBounds(math.nan, 0, 0, math.nan),
292293
)
293294
)
294295

295296
# Battery 106 should not work because both battery and inverter sends NaN
296297
await mockgrid.mock_client.send(
297298
inverter_msg(
298299
8,
299-
power=Bound(-1000, math.nan),
300+
power=PowerBounds(-1000, 0, 0, math.nan),
300301
)
301302
)
302303

@@ -305,7 +306,7 @@ async def test_battery_power_bounds_nan(self, mocker: MockerFixture) -> None:
305306
9,
306307
soc=Metric(40, Bound(20, 80)),
307308
capacity=Metric(float(98000)),
308-
power=Bound(math.nan, math.nan),
309+
power=PowerBounds(math.nan, 0, 0, math.nan),
309310
)
310311
)
311312

@@ -450,7 +451,7 @@ async def test_power_distributor_one_user_adjust_power_consume(
450451
assert isinstance(result, OutOfBound)
451452
assert result is not None
452453
assert result.request == request
453-
assert result.bound == 1000
454+
assert result.bound.inclusion_upper == 1000
454455

455456
async def test_power_distributor_one_user_adjust_power_supply(
456457
self, mocker: MockerFixture
@@ -503,7 +504,7 @@ async def test_power_distributor_one_user_adjust_power_supply(
503504
assert isinstance(result, OutOfBound)
504505
assert result is not None
505506
assert result.request == request
506-
assert result.bound == -1000
507+
assert result.bound.inclusion_lower == -1000
507508

508509
async def test_power_distributor_one_user_adjust_power_success(
509510
self, mocker: MockerFixture
@@ -760,13 +761,13 @@ async def test_force_request_battery_nan_value_non_cached(
760761
9,
761762
soc=Metric(math.nan, Bound(20, 80)),
762763
capacity=Metric(math.nan),
763-
power=Bound(-1000, 1000),
764+
power=PowerBounds(-1000, 0, 0, 1000),
764765
),
765766
battery_msg(
766767
19,
767768
soc=Metric(40, Bound(20, 80)),
768769
capacity=Metric(math.nan),
769-
power=Bound(-1000, 1000),
770+
power=PowerBounds(-1000, 0, 0, 1000),
770771
),
771772
)
772773

@@ -849,19 +850,19 @@ async def test_result() -> None:
849850
9,
850851
soc=Metric(math.nan, Bound(20, 80)),
851852
capacity=Metric(98000),
852-
power=Bound(-1000, 1000),
853+
power=PowerBounds(-1000, 0, 0, 1000),
853854
),
854855
battery_msg(
855856
19,
856857
soc=Metric(40, Bound(20, 80)),
857858
capacity=Metric(math.nan),
858-
power=Bound(-1000, 1000),
859+
power=PowerBounds(-1000, 0, 0, 1000),
859860
),
860861
battery_msg(
861862
29,
862863
soc=Metric(40, Bound(20, 80)),
863864
capacity=Metric(float(98000)),
864-
power=Bound(math.nan, math.nan),
865+
power=PowerBounds(math.nan, 0, 0, math.nan),
865866
),
866867
)
867868

0 commit comments

Comments
 (0)