| Total Complexity | 7 |
| Total Lines | 38 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 |