Passed
Pull Request — dev (#1238)
by Patrik
02:07
created

TestResultsClass.test_attribute_checking()   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nop 1
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_objective(self):
22
        assert self.results.objective == pytest.approx(8495, abs=1)
23
24
    def test_to_set_objective(self):
25
        with pytest.raises(AttributeError):
26
            self.results.objective = 5
27
28
    def test_time_index(self):
29
        assert len(self.results.timeindex) == 25
30
        assert (
31
            self.results.timeindex[3].strftime("%m/%d/%Y, %H")
32
            == "01/01/2012, 03"
33
        )
34
35
    def test_attribute_checking(self):
36
        assert hasattr(self.results, "objective")
37
        assert not hasattr(self.results, "non_existing")
38