Passed
Pull Request — dev (#1183)
by Patrik
04:02
created

tests.test_models.test_multi_period_default_discount_rate()   A

Complexity

Conditions 2

Size

Total Lines 42
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 42
rs 9.184
c 0
b 0
f 0
cc 2
nop 0
1
# -*- coding: utf-8 -
2
3
"""Basic tests.
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/basic_tests.py
8
9
SPDX-License-Identifier: MIT
10
"""
11
12
import pytest
13
14
from oemof import solph
15
16
17
def test_infeasible_model():
18
    es = solph.EnergySystem(timeincrement=[1])
19
    bel = solph.buses.Bus(label="bus")
20
    es.add(bel)
21
    es.add(
22
        solph.components.Sink(
23
            inputs={bel: solph.flows.Flow(nominal_capacity=5, fix=[1])}
24
        )
25
    )
26
    es.add(
27
        solph.components.Source(
28
            outputs={
29
                bel: solph.flows.Flow(nominal_capacity=4, variable_costs=5)
30
            }
31
        )
32
    )
33
    m = solph.Model(es)
34
    with pytest.warns(
35
        UserWarning, match="The solver did not return an optimal solution"
36
    ):
37
        m.solve(solver="cbc", allow_nonoptimal=True)
38
39
    with pytest.raises(
40
        RuntimeError, match="The solver did not return an optimal solution"
41
    ):
42
        m.solve(solver="cbc", allow_nonoptimal=False)
43
44
45
def test_unbounded_model():
46
    es = solph.EnergySystem(timeincrement=[1])
47
    bel = solph.buses.Bus(label="bus")
48
    es.add(bel)
49
    # Add a Sink with a higher demand
50
    es.add(solph.components.Sink(inputs={bel: solph.flows.Flow()}))
51
52
    # Add a Source with a very high supply
53
    es.add(
54
        solph.components.Source(
55
            outputs={bel: solph.flows.Flow(variable_costs=-5)}
56
        )
57
    )
58
    m = solph.Model(es)
59
60
    with pytest.raises(
61
        RuntimeError, match="The solver did not return an optimal solution"
62
    ):
63
        m.solve(solver="cbc", allow_nonoptimal=False)
64