| Total Complexity | 3 |
| Total Lines | 46 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | |||
| 3 | """This module is designed to test the helper functions.. |
||
| 4 | |||
| 5 | SPDX-FileCopyrightText: Uwe Krien <[email protected]> |
||
| 6 | |||
| 7 | SPDX-License-Identifier: MIT |
||
| 8 | |||
| 9 | """ |
||
| 10 | |||
| 11 | import os |
||
| 12 | |||
| 13 | import pytest |
||
| 14 | |||
| 15 | from oemof.solph import create_time_index |
||
| 16 | from oemof.solph import helpers |
||
| 17 | |||
| 18 | |||
| 19 | def test_creation_of_extended_path(): |
||
| 20 | """Creation of a sub-folder based on the base path failed.""" |
||
| 21 | p = helpers.extend_basic_path("test_subfolder_X345qw34_tmp") |
||
| 22 | assert os.path.isdir(p) |
||
| 23 | os.rmdir(p) |
||
| 24 | |||
| 25 | |||
| 26 | def test_create_time_index(): |
||
| 27 | assert len(create_time_index(2014)) == 8761 |
||
| 28 | assert len(create_time_index(2012)) == 8785 # leap year |
||
| 29 | assert len(create_time_index(2014, interval=0.5)) == 17521 |
||
| 30 | assert len(create_time_index(2014, interval=0.5, number=10)) == 11 |
||
| 31 | assert len(create_time_index(2014, number=10)) == 11 |
||
| 32 | assert ( |
||
| 33 | str(create_time_index(2014, interval=0.5, number=10)[-1]) |
||
| 34 | == "2014-01-01 05:00:00" |
||
| 35 | ) |
||
| 36 | assert ( |
||
| 37 | str(create_time_index(2014, interval=2, number=10)[-1]) |
||
| 38 | == "2014-01-01 20:00:00" |
||
| 39 | ) |
||
| 40 | assert ( |
||
| 41 | str(create_time_index(interval=0.5, number=10, start="2025-01-02")[-1]) |
||
| 42 | == "2025-01-02 05:00:00" |
||
| 43 | ) |
||
| 44 | with pytest.raises(ValueError, match="mutually exclusive"): |
||
| 45 | create_time_index(year=2015, start="2025-01-02") |
||
| 46 |