Passed
Pull Request — dev (#1208)
by Patrik
04:04 queued 02:13
created

test_creation_of_extended_path()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 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