Passed
Pull Request — dev (#1208)
by Patrik
04:04 queued 02:13
created

tests.test_options.test_check_age_and_lifetime()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 0
1
"""Tests of the _options module.
2
3
This file is part of project oemof (github.com/oemof/oemof). It's copyrighted
4
by the contributors recorded in the version control history of the file,
5
available from its original location oemof/tests/test_components.py
6
7
SPDX-License-Identifier: MIT
8
"""
9
10
import pytest
11
from oemof.tools import debugging
12
13
from oemof import solph
14
15
16
def test_check_age_and_lifetime():
17
    """Check error being thrown if age > lifetime"""
18
    msg = "A unit's age must be smaller than its expected lifetime."
19
    with pytest.raises(AttributeError, match=msg):
20
        solph.Flow(nominal_capacity=solph.Investment(age=41, lifetime=40))
21
22
23
def test_check_invest_attributes_nonconvex():
24
    """Check error being thrown if nonconvex parameter is not of type bool"""
25
    msg = (
26
        "The `nonconvex` parameter of the `Investment` class has to be of type"
27
        + " boolean, not <class 'oemof.solph._options.NonConvex'>."
28
    )
29
    with pytest.raises(AttributeError, match=msg):
30
        solph.Flow(
31
            nominal_capacity=solph.Investment(
32
                maximum=1, nonconvex=solph.NonConvex()
33
            )
34
        )
35
36
37
def test_check_nonconvex():
38
    """
39
    Check warning being thrown if minimum and offset are zero and nonconvex
40
    is set
41
    """
42
    with pytest.warns(debugging.SuspiciousUsageWarning):
43
        solph.Flow(
44
            nominal_capacity=solph.Investment(
45
                maximum=1, minimum=0, offset=0, nonconvex=True
46
            )
47
        )
48