Skip to content

Commit ceba590

Browse files
committed
Replace old Components with specific classes in tests
Many tests build mock components, so now this components need to be created as concrete subclasses of `Component`. Some test also has some minor readability improvements. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 6ad9cb1 commit ceba590

File tree

7 files changed

+922
-946
lines changed

7 files changed

+922
-946
lines changed

tests/microgrid/test_data_sourcing.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,21 @@
1212
import pytest
1313
import pytest_mock
1414
from frequenz.channels import Broadcast
15+
from frequenz.client.common.microgrid import MicrogridId
1516
from frequenz.client.common.microgrid.components import ComponentId
1617
from frequenz.client.microgrid import (
1718
BatteryComponentState,
1819
BatteryRelayState,
19-
Component,
20-
ComponentCategory,
2120
EVChargerCableState,
2221
EVChargerComponentState,
2322
InverterComponentState,
2423
)
24+
from frequenz.client.microgrid.component import (
25+
BatteryInverter,
26+
DcEvCharger,
27+
LiIonBattery,
28+
Meter,
29+
)
2530
from frequenz.client.microgrid.metrics import Metric
2631
from frequenz.quantities import Quantity
2732

@@ -41,6 +46,8 @@
4146

4247
T = TypeVar("T", bound=ComponentData)
4348

49+
_MICROGRID_ID = MicrogridId(1)
50+
4451

4552
@pytest.fixture
4653
def mock_connection_manager(mocker: pytest_mock.MockFixture) -> mock.Mock:
@@ -49,12 +56,10 @@ def mock_connection_manager(mocker: pytest_mock.MockFixture) -> mock.Mock:
4956
mock_client.list_components = mock.AsyncMock(
5057
name="list_components()",
5158
return_value=[
52-
Component(component_id=ComponentId(4), category=ComponentCategory.METER),
53-
Component(component_id=ComponentId(6), category=ComponentCategory.INVERTER),
54-
Component(component_id=ComponentId(9), category=ComponentCategory.BATTERY),
55-
Component(
56-
component_id=ComponentId(12), category=ComponentCategory.EV_CHARGER
57-
),
59+
Meter(id=ComponentId(4), microgrid_id=_MICROGRID_ID),
60+
BatteryInverter(id=ComponentId(6), microgrid_id=_MICROGRID_ID),
61+
LiIonBattery(id=ComponentId(9), microgrid_id=_MICROGRID_ID),
62+
DcEvCharger(id=ComponentId(12), microgrid_id=_MICROGRID_ID),
5863
],
5964
)
6065

tests/microgrid/test_datapipeline.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
import async_solipsism
1010
import pytest
1111
import time_machine
12+
from frequenz.client.common.microgrid import MicrogridId
1213
from frequenz.client.common.microgrid.components import ComponentId
13-
from frequenz.client.microgrid import (
14-
Component,
15-
ComponentCategory,
16-
InverterType,
17-
)
1814
from frequenz.client.microgrid.component import (
15+
BatteryInverter,
1916
ComponentConnection,
17+
GridConnectionPoint,
18+
LiIonBattery,
2019
)
2120
from pytest_mock import MockerFixture
2221

@@ -32,6 +31,9 @@ def event_loop_policy() -> async_solipsism.EventLoopPolicy:
3231
return async_solipsism.EventLoopPolicy()
3332

3433

34+
_MICROGRID_ID = MicrogridId(1)
35+
36+
3537
# loop time is advanced but not the system time
3638
async def test_actors_started(
3739
fake_time: time_machine.Coordinates, mocker: MockerFixture
@@ -61,15 +63,16 @@ async def test_actors_started(
6163

6264
assert datapipeline._battery_power_wrapper._power_distributing_actor is None
6365

66+
grid_1 = GridConnectionPoint(
67+
id=ComponentId(1), microgrid_id=_MICROGRID_ID, rated_fuse_current=10_000
68+
)
69+
bat_inverter_4 = BatteryInverter(id=ComponentId(4), microgrid_id=_MICROGRID_ID)
70+
battery_15 = LiIonBattery(id=ComponentId(15), microgrid_id=_MICROGRID_ID)
6471
mock_client = MockMicrogridClient(
65-
{
66-
Component(ComponentId(1), ComponentCategory.GRID),
67-
Component(ComponentId(4), ComponentCategory.INVERTER, InverterType.BATTERY),
68-
Component(ComponentId(15), ComponentCategory.BATTERY),
69-
},
72+
components={grid_1, bat_inverter_4, battery_15},
7073
connections={
71-
ComponentConnection(source=ComponentId(1), destination=ComponentId(4)),
72-
ComponentConnection(source=ComponentId(4), destination=ComponentId(15)),
74+
ComponentConnection(source=grid_1.id, destination=bat_inverter_4.id),
75+
ComponentConnection(source=bat_inverter_4.id, destination=battery_15.id),
7376
},
7477
)
7578
mock_client.initialize(mocker)

0 commit comments

Comments
 (0)