Skip to content

Commit

Permalink
Merge pull request #31 from oemof/revision/deprecate_node_child_classes
Browse files Browse the repository at this point in the history
Deprecate child classes of Node
  • Loading branch information
p-snft authored Oct 10, 2023
2 parents c81809d + 2e2a562 commit dc5e751
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
21 changes: 19 additions & 2 deletions src/oemof/network/network/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
SPDX-License-Identifier: MIT
"""

import warnings

from .edge import Edge
from .entity import Entity

Expand Down Expand Up @@ -68,12 +70,27 @@ def __init__(self, *args, **kwargs):
edge.output = o


_deprecation_warning = (
"Usage of {} is deprecated. Use oemof.network.Node instead."
)


class Bus(Node):
pass
def __init__(self, *args, **kwargs):
warnings.warn(
_deprecation_warning.format(type(self)),
FutureWarning,
)
super().__init__(*args, **kwargs)


class Component(Node):
pass
def __init__(self, *args, **kwargs):
warnings.warn(
_deprecation_warning.format(type(self)),
FutureWarning,
)
super().__init__(*args, **kwargs)


class Sink(Component):
Expand Down
35 changes: 24 additions & 11 deletions tests/test_network_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

from oemof.network.energy_system import EnergySystem as EnSys
from oemof.network.network import Bus
from oemof.network.network import Sink
from oemof.network.network import Source
from oemof.network.network import Transformer
from oemof.network.network.edge import Edge
from oemof.network.network.entity import Entity
Expand Down Expand Up @@ -124,7 +126,7 @@ def test_that_nodes_do_not_get_undead_flows(self):
"""
flow = object()
old = Node(label="A reused label")
bus = Bus(label="bus", inputs={old: flow})
bus = Node(label="bus", inputs={old: flow})
assert bus.inputs[old].flow == flow, (
("\n Expected: {0}" + "\n Got : {1} instead").format(
flow, bus.inputs[old].flow
Expand Down Expand Up @@ -172,7 +174,7 @@ def test_modifying_outputs_after_construction(self):
def test_modifying_inputs_after_construction(self):
"""One should be able to add and delete inputs of a node."""
node = Node("N1")
bus = Bus("N2")
bus = Node("N2")
flow = "flow"

assert node.inputs == {}, (
Expand Down Expand Up @@ -329,12 +331,23 @@ def setup_method(self):
self.es = EnSys()

def test_entity_registration(self):
b1 = Bus(label="<B1>")
self.es.add(b1)
assert self.es.nodes[0] == b1
b2 = Bus(label="<B2>")
self.es.add(b2)
assert self.es.nodes[1] == b2
t1 = Transformer(label="<TF1>", inputs=[b1], outputs=[b2])
self.es.add(t1)
assert t1 in self.es.nodes
n1 = Node(label="<B1>")
self.es.add(n1)
assert self.es.nodes[0] == n1
n2 = Node(label="<B2>")
self.es.add(n2)
assert self.es.nodes[1] == n2
n3 = Node(label="<TF1>", inputs=[n1], outputs=[n2])
self.es.add(n3)
assert n3 in self.es.nodes


def test_deprecated_classes():
with pytest.warns(FutureWarning):
Bus()
with pytest.warns(FutureWarning):
Sink()
with pytest.warns(FutureWarning):
Source()
with pytest.warns(FutureWarning):
Transformer()

0 comments on commit dc5e751

Please sign in to comment.