diff --git a/tests/test_energy_system.py b/tests/test_energy_system.py new file mode 100644 index 0000000..6a789f8 --- /dev/null +++ b/tests/test_energy_system.py @@ -0,0 +1,70 @@ +# -*- 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 +SPDX-FileCopyrightText: Simon Hilpert <> +SPDX-FileCopyrightText: Cord Kaldemeyer <> +SPDX-FileCopyrightText: Patrik Schönfeldt + +SPDX-License-Identifier: MIT +""" +from itertools import chain + +from oemof.network import energy_system as es +from oemof.network.groupings import Flows +from oemof.network.groupings import FlowsWithNodes as FWNs +from oemof.network.network import Bus +from oemof.network.network.nodes import Node + + +class TestsEnergySystem: + def setup_method(self): + self.es = es.EnergySystem() + + def test_flows(self): + key = object() + ensys = es.EnergySystem(groupings=[Flows(key)]) + bus = Bus(label="A Bus") + node = Node(label="A Node", inputs={bus: None}, outputs={bus: None}) + ensys.add(bus, node) + assert ensys.groups[key] == set( + chain(bus.inputs.values(), bus.outputs.values()) + ) + + def test_flows_with_nodes(self): + key = object() + ensys = es.EnergySystem(groupings=[FWNs(key)]) + bus = Bus(label="A Bus") + node = Node(label="A Node", inputs={bus: None}, outputs={bus: None}) + ensys.add(bus, node) + assert ensys.groups[key], { + (bus, node, bus.outputs[node]), + (node, bus, node.outputs[bus]), + } + + 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) diff --git a/tests/test_groupings.py b/tests/test_groupings/test_groupings_advanced.py similarity index 100% rename from tests/test_groupings.py rename to tests/test_groupings/test_groupings_advanced.py diff --git a/tests/basic_tests.py b/tests/test_groupings/test_groupings_basic.py similarity index 78% rename from tests/basic_tests.py rename to tests/test_groupings/test_groupings_basic.py index 94f111b..7d3a8a0 100644 --- a/tests/basic_tests.py +++ b/tests/test_groupings/test_groupings_basic.py @@ -2,9 +2,7 @@ """Basic tests. -This file is part of project oemof (github.com/oemof/oemof). It's copyrighted -by the contributors recorded in the version control history of the file, -available from its original location oemof/tests/basic_tests.py +This file is part of project oemof.network (github.com/oemof/oemof-network). SPDX-FileCopyrightText: Stephan Günther <> SPDX-FileCopyrightText: Uwe Krien @@ -15,13 +13,10 @@ SPDX-License-Identifier: MIT """ from collections.abc import Iterable -from itertools import chain from pprint import pformat from oemof.network import energy_system as es from oemof.network.groupings import Entities -from oemof.network.groupings import Flows -from oemof.network.groupings import FlowsWithNodes as FWNs from oemof.network.groupings import Grouping from oemof.network.network import Bus from oemof.network.network.nodes import Node @@ -188,47 +183,3 @@ def everything(): assert everything in ensys.groups assert ensys.groups[everything] == {node} assert everything() == "everything" - - def test_flows(self): - key = object() - ensys = es.EnergySystem(groupings=[Flows(key)]) - bus = Bus(label="A Bus") - node = Node(label="A Node", inputs={bus: None}, outputs={bus: None}) - ensys.add(bus, node) - assert ensys.groups[key] == set( - chain(bus.inputs.values(), bus.outputs.values()) - ) - - def test_flows_with_nodes(self): - key = object() - ensys = es.EnergySystem(groupings=[FWNs(key)]) - bus = Bus(label="A Bus") - node = Node(label="A Node", inputs={bus: None}, outputs={bus: None}) - ensys.add(bus, node) - assert ensys.groups[key], { - (bus, node, bus.outputs[node]), - (node, bus, node.outputs[bus]), - } - - 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)