Skip to content

Commit 5eec9d2

Browse files
committed
fix linting + improvements
Signed-off-by: Vincent Koppen <[email protected]>
1 parent 8443774 commit 5eec9d2

File tree

2 files changed

+8
-20
lines changed

2 files changed

+8
-20
lines changed

src/power_grid_model_ds/_core/power_grid_model_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def create_grid_from_input_data(self, check_ids: bool = True) -> Grid:
7474
Returns a Grid object with the arrays filled with the PowerGridModel input.
7575
"""
7676
for pgm_name in ComponentType:
77-
if pgm_name in self._input_data and hasattr(self.grid, pgm_name):
77+
if pgm_name in self._input_data:
7878
pgm_ds_array_class = getattr(self.grid, pgm_name).__class__
7979
pgm_ds_array = pgm_ds_array_class(self._input_data[pgm_name])
8080
self.grid.append(pgm_ds_array, check_max_id=False)

tests/integration/loadflow/test_power_grid_model.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def test_grid_with_automatic_tap_regulator(self, grid_with_tap_regulator: Grid):
115115
assert output["transformer_tap_regulator"]["tap_pos"][0] > 0
116116

117117

118-
ExtendedComponentType = StrEnum("ExtendedComponentType", {x.name: x.value for x in ComponentType} | {"onzin": "onzin"})
118+
ExtendedComponentType = StrEnum( # type: ignore
119+
"ExtendedComponentType",
120+
{component.name: component.value for component in ComponentType} | {"DUMMY_EXTRA_COMPONENT": "dummy"},
121+
)
119122

120123

121124
class TestPowerGridModelInterfaceMethods:
@@ -126,10 +129,13 @@ def test_update_grid(self):
126129
grid.node = ExtendedNodeArray(grid.node.data)
127130
grid.line = ExtendedLineArray(grid.line.data)
128131

132+
# Patch ComponentType to include a value that is not present in the grid as an attribute
129133
with patch("power_grid_model_ds._core.power_grid_model_interface.ComponentType", ExtendedComponentType):
130134
core_interface = PowerGridModelInterface(grid=grid)
131135
core_interface.create_input_from_grid()
132136
core_interface.calculate_power_flow()
137+
# Mock additional component type that is not in the grid
138+
core_interface.output_data["dummy"] = np.array([])
133139
core_interface.update_grid()
134140

135141
grid = core_interface.grid
@@ -139,24 +145,6 @@ def test_update_grid(self):
139145
# all lines have a current
140146
assert all(grid.line.i_from > 0)
141147

142-
# def test_update_grid_missing_component(self, core_interface_after_loadflow: PowerGridModelInterface):
143-
# """Test that update grid works when a component is missing in the grid."""
144-
# del core_interface_after_loadflow.grid.source
145-
146-
# core_interface_after_loadflow.update_grid()
147-
148-
# # voltage should be in neighbourhood of 10500
149-
# grid = core_interface_after_loadflow.grid
150-
# assert not all(grid.node.is_empty("u"))
151-
# assert not hasattr(grid, "source")
152-
153-
def test_input_from_grid_missing_component(self, grid: Grid):
154-
# Mimic no source in grid
155-
del grid.source
156-
157-
core_interface = PowerGridModelInterface(grid=grid)
158-
assert "source" not in core_interface.create_input_from_grid()
159-
160148
def test_update_model(self):
161149
"""Test whether a pgm model can be updated and returns different results"""
162150
grid_generator = RadialGridGenerator(grid_class=Grid, nr_nodes=5, nr_sources=1, nr_nops=0)

0 commit comments

Comments
 (0)