Passed
Pull Request — dev (#1232)
by Patrik
01:49
created

test_custom_properties()   A

Complexity

Conditions 3

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 20
rs 9.65
c 0
b 0
f 0
cc 3
nop 0
1
# -*- coding: utf-8 -
2
3
"""Testing the flows.
4
5
This file is part of project oemof (github.com/oemof/oemof). It's copyrighted
6
by the contributors recorded in the version control history of the file,
7
available from its original location oemof/tests/test_components.py
8
9
SPDX-License-Identifier: MIT
10
"""
11
12
import pytest
13
14
from oemof.solph import NonConvex
15
from oemof.solph.flows import Flow
16
17
18
def test_source_with_full_load_time_max():
19
    Flow(nominal_capacity=1, full_load_time_max=2)
20
21
22
def test_nonconvex_positive_gradient_error():
23
    """Testing nonconvex positive gradient error."""
24
    msg = (
25
        "You specified a positive gradient in your nonconvex "
26
        "option. This cannot be combined with a positive or a "
27
        "negative gradient for a standard flow!"
28
    )
29
30
    with pytest.raises(ValueError, match=msg):
31
        Flow(
32
            nonconvex=NonConvex(
33
                positive_gradient_limit=0.03,
34
            ),
35
            positive_gradient_limit=0.03,
36
        )
37
38
39
def test_non_convex_negative_gradient_error():
40
    """Testing non-convex positive gradient error."""
41
    msg = (
42
        "You specified a negative gradient in your nonconvex "
43
        "option. This cannot be combined with a positive or a "
44
        "negative gradient for a standard flow!"
45
    )
46
47
    with pytest.raises(ValueError, match=msg):
48
        Flow(
49
            nonconvex=NonConvex(
50
                negative_gradient_limit=0.03,
51
            ),
52
            positive_gradient_limit=0.03,
53
        )
54
55
56
def test_fix_sequence():
57
    flow = Flow(nominal_capacity=4, fix=[0.3, 0.2, 0.7])
58
59
    assert flow.fix[0] == 0.3
60
    assert flow.fix[1] == 0.2
61
    assert flow.fix[2] == 0.7
62
63
64
def test_fix_sequence_non_nominal():
65
    """Attribute fix needs nominal_capacity"""
66
    with pytest.raises(AttributeError):
67
        Flow(fix=[0.3, 0.2, 0.7])
68