Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Sylvain Leclerc <[email protected]>
  • Loading branch information
sylvlecl committed Feb 12, 2024
1 parent 81ae8b9 commit 5304a9b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/andromede/expression/port_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,13 @@ def port_field_aggregator(self, node: PortFieldAggregatorNode) -> ExpressionNode
if not isinstance(port_field_node, PortFieldNode):
raise ValueError(f"Should be a portFieldNode : {port_field_node}")

expressions = self.ports_expressions[
expressions = self.ports_expressions.get(
PortFieldKey(
self.component_id,
PortFieldId(port_field_node.port_name, port_field_node.field_name),
)
]
),
[],
)
return sum_expressions(expressions)


Expand Down
6 changes: 5 additions & 1 deletion src/andromede/study/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,11 @@ def add_component(self, component: Component) -> None:
self._components[component.id] = component

def get_component(self, component_id: str) -> Component:
return self._components[component_id]
"""
Returns the component (possibly a node) corresponding to this ID.
"""
res = self._components.get(component_id, None)
return res if res else self._nodes[component_id]

@property
def components(self) -> Iterable[Component]:
Expand Down
3 changes: 3 additions & 0 deletions tests/andromede/test_andromede.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def test_network() -> None:
network.add_arc(Arc("L", "N1", "N2"))
assert list(network.arcs) == [Arc("L", "N1", "N2")]
assert network.get_arc("L") == Arc("L", "N1", "N2")
assert network.get_component("N1") == Node(model=NODE_BALANCE_MODEL, id="N1")
with pytest.raises(KeyError):
network.get_component("unknown")


def test_basic_balance() -> None:
Expand Down

0 comments on commit 5304a9b

Please sign in to comment.