Passed
Pull Request — dev (#1174)
by
unknown
01:49
created

test_additional_total_limit()   B

Complexity

Conditions 1

Size

Total Lines 55
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 55
rs 8.968
c 0
b 0
f 0
cc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
# -*- coding: utf-8 -*-
2
3
"""Tests for Flows with NonConvex attribute
4
5
SPDX-FileCopyrightText: Deutsches Zentrum für Luft- und Raumfahrt e.V.
6
SPDX-FileCopyrightText: Maximilian Hillen
7
8
SPDX-License-Identifier: MIT
9
"""
10
11
import pandas as pd
12
13
from oemof import solph
14
15
16
def test_additional_total_limit():
17
    date_time_index = pd.date_range("1/1/2012", periods=3, freq="h")
18
    energysystem = solph.EnergySystem(
19
        timeindex=date_time_index,
20
        infer_last_interval=True,
21
    )
22
23
    a = solph.buses.Bus(label="a", balanced=False)
24
    b = solph.buses.Bus(label="b", balanced=True)
25
26
    # Converter a
27
    conv_linear = 4
28
    conv_offset = 5
29
    conv_flow = 1
30
    converter = solph.components.Converter(
31
        label="trafo_a",
32
        inputs={a: solph.Flow()},
33
        outputs={
34
            b: solph.Flow(
35
                nominal_capacity=solph.Investment(
36
                    ep_costs=1,
37
                    offset=1,
38
                    custom_attributes={
39
                        "emission": {
40
                            "linear": conv_linear,
41
                            "offset": conv_offset,
42
                        }
43
                    },
44
                    nonconvex=True,
45
                    maximum=5,
46
                ),
47
                custom_attributes={"emission": conv_flow},
48
            )
49
        },
50
        conversion_factors={a: 1},
51
    )
52
    energysystem.add(converter)
53
    s = solph.components.Sink(
54
        label="s",
55
        inputs={b: solph.Flow(nominal_capacity=1, fix=[1, 1, 1])},
56
    )
57
58
    energysystem.add(converter, a, b, s)
59
60
    model = solph.Model(energysystem)
61
62
    model = solph.constraints.additional_total_limit(
63
        model, "emission", limit=100
64
    )
65
66
    model.solve(solver="cbc")
67
68
    emission_used = model.total_limit_emission()
69
    print(emission_used)
70
    assert (1 * 3 + 4 + 5) == emission_used
71