Skip to content

Commit

Permalink
Merge pull request #26 from oemof/revision/tests
Browse files Browse the repository at this point in the history
Refine tests
  • Loading branch information
p-snft authored Sep 28, 2023
2 parents 743cfa3 + cd040ca commit d5533fa
Show file tree
Hide file tree
Showing 5 changed files with 294 additions and 234 deletions.
234 changes: 0 additions & 234 deletions tests/basic_tests.py

This file was deleted.

66 changes: 66 additions & 0 deletions tests/test_energy_system.py
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.
Loading

0 comments on commit d5533fa

Please sign in to comment.