Skip to content

Commit 018e176

Browse files
committed
Remove hardcoded component graph and fixtures
These are now unused because tests have migrated to use dynamic component graphs provided by MockMicrogrid. Signed-off-by: Sahas Subramanian <[email protected]>
1 parent 1c8f58b commit 018e176

File tree

3 files changed

+4
-116
lines changed

3 files changed

+4
-116
lines changed

tests/actor/test_battery_pool_status.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import asyncio
66
from typing import Set
77

8-
import pytest
98
from frequenz.channels import Broadcast
109
from pytest_mock import MockerFixture
1110

@@ -16,29 +15,13 @@
1615
from frequenz.sdk.microgrid.component import ComponentCategory
1716
from tests.timeseries.mock_microgrid import MockMicrogrid
1817

19-
from ..utils.mock_microgrid_client import MockMicrogridClient
20-
from .test_battery_status import battery_data, component_graph, inverter_data
18+
from .test_battery_status import battery_data, inverter_data
2119

2220

2321
# pylint: disable=protected-access
2422
class TestBatteryPoolStatus:
2523
"""Tests for BatteryPoolStatus"""
2624

27-
@pytest.fixture
28-
async def mock_microgrid(self, mocker: MockerFixture) -> MockMicrogridClient:
29-
"""Create and initialize mock microgrid
30-
31-
Args:
32-
mocker: pytest mocker
33-
34-
Returns:
35-
MockMicrogridClient
36-
"""
37-
components, connections = component_graph()
38-
microgrid = MockMicrogridClient(components, connections)
39-
microgrid.initialize(mocker)
40-
return microgrid
41-
4225
async def test_batteries_status(self, mocker: MockerFixture) -> None:
4326
"""Basic tests for BatteryPoolStatus.
4427

tests/actor/test_battery_status.py

Lines changed: 2 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import math
77
from dataclasses import dataclass
88
from datetime import datetime, timedelta, timezone
9-
from typing import Generic, Iterable, List, Optional, Set, Tuple, TypeVar
9+
from typing import Generic, Iterable, List, Optional, TypeVar
1010

11-
import pytest
1211
import time_machine
1312
from frequenz.api.microgrid.battery_pb2 import ComponentState as BatteryState
1413
from frequenz.api.microgrid.battery_pb2 import Error as BatteryError
@@ -26,17 +25,10 @@
2625
SetPowerResult,
2726
Status,
2827
)
29-
from frequenz.sdk.microgrid.client import Connection
30-
from frequenz.sdk.microgrid.component import (
31-
BatteryData,
32-
Component,
33-
ComponentCategory,
34-
InverterData,
35-
)
28+
from frequenz.sdk.microgrid.component import BatteryData, InverterData
3629
from tests.timeseries.mock_microgrid import MockMicrogrid
3730

3831
from ..utils.component_data_wrapper import BatteryDataWrapper, InverterDataWrapper
39-
from ..utils.mock_microgrid_client import MockMicrogridClient
4032

4133

4234
def battery_data( # pylint: disable=too-many-arguments
@@ -109,42 +101,6 @@ def inverter_data(
109101
)
110102

111103

112-
def component_graph() -> Tuple[Set[Component], Set[Connection]]:
113-
"""Creates components and connections for the microgrid component graph.
114-
115-
Returns:
116-
Tuple with set of components and set of connections.
117-
"""
118-
components = {
119-
Component(1, ComponentCategory.GRID),
120-
Component(2, ComponentCategory.METER),
121-
Component(104, ComponentCategory.METER),
122-
Component(105, ComponentCategory.INVERTER),
123-
Component(106, ComponentCategory.BATTERY),
124-
Component(204, ComponentCategory.METER),
125-
Component(205, ComponentCategory.INVERTER),
126-
Component(206, ComponentCategory.BATTERY),
127-
Component(304, ComponentCategory.METER),
128-
Component(305, ComponentCategory.INVERTER),
129-
Component(306, ComponentCategory.BATTERY),
130-
}
131-
132-
connections = {
133-
Connection(1, 2),
134-
Connection(2, 104),
135-
Connection(104, 105),
136-
Connection(105, 106),
137-
Connection(2, 204),
138-
Connection(204, 205),
139-
Connection(205, 206),
140-
Connection(2, 304),
141-
Connection(304, 305),
142-
Connection(305, 306),
143-
}
144-
145-
return components, connections
146-
147-
148104
T = TypeVar("T")
149105

150106

@@ -163,21 +119,6 @@ class Message(Generic[T]):
163119
class TestBatteryStatus:
164120
"""Tests BatteryStatusTracker."""
165121

166-
@pytest.fixture
167-
async def mock_microgrid(self, mocker: MockerFixture) -> MockMicrogridClient:
168-
"""Create and initialize mock microgrid
169-
170-
Args:
171-
mocker: pytest mocker
172-
173-
Returns:
174-
MockMicrogridClient
175-
"""
176-
components, connections = component_graph()
177-
microgrid = MockMicrogridClient(components, connections)
178-
microgrid.initialize(mocker)
179-
return microgrid
180-
181122
@time_machine.travel("2022-01-01 00:00 UTC", tick=False)
182123
async def test_sync_update_status_with_messages(
183124
self, mocker: MockerFixture

tests/actor/test_power_distributing.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
Result,
3030
Success,
3131
)
32-
from frequenz.sdk.microgrid.client import Connection
33-
from frequenz.sdk.microgrid.component import Component, ComponentCategory
32+
from frequenz.sdk.microgrid.component import ComponentCategory
3433
from tests.timeseries.mock_microgrid import MockMicrogrid
3534

3635
from ..conftest import SAFETY_TIMEOUT
@@ -45,41 +44,6 @@ class TestPowerDistributingActor:
4544

4645
_namespace = "power_distributor"
4746

48-
def component_graph(self) -> tuple[set[Component], set[Connection]]:
49-
"""Create graph components
50-
51-
Returns:
52-
Tuple where first element is set of components and second element is
53-
set of connections.
54-
"""
55-
components = {
56-
Component(1, ComponentCategory.GRID),
57-
Component(2, ComponentCategory.METER),
58-
Component(104, ComponentCategory.METER),
59-
Component(105, ComponentCategory.INVERTER),
60-
Component(106, ComponentCategory.BATTERY),
61-
Component(204, ComponentCategory.METER),
62-
Component(205, ComponentCategory.INVERTER),
63-
Component(206, ComponentCategory.BATTERY),
64-
Component(304, ComponentCategory.METER),
65-
Component(305, ComponentCategory.INVERTER),
66-
Component(306, ComponentCategory.BATTERY),
67-
}
68-
69-
connections = {
70-
Connection(1, 2),
71-
Connection(2, 104),
72-
Connection(104, 105),
73-
Connection(105, 106),
74-
Connection(2, 204),
75-
Connection(204, 205),
76-
Connection(205, 206),
77-
Connection(2, 304),
78-
Connection(304, 305),
79-
Connection(305, 306),
80-
}
81-
return components, connections
82-
8347
async def test_constructor(self, mocker: MockerFixture) -> None:
8448
"""Test if gets all necessary data."""
8549
mockgrid = MockMicrogrid(grid_side_meter=True)

0 commit comments

Comments
 (0)