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
|
|
|
|