Skip to content

Commit

Permalink
Deprecate child classes of Node
Browse files Browse the repository at this point in the history
All subclasses to Node (Bus, Component, Sink, Source, and Transformer) do
not implement any additional functionality. This prepares their deletion.
  • Loading branch information
p-snft committed Sep 29, 2023
1 parent 2c298a7 commit 0e0237b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 13 deletions.
20 changes: 18 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 @@ -59,12 +61,26 @@ 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
34 changes: 23 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,22 @@ 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 0e0237b

Please sign in to comment.