Completed
Push — dev ( 68ddc7...49e927 )
by Patrik
58s queued 48s
created

test_sink.test_multi_input_sink()   A

Complexity

Conditions 3

Size

Total Lines 43
Code Lines 29

Duplication

Lines 43
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 29
dl 43
loc 43
rs 9.184
c 0
b 0
f 0
cc 3
nop 0
1
# -*- coding: utf-8 -*-
2
import warnings
3
4
import pytest
5
from oemof.tools.debugging import ExperimentalFeatureWarning
6
7
from oemof import solph
8
9
10 View Code Duplication
def test_multi_input_sink():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
    num_in = 3
12
    steps = 10
13
    costs = -0.1
14
15
    es = solph.EnergySystem(
16
        timeindex=solph.create_time_index(year=2023, number=steps),
17
        infer_last_interval=False,
18
    )
19
20
    for i in range(num_in):
21
        bus_label = f"bus input {i}"
22
        b = solph.Bus(bus_label)
23
        es.add(b)
24
        es.add(
25
            solph.components.Source(f"source {i}", outputs={b: solph.Flow()})
26
        )
27
    # Use of experimental API to access nodes by label.
28
    # Can be removed with future release of network.
29
    with warnings.catch_warnings():
30
        warnings.simplefilter("ignore", ExperimentalFeatureWarning)
31
        es.add(
32
            solph.components.Sink(
33
                inputs={
34
                    es.node[f"bus input {i}"]: solph.Flow(
35
                        nominal_capacity=1,
36
                        variable_costs=costs,
37
                    )
38
                    for i in range(num_in)
39
                }
40
            )
41
        )
42
43
    model = solph.Model(es)
44
    model.solve("cbc")
45
46
    assert (
47
        model.solver_results["Solver"][0]["Termination condition"]
48
        != "infeasible"
49
    )
50
    meta_results = solph.processing.meta_results(model)
51
52
    assert meta_results["objective"] == pytest.approx(num_in * steps * costs)
53