Passed
Push — master ( a239f0...6ab410 )
by Uwe
01:08 queued 11s
created

tool_tests.test_suspicious_usage_warning()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -
2
3
"""Test the created constraints against approved constraints.
4
5
This file is part of project oemof (github.com/oemof/oemof). It's copyrighted
6
by the contributors recorded in the version control history of the file,
7
available from its original location oemof/tests/tool_tests.py
8
9
SPDX-License-Identifier: MIT
10
"""
11
12
import os
13
import warnings
14
15
from nose.tools import assert_raises_regexp
16
from nose.tools import ok_, eq_
17
from oemof.tools import economics
18
from oemof.tools import debugging
19
from oemof.tools.logger import define_logging
20
from oemof.tools.logger import extend_basic_path
21
from oemof.tools.logger import get_basic_path
22
23
24
def test_helpers():
25
    get_basic_path()
26
    ok_(os.path.isdir(os.path.join(os.path.expanduser('~'), '.oemof')))
27
    new_dir = extend_basic_path('test_xf67456_dir')
28
    ok_(os.path.isdir(new_dir))
29
    os.rmdir(new_dir)
30
    ok_(not os.path.isdir(new_dir))
31
32
33
def test_logger():
34
    filepath = define_logging()
35
    ok_(isinstance(filepath, str))
36
    ok_(filepath[-9:] == 'oemof.log')
37
    ok_(os.path.isfile(filepath))
38
39
40
def test_annuity():
41
    """Test annuity function of economics tool."""
42
    ok_(round(economics.annuity(1000, 10, 0.1)) == 163)
43
    ok_(round(economics.annuity(capex=1000, wacc=0.1, n=10, u=5)) == 264)
44
    ok_(round(economics.annuity(1000, 10, 0.1, u=5, cost_decrease=0.1)) == 222)
45
46
47
def test_annuity_exceptions():
48
    """Test out-of-bounds-error of the annuity tool."""
49
    msg = "Input arguments for 'annuity' out of bounds!"
50
    assert_raises_regexp(ValueError, msg, economics.annuity, 1000, 10, 2)
51
    assert_raises_regexp(ValueError, msg, economics.annuity, 1000, 0.5, 1)
52
    assert_raises_regexp(
53
        ValueError, msg, economics.annuity, 1000, 10, 0.1, u=0.3)
54
    assert_raises_regexp(
55
        ValueError, msg, economics.annuity, 1000, 10, 0.1, cost_decrease=-1)
56
57
58
def test_suspicious_usage_warning():
59
    msg = "My message."
60
    with warnings.catch_warnings(record=True) as w:
61
        warnings.warn(msg, debugging.SuspiciousUsageWarning)
62
        ok_(len(w) == 1)
63
        eq_(msg, str(w[-1].message))
64