-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from oemof/revision/tests
Refine tests
- Loading branch information
Showing
5 changed files
with
294 additions
and
234 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# -*- coding: utf-8 - | ||
|
||
"""Basic tests. | ||
This file is part of project oemof.network (github.com/oemof/oemof-network). | ||
SPDX-FileCopyrightText: Stephan Günther <> | ||
SPDX-FileCopyrightText: Uwe Krien <[email protected]> | ||
SPDX-FileCopyrightText: Simon Hilpert <> | ||
SPDX-FileCopyrightText: Cord Kaldemeyer <> | ||
SPDX-FileCopyrightText: Patrik Schönfeldt <[email protected]> | ||
SPDX-License-Identifier: MIT | ||
""" | ||
|
||
from oemof.network import energy_system as es | ||
from oemof.network.network import Edge | ||
from oemof.network.network.nodes import Node | ||
|
||
|
||
class TestsEnergySystem: | ||
def setup_method(self): | ||
self.es = es.EnergySystem() | ||
|
||
def test_add_nodes(self): | ||
assert not self.es.nodes | ||
|
||
node1 = Node(label="node1") | ||
self.es.add(node1) | ||
assert self.es.nodes | ||
assert node1 in self.es.nodes | ||
assert not self.es.flows() | ||
|
||
# Note that node2 is not added, but the Flow is already | ||
# registred. We do not assert the latter fact as this is not a | ||
# guaranteed functionality. | ||
node2 = Node(label="node2", inputs={node1: Edge()}) | ||
assert node2 not in self.es.nodes | ||
|
||
# When both nodes are registred, also the Flow needs to be there. | ||
self.es.add(node2) | ||
assert node2 in self.es.nodes | ||
assert (node1, node2) 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. | ||
""" | ||
node = Node(label="Node") | ||
|
||
def subscriber(sender, **kwargs): | ||
assert sender is node | ||
assert kwargs["EnergySystem"] is self.es | ||
subscriber.called = True | ||
|
||
subscriber.called = False | ||
|
||
es.EnergySystem.signals[es.EnergySystem.add].connect( | ||
subscriber, sender=node | ||
) | ||
self.es.add(node) | ||
assert subscriber.called, ( | ||
"\nExpected `subscriber.called` to be `True`.\n" | ||
"Got {}.\n" | ||
"Probable reason: `subscriber` didn't get called." | ||
).format(subscriber.called) |
File renamed without changes.
Oops, something went wrong.