Skip to content

Commit

Permalink
Merge pull request #28 from oemof/features/add_flows
Browse files Browse the repository at this point in the history
Add tests for API to add Flows between existing Nodes
  • Loading branch information
p-snft authored Oct 10, 2023
2 parents 2c298a7 + a50ad84 commit c81809d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
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

0 comments on commit c81809d

Please sign in to comment.