forked from maxbbraun/trump2cash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs_tests.py
49 lines (34 loc) · 1.04 KB
/
logs_tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pytest import fixture
from logs import Logs
from logs import LOG_FILE
@fixture
def logs():
# TODO: Test cloud logging.
return Logs("test", to_cloud=False)
def get_last_logs(lines=1):
log_file = open(LOG_FILE, "r")
try:
last_logs = log_file.readlines()[-lines:]
finally:
log_file.close()
return "".join(last_logs)
def test_debug(logs, capfd):
logs.debug("debug")
assert get_last_logs().endswith(" DEBUG debug\n")
def test_info(logs, capfd):
logs.info("info")
assert get_last_logs().endswith(" INFO info\n")
def test_warn(logs, capfd):
logs.warn("warn")
assert get_last_logs().endswith(" WARNING warn\n")
def test_error(logs, capfd):
logs.error("error")
assert get_last_logs().endswith(" ERROR error\n")
def test_catch(logs, capfd):
try:
raise Exception("exception")
except Exception:
logs.catch()
assert get_last_logs(4).endswith(
'logs_tests.py", line 44, in test_catch\n raise Exception("exceptio'
'n")\nException: exception\n')