-
-
Notifications
You must be signed in to change notification settings - Fork 598
/
Copy pathtest_logger.py
75 lines (66 loc) · 2.84 KB
/
test_logger.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Test the printing and logging
"""
# ****************************************************************************
# Copyright (C) 2015 Volker Braun <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
# https://www.gnu.org/licenses/
# ****************************************************************************
import unittest
from textwrap import dedent
from .runnable import run_log_with
class LoggerTestCase(unittest.TestCase):
def test_interactive(self):
stdout, stderr = run_log_with('interactive:true')
self.assertEqual(stderr.strip(), dedent("""
WARNING [runnable|print_log:25]: This is the warning log level
CRITICAL [runnable|print_log:26]: This is the critical log level
ERROR [runnable|print_log:27]: This is the error log level
""").strip())
self.assertEqual(stdout.strip(), dedent("""
This is the info log level
This is printed
""").strip())
def test_noninteractive(self):
stdout, stderr = run_log_with('interactive:false')
self.assertEqual(stderr.strip(), dedent("""
This is the info log level
WARNING [runnable|print_log:25]: This is the warning log level
CRITICAL [runnable|print_log:26]: This is the critical log level
ERROR [runnable|print_log:27]: This is the error log level
""").strip())
self.assertEqual(stdout.strip(), dedent("""
This is printed
""").strip())
def test_debug(self):
"""
The lowest logging level
"""
stdout, stderr = run_log_with('log:debug,interactive:true')
self.assertEqual(stderr.strip(), dedent("""
DEBUG [runnable|print_log:23]: This is the debug log level
WARNING [runnable|print_log:25]: This is the warning log level
CRITICAL [runnable|print_log:26]: This is the critical log level
ERROR [runnable|print_log:27]: This is the error log level
""").strip())
self.assertEqual(stdout.strip(), dedent("""
This is the info log level
This is printed
""").strip())
def test_error(self):
"""
The highest logging level
"""
stdout, stderr = run_log_with('log:error,interactive:true')
self.assertEqual(stderr.strip(), dedent("""
CRITICAL [runnable|print_log:26]: This is the critical log level
ERROR [runnable|print_log:27]: This is the error log level
""").strip())
self.assertEqual(stdout.strip(), dedent("""
This is printed
""").strip())