Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sage
Path: blob/develop/build/test/test_logger.py
4052 views
1
# -*- coding: utf-8 -*-
2
"""
3
Test the printing and logging
4
"""
5
6
# ****************************************************************************
7
# Copyright (C) 2015 Volker Braun <[email protected]>
8
#
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU General Public License as published by
11
# the Free Software Foundation, either version 2 of the License, or
12
# (at your option) any later version.
13
# https://www.gnu.org/licenses/
14
# ****************************************************************************
15
16
17
import unittest
18
from textwrap import dedent
19
from .runnable import run_log_with
20
21
22
class LoggerTestCase(unittest.TestCase):
23
24
def test_interactive(self):
25
stdout, stderr = run_log_with('interactive:true')
26
self.assertEqual(stderr.strip(), dedent("""
27
WARNING [runnable|print_log:25]: This is the warning log level
28
CRITICAL [runnable|print_log:26]: This is the critical log level
29
ERROR [runnable|print_log:27]: This is the error log level
30
""").strip())
31
self.assertEqual(stdout.strip(), dedent("""
32
This is the info log level
33
This is printed
34
""").strip())
35
36
def test_noninteractive(self):
37
stdout, stderr = run_log_with('interactive:false')
38
self.assertEqual(stderr.strip(), dedent("""
39
This is the info log level
40
WARNING [runnable|print_log:25]: This is the warning log level
41
CRITICAL [runnable|print_log:26]: This is the critical log level
42
ERROR [runnable|print_log:27]: This is the error log level
43
""").strip())
44
self.assertEqual(stdout.strip(), dedent("""
45
This is printed
46
""").strip())
47
48
def test_debug(self):
49
"""
50
The lowest logging level
51
"""
52
stdout, stderr = run_log_with('log:debug,interactive:true')
53
self.assertEqual(stderr.strip(), dedent("""
54
DEBUG [runnable|print_log:23]: This is the debug log level
55
WARNING [runnable|print_log:25]: This is the warning log level
56
CRITICAL [runnable|print_log:26]: This is the critical log level
57
ERROR [runnable|print_log:27]: This is the error log level
58
""").strip())
59
self.assertEqual(stdout.strip(), dedent("""
60
This is the info log level
61
This is printed
62
""").strip())
63
64
def test_error(self):
65
"""
66
The highest logging level
67
"""
68
stdout, stderr = run_log_with('log:error,interactive:true')
69
self.assertEqual(stderr.strip(), dedent("""
70
CRITICAL [runnable|print_log:26]: This is the critical log level
71
ERROR [runnable|print_log:27]: This is the error log level
72
""").strip())
73
self.assertEqual(stdout.strip(), dedent("""
74
This is printed
75
""").strip())
76
77