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

tests.test_outputlib.test_results   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 27
dl 0
loc 38
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A TestResultsClass.test_to_set_objective() 0 3 2
A TestResultsClass.setup_class() 0 8 2
A TestResultsClass.test_objective() 0 2 1
A TestResultsClass.test_time_index() 0 5 1
A TestResultsClass.test_attribute_checking() 0 3 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