Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for API to add Flows between existing Nodes #28

Merged
merged 10 commits into from
Oct 10, 2023
9 changes: 9 additions & 0 deletions src/oemof/network/network/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,18 @@ class Node(Entity):
inputs: list or dict, optional
Either a list of this nodes' input nodes or a dictionary mapping input
nodes to corresponding inflows (i.e. input values).
List will be converted to dictionary with values set to None.
outputs: list or dict, optional
Either a list of this nodes' output nodes or a dictionary mapping
output nodes to corresponding outflows (i.e. output values).
List will be converted to dictionary with values set to None.

Attributes
----------
inputs: dict
A dictionary mapping input nodes to corresponding inflows.
outputs: dict
A dictionary mapping output nodes to corresponding outflows.
"""

def __init__(self, *args, **kwargs):
Expand Down
24 changes: 24 additions & 0 deletions tests/test_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ def test_add_nodes(self):
assert node2 in self.es.nodes
assert (node1, node2) in self.es.flows().keys()

def test_add_flow_assignment(self):
assert not self.es.nodes

node0 = Node(label="node0")
node1 = Node(label="node1")
node2 = Node(label="node2", inputs={node0: Edge()})

self.es.add(node0, node1, node2)

assert (node0, node2) in self.es.flows().keys()
assert (node1, node2) not in self.es.flows().keys()
assert (node2, node1) not in self.es.flows().keys()

node2.inputs[node1] = Edge()

assert (node0, node2) in self.es.flows().keys()
assert (node1, node2) in self.es.flows().keys()
assert (node2, node1) not in self.es.flows().keys()

node2.outputs[node1] = Edge()
assert (node0, node2) in self.es.flows().keys()
assert (node1, node2) in self.es.flows().keys()
assert (node2, node1) in self.es.flows().keys()

def test_that_node_additions_are_signalled(self):
"""
When a node gets `add`ed, a corresponding signal should be emitted.
Expand Down
Loading