|
1
|
|
|
import warnings |
|
2
|
|
|
|
|
3
|
|
|
import pytest |
|
4
|
|
|
from oemof.tools.debugging import ExperimentalFeatureWarning |
|
5
|
|
|
|
|
6
|
|
|
from oemof.solph import Results |
|
7
|
|
|
|
|
8
|
|
|
from . import optimization_model |
|
9
|
|
|
|
|
10
|
|
|
|
|
11
|
|
|
class TestResultsClass: |
|
12
|
|
|
@classmethod |
|
13
|
|
|
def setup_class(cls): |
|
14
|
|
|
with warnings.catch_warnings(): |
|
15
|
|
|
warnings.simplefilter( |
|
16
|
|
|
"ignore", |
|
17
|
|
|
category=ExperimentalFeatureWarning, |
|
18
|
|
|
) |
|
19
|
|
|
cls.results = Results(optimization_model) |
|
20
|
|
|
|
|
21
|
|
|
def test_hasattr(self): |
|
22
|
|
|
assert hasattr(self.results, "_variables"), ( |
|
23
|
|
|
'\nFailed testing `hasattr(results, "_variables")`, where' |
|
24
|
|
|
" `results` is a `Results` instance." |
|
25
|
|
|
'\nExpected: `hasattr(results, "_variables")`' |
|
26
|
|
|
'\nGot : `not hasattr(results, "_variables")`' |
|
27
|
|
|
) |
|
28
|
|
|
assert not hasattr(self.results, "flow"), ( |
|
29
|
|
|
'\nFailed testing `not hasattr(results, "flow")`, where' |
|
30
|
|
|
" `results` is a `Results` instance." |
|
31
|
|
|
'\nExpected: `not hasattr(results, "flow")`' |
|
32
|
|
|
'\nGot : `hasattr(results, "flow")`' |
|
33
|
|
|
) |
|
34
|
|
|
|
|
35
|
|
|
def test_membership_checking(self): |
|
36
|
|
|
assert "flow" in self.results, ( |
|
37
|
|
|
'\nFailed testing `"flow" in results`, where `results` is a' |
|
38
|
|
|
" `Results` instance." |
|
39
|
|
|
'\nExpected: `"flow" in results`' |
|
40
|
|
|
'\nGot : `"flow" not in results`' |
|
41
|
|
|
) |
|
42
|
|
|
assert "" not in self.results, ( |
|
43
|
|
|
'\nFailed testing `"" in results`, where `results` is a' |
|
44
|
|
|
" `Results` instance." |
|
45
|
|
|
'\nExpected: `"" not in results`' |
|
46
|
|
|
'\nGot : `"" in results`' |
|
47
|
|
|
) |
|
48
|
|
|
|
|
49
|
|
|
def test_objective(self): |
|
50
|
|
|
assert self.results["objective"] == pytest.approx(8495, abs=1) |
|
51
|
|
|
|
|
52
|
|
|
def test_to_set_objective(self): |
|
53
|
|
|
with pytest.raises(TypeError): |
|
54
|
|
|
self.results["objective"] = 5 |
|
55
|
|
|
|
|
56
|
|
|
def test_time_index(self): |
|
57
|
|
|
assert len(self.results.timeindex) == 25 |
|
58
|
|
|
assert ( |
|
59
|
|
|
self.results.timeindex[3].strftime("%m/%d/%Y, %H") |
|
60
|
|
|
== "01/01/2012, 03" |
|
61
|
|
|
) |
|
62
|
|
|
|