Completed
Push — master ( 92ac7a...fe615f )
by Andreas
24s queued 12s
created

tests.test_f_logging   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 30
dl 0
loc 55
rs 10
c 0
b 0
f 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A test_check_logging_opt_false() 0 12 2
A test_check_logging_opt_true() 0 12 2
A test_check_logging_opt_none() 0 17 3
1
"""Тестирование механизмов логирования."""
2
import yaml
3
from f_logging import check_logging_opt
4
5
6
def test_check_logging_opt_true():
7
    """Проверка параметров логирования.
8
9
    Логирование True.
10
    """
11
    conffile = open('./conf/main.yml', 'r')
12
    config: dict[str, dict[str, str]] = yaml.full_load(conffile)
13
    conffile.close()
14
    config['settings']['logging'] = str(True)
15
    with open(r'conf/main.yml', 'w') as file:
16
        yaml.dump(config, file)
17
    assert check_logging_opt() is True, ('Check with TRUE: '
18
                                         'Return does not match '
19
                                         'expected value')
20
21
22
def test_check_logging_opt_false():
23
    """Проверка параметров логирования.
24
25
    Логирование False.
26
    """
27
    conffile = open('./conf/main.yml', 'r')
28
    config: dict[str, dict[str, str]] = yaml.full_load(conffile)
29
    conffile.close()
30
    config['settings']['logging'] = str(False)
31
    with open(r'conf/main.yml', 'w') as file:
32
        yaml.dump(config, file)
33
    assert check_logging_opt() is False, ('Check with FALSE: '
34
                                          'Return does not match '
35
                                          'expected value')
36
37
38
def test_check_logging_opt_none():
39
    """Проверка параметров логирования.
40
41
    Логирование не определено в конфиге.
42
    """
43
    conffile = open('./conf/main.yml', 'r')
44
    config: dict[str, dict[str, str]] = yaml.full_load(conffile)
45
    conffile.close()
46
    config['settings']['logging'] = ''
47
    with open(r'conf/main.yml', 'w') as file:
48
        yaml.dump(config, file)
49
    assert check_logging_opt() == 'ERR', ('Check with FALSE: '
50
                                          'Return does not match '
51
                                          'expected value')
52
    config['settings']['logging'] = str(False)
53
    with open(r'conf/main.yml', 'w') as file:
54
        yaml.dump(config, file)
55