Passed
Pull Request — dev (#1174)
by
unknown
02:47 queued 01:01
created

test_additional_total_limit()   B

Complexity

Conditions 1

Size

Total Lines 57
Code Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 57
rs 8.9439
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
import pytest
13
14
from oemof import solph
15
16
17
def test_additional_total_limit():
18
    date_time_index = pd.date_range("1/1/2012", periods=3, freq="h")
19
    energysystem = solph.EnergySystem(
20
        timeindex=date_time_index,
21
        infer_last_interval=True,
22
    )
23
24
    a = solph.buses.Bus(label="a", balanced=False)
25
    b = solph.buses.Bus(label="b", balanced=True)
26
27
    # Converter a
28
    conv_linear = 4
29
    conv_offset = 5
30
    conv_flow = 1
31
    converter = solph.components.Converter(
32
        label="trafo_a",
33
        inputs={a: solph.Flow()},
34
        outputs={
35
            b: solph.Flow(
36
                nominal_capacity=solph.Investment(
37
                    ep_costs=1,
38
                    offset=1,
39
                    custom_attributes={
40
                        "emission": {
41
                            "linear": conv_linear,
42
                            "offset": conv_offset,
43
                        }
44
                    },
45
                    nonconvex=True,
46
                    maximum=5,
47
                ),
48
                custom_attributes={"emission": conv_flow},
49
            )
50
        },
51
        conversion_factors={a: 1},
52
    )
53
    energysystem.add(converter)
54
    s = solph.components.Sink(
55
        label="s",
56
        inputs={b: solph.Flow(nominal_capacity=1, fix=[1, 1, 1])},
57
    )
58
59
    energysystem.add(converter, a, b, s)
60
61
    model = solph.Model(energysystem)
62
63
    model = solph.constraints.additional_total_limit(
64
        model, "emission", limit=100
65
    )
66
67
    model.solve(solver="cbc")
68
69
    results = solph.processing.results(model)
70
71
    emission_used = model.total_limit_emission()
72
    print(emission_used)
73
    assert (1 * 3 + 4 + 5) == emission_used
74