1
|
|
|
# -*- coding: utf-8 - |
2
|
|
|
|
3
|
|
|
""" Tests pertaining to :obj:`node {}` registration via |
4
|
|
|
:attr:`Node.registry <oemof.network.network.Node.registry>`. |
5
|
|
|
|
6
|
|
|
This test suite (eventually) collects all tests revolving around automatically |
7
|
|
|
registering :obj:`nodes <oemof.network.network.Node>` in an |
8
|
|
|
:obj:`energy system <oemof.network.EnergySystem>`. Since this feature is |
9
|
|
|
deprecated, having all tests pertaining to it in one file makes it easier to |
10
|
|
|
remove them all at once, when the feature is romved. |
11
|
|
|
|
12
|
|
|
This file is part of project oemof (github.com/oemof/oemof). It's copyrighted |
13
|
|
|
by the contributors recorded in the version control history of the file, |
14
|
|
|
available from its original location oemof/tests/basic_tests.py |
15
|
|
|
|
16
|
|
|
SPDX-License-Identifier: MIT |
17
|
|
|
""".format( |
18
|
|
|
"<oemof.network.network.Node>" |
19
|
|
|
) |
20
|
|
|
|
21
|
|
|
import warnings |
22
|
|
|
|
23
|
|
|
import pandas as pd |
24
|
|
|
import pytest |
25
|
|
|
|
26
|
|
|
from oemof.network.energy_system import EnergySystem |
27
|
|
|
from oemof.network.network import Bus |
28
|
|
|
from oemof.network.network import Node |
29
|
|
|
from oemof.network.network import Transformer |
30
|
|
|
|
31
|
|
|
|
32
|
|
|
class NodeRegistrationTests: |
33
|
|
|
|
34
|
|
|
# TODO: Move all other registration tests into this test suite. |
35
|
|
|
|
36
|
|
|
@classmethod |
37
|
|
|
def setup_class(cls): |
38
|
|
|
cls.timeindex = pd.date_range("1/1/2012", periods=5, freq="H") |
39
|
|
|
|
40
|
|
|
def setup(self): |
41
|
|
|
self.es = EnergySystem() |
42
|
|
|
with warnings.catch_warnings(): |
43
|
|
|
warnings.simplefilter("ignore") |
44
|
|
|
Node.registry = None |
45
|
|
|
|
46
|
|
|
def test_entity_registration(self): |
47
|
|
|
with warnings.catch_warnings(): |
48
|
|
|
warnings.simplefilter("ignore") |
49
|
|
|
Node.registry = self.es |
50
|
|
|
bus = Bus(label="bus-uid", type="bus-type") |
51
|
|
|
assert self.es.nodes[0] == bus |
52
|
|
|
bus2 = Bus(label="bus-uid2", type="bus-type") |
53
|
|
|
assert self.es.nodes[1] == bus2 |
54
|
|
|
t1 = Transformer(label="pp_gas", inputs=[bus], outputs=[bus2]) |
55
|
|
|
assert t1 in self.es.nodes |
56
|
|
|
self.es.timeindex = self.timeindex |
57
|
|
|
assert len(self.es.timeindex) == 5 |
58
|
|
|
|
59
|
|
|
def test_that_setting_a_node_registry_emits_a_warning(self): |
60
|
|
|
with pytest.warns(FutureWarning): |
61
|
|
|
Node.registry = 1 |
62
|
|
|
|
63
|
|
|
def test_that_accessing_the_node_registry_emits_a_warning(self): |
64
|
|
|
with pytest.warns(FutureWarning): |
65
|
|
|
Node.registry |
66
|
|
|
|
67
|
|
|
def test_that_node_creation_does_not_emit_a_warning(self): |
68
|
|
|
with pytest.warns(None) as record: |
69
|
|
|
Node() |
70
|
|
|
|
71
|
|
|
recorded = [w for w in record.list if w.category is FutureWarning] |
72
|
|
|
if recorded: |
73
|
|
|
pytest.fail( |
74
|
|
|
"Creating a node emitted the following `FutureWarning`s\n" |
75
|
|
|
"although no warning was expected:\n{}".format( |
76
|
|
|
"\n---\n".join([str(w.message) for w in recorded]) |
77
|
|
|
) |
78
|
|
|
) |
79
|
|
|
|
80
|
|
|
def test_that_node_creation_emits_a_warning_if_registry_is_not_none(self): |
81
|
|
|
with warnings.catch_warnings(): |
82
|
|
|
warnings.simplefilter("ignore") |
83
|
|
|
Node.registry = EnergySystem() |
84
|
|
|
|
85
|
|
|
with pytest.warns(FutureWarning): |
86
|
|
|
Node() |
87
|
|
|
|