Skip to content

Commit

Permalink
Refactor for improved readability
Browse files Browse the repository at this point in the history
Double use of the name es also caused an error being hard to detect.
  • Loading branch information
p-snft committed Jan 11, 2024
1 parent 4ad9e30 commit af3b0a9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 5 additions & 13 deletions tests/test_energy_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@

import pytest

from oemof.network import energy_system as es
from oemof.network.energy_system import EnergySystem
from oemof.network.network import Edge
from oemof.network.network.nodes import Node


def test_ensys_init():
node = Node("label")
ensys = es.EnergySystem(nodes=[node])
ensys = EnergySystem(nodes=[node])
assert node in ensys.nodes

with pytest.warns(FutureWarning):
ensys = es.EnergySystem(entities=[node])
ensys = EnergySystem(entities=[node])
assert node in ensys.nodes


class TestsEnergySystem:
def setup_method(self):
self.es = es.EnergySystem()
self.es = EnergySystem()

def test_add_nodes(self):
assert not self.es.nodes
Expand All @@ -54,14 +54,6 @@ def test_add_nodes(self):
assert node2 in self.es.nodes
assert (node1, node2) in self.es.flows().keys()

def test_node_access_warning(self):
node_label = "label"
self.es.add(Node(node_label))
with pytest.warns(
match="API to access nodes by label is experimental"
):
_ = es.node[node_label]

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

Expand Down Expand Up @@ -99,7 +91,7 @@ def subscriber(sender, **kwargs):

subscriber.called = False

es.EnergySystem.signals[es.EnergySystem.add].connect(
EnergySystem.signals[EnergySystem.add].connect(
subscriber, sender=node
)
self.es.add(node)
Expand Down
11 changes: 7 additions & 4 deletions tests/test_network_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import pytest

from oemof.network.energy_system import EnergySystem as EnSys
from oemof.network.energy_system import EnergySystem
from oemof.network.network import Bus
from oemof.network.network import Sink
from oemof.network.network import Source
Expand All @@ -31,7 +31,7 @@

class TestsNode:
def setup_method(self):
self.energysystem = EnSys()
self.energysystem = EnergySystem()

def test_entity_initialisation(self):
entity = Entity(label="foo")
Expand Down Expand Up @@ -328,7 +328,7 @@ def test_flow_setter(self):

class TestsEnergySystemNodesIntegration:
def setup_method(self):
self.es = EnSys()
self.es = EnergySystem()

def test_entity_registration(self):
n1 = Node(label="<B1>")
Expand All @@ -339,7 +339,10 @@ def test_entity_registration(self):
assert self.es.node["<B2>"] == n2
n3 = Node(label="<TF1>", inputs=[n1], outputs=[n2])
self.es.add(n3)
assert self.es.node["<TF1>"] == n3
with pytest.warns(
match="API to access nodes by label is experimental"
):
assert self.es.node["<TF1>"] == n3


def test_deprecated_classes():
Expand Down

0 comments on commit af3b0a9

Please sign in to comment.