annotate Lib/test/test_logging.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 8817c295a8ee
children 8ae1c28445f8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
2 #
76543
9cfe6845b1df Updated year in docstring/comment.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76542
diff changeset
3 # Copyright 2001-2012 by Vinay Sajip. All Rights Reserved.
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
4 #
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
5 # Permission to use, copy, modify, and distribute this software and its
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
6 # documentation for any purpose and without fee is hereby granted,
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
7 # provided that the above copyright notice appear in all copies and that
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
8 # both that copyright notice and this permission notice appear in
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
9 # supporting documentation, and that the name of Vinay Sajip
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
10 # not be used in advertising or publicity pertaining to distribution
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
11 # of the software without specific, written prior permission.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
12 # VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
13 # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
14 # VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
15 # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
16 # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
17 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
18
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
19 """Test harness for the logging module. Run all tests.
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
20
76543
9cfe6845b1df Updated year in docstring/comment.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76542
diff changeset
21 Copyright (C) 2001-2012 Vinay Sajip. All Rights Reserved.
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
22 """
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
23
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
24 import logging
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
25 import logging.handlers
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
26 import logging.config
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
27
51476
4ea122973914 Fixed missing import.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 51475
diff changeset
28 import codecs
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
29 import cPickle
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
30 import cStringIO
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
31 import gc
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
32 import json
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
33 import os
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
34 import random
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
35 import re
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
36 import select
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
37 import socket
47241
ba1fa511b72d socketserver renaming reversal part 3: move the module into the right
Georg Brandl <georg@python.org>
parents: 46929
diff changeset
38 from SocketServer import ThreadingTCPServer, StreamRequestHandler
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
39 import struct
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
40 import sys
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
41 import tempfile
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
42 from test.test_support import captured_stdout, run_with_locale, run_unittest
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
43 import textwrap
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
44 import time
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
45 import unittest
49955
878d40468c4e Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
46 import warnings
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
47 import weakref
61046
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
48 try:
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
49 import threading
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
50 except ImportError:
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
51 threading = None
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
52
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
53 class BaseTest(unittest.TestCase):
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
54
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
55 """Base class for logging tests."""
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
56
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
57 log_format = "%(name)s -> %(levelname)s: %(message)s"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
58 expected_log_pat = r"^([\w.]+) -> ([\w]+): ([\d]+)$"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
59 message_num = 0
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
60
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
61 def setUp(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
62 """Setup the default logging stream to an internal StringIO instance,
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
63 so that we can examine log output as we want."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
64 logger_dict = logging.getLogger().manager.loggerDict
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
65 logging._acquireLock()
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
66 try:
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
67 self.saved_handlers = logging._handlers.copy()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
68 self.saved_handler_list = logging._handlerList[:]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
69 self.saved_loggers = logger_dict.copy()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
70 self.saved_level_names = logging._levelNames.copy()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
71 finally:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
72 logging._releaseLock()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
73
63111
45ed0cf2c386 Fixed #9310: backported logging fix from 2.7.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59834
diff changeset
74 # Set two unused loggers: one non-ASCII and one Unicode.
45ed0cf2c386 Fixed #9310: backported logging fix from 2.7.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59834
diff changeset
75 # This is to test correct operation when sorting existing
59901
15de5390707d Issue #8201: logging: Handle config errors when non-ASCII and Unicode logger names exist at the same time.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59402
diff changeset
76 # loggers in the configuration code. See issue 8201.
63111
45ed0cf2c386 Fixed #9310: backported logging fix from 2.7.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59834
diff changeset
77 logging.getLogger("\xab\xd7\xbb")
45ed0cf2c386 Fixed #9310: backported logging fix from 2.7.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59834
diff changeset
78 logging.getLogger(u"\u013f\u00d6\u0047")
45ed0cf2c386 Fixed #9310: backported logging fix from 2.7.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59834
diff changeset
79
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
80 self.root_logger = logging.getLogger("")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
81 self.original_logging_level = self.root_logger.getEffectiveLevel()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
82
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
83 self.stream = cStringIO.StringIO()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
84 self.root_logger.setLevel(logging.DEBUG)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
85 self.root_hdlr = logging.StreamHandler(self.stream)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
86 self.root_formatter = logging.Formatter(self.log_format)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
87 self.root_hdlr.setFormatter(self.root_formatter)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
88 self.root_logger.addHandler(self.root_hdlr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
89
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
90 def tearDown(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
91 """Remove our logging stream, and restore the original logging
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
92 level."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
93 self.stream.close()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
94 self.root_logger.removeHandler(self.root_hdlr)
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
95 while self.root_logger.handlers:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
96 h = self.root_logger.handlers[0]
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
97 self.root_logger.removeHandler(h)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
98 h.close()
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
99 self.root_logger.setLevel(self.original_logging_level)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
100 logging._acquireLock()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
101 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
102 logging._levelNames.clear()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
103 logging._levelNames.update(self.saved_level_names)
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
104 logging._handlers.clear()
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
105 logging._handlers.update(self.saved_handlers)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
106 logging._handlerList[:] = self.saved_handler_list
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
107 loggerDict = logging.getLogger().manager.loggerDict
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
108 loggerDict.clear()
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
109 loggerDict.update(self.saved_loggers)
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
110 finally:
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
111 logging._releaseLock()
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
112
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
113 def assert_log_lines(self, expected_values, stream=None):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
114 """Match the collected log lines against the regular expression
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
115 self.expected_log_pat, and compare the extracted group values to
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
116 the expected_values list of tuples."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
117 stream = stream or self.stream
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
118 pat = re.compile(self.expected_log_pat)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
119 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
120 stream.reset()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
121 actual_lines = stream.readlines()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
122 except AttributeError:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
123 # StringIO.StringIO lacks a reset() method.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
124 actual_lines = stream.getvalue().splitlines()
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
125 self.assertEqual(len(actual_lines), len(expected_values))
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
126 for actual, expected in zip(actual_lines, expected_values):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
127 match = pat.search(actual)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
128 if not match:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
129 self.fail("Log line does not match expected pattern:\n" +
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
130 actual)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
131 self.assertEqual(tuple(match.groups()), expected)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
132 s = stream.read()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
133 if s:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
134 self.fail("Remaining output at end of log stream:\n" + s)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
135
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
136 def next_message(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
137 """Generate a message consisting solely of an auto-incrementing
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
138 integer."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
139 self.message_num += 1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
140 return "%d" % self.message_num
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
141
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
142
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
143 class BuiltinLevelsTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
144 """Test builtin levels and their inheritance."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
145
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
146 def test_flat(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
147 #Logging levels in a flat logger namespace.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
148 m = self.next_message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
149
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
150 ERR = logging.getLogger("ERR")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
151 ERR.setLevel(logging.ERROR)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
152 INF = logging.getLogger("INF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
153 INF.setLevel(logging.INFO)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
154 DEB = logging.getLogger("DEB")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
155 DEB.setLevel(logging.DEBUG)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
156
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
157 # These should log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
158 ERR.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
159 ERR.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
160
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
161 INF.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
162 INF.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
163 INF.warn(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
164 INF.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
165
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
166 DEB.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
167 DEB.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
168 DEB.warn (m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
169 DEB.info (m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
170 DEB.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
171
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
172 # These should not log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
173 ERR.warn(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
174 ERR.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
175 ERR.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
176
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
177 INF.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
178
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
179 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
180 ('ERR', 'CRITICAL', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
181 ('ERR', 'ERROR', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
182 ('INF', 'CRITICAL', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
183 ('INF', 'ERROR', '4'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
184 ('INF', 'WARNING', '5'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
185 ('INF', 'INFO', '6'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
186 ('DEB', 'CRITICAL', '7'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
187 ('DEB', 'ERROR', '8'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
188 ('DEB', 'WARNING', '9'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
189 ('DEB', 'INFO', '10'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
190 ('DEB', 'DEBUG', '11'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
191 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
192
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
193 def test_nested_explicit(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
194 # Logging levels in a nested namespace, all explicitly set.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
195 m = self.next_message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
196
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
197 INF = logging.getLogger("INF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
198 INF.setLevel(logging.INFO)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
199 INF_ERR = logging.getLogger("INF.ERR")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
200 INF_ERR.setLevel(logging.ERROR)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
201
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
202 # These should log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
203 INF_ERR.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
204 INF_ERR.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
205
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
206 # These should not log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
207 INF_ERR.warn(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
208 INF_ERR.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
209 INF_ERR.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
210
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
211 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
212 ('INF.ERR', 'CRITICAL', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
213 ('INF.ERR', 'ERROR', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
214 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
215
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
216 def test_nested_inherited(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
217 #Logging levels in a nested namespace, inherited from parent loggers.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
218 m = self.next_message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
219
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
220 INF = logging.getLogger("INF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
221 INF.setLevel(logging.INFO)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
222 INF_ERR = logging.getLogger("INF.ERR")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
223 INF_ERR.setLevel(logging.ERROR)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
224 INF_UNDEF = logging.getLogger("INF.UNDEF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
225 INF_ERR_UNDEF = logging.getLogger("INF.ERR.UNDEF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
226 UNDEF = logging.getLogger("UNDEF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
227
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
228 # These should log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
229 INF_UNDEF.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
230 INF_UNDEF.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
231 INF_UNDEF.warn(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
232 INF_UNDEF.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
233 INF_ERR_UNDEF.log(logging.CRITICAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
234 INF_ERR_UNDEF.error(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
235
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
236 # These should not log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
237 INF_UNDEF.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
238 INF_ERR_UNDEF.warn(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
239 INF_ERR_UNDEF.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
240 INF_ERR_UNDEF.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
241
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
242 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
243 ('INF.UNDEF', 'CRITICAL', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
244 ('INF.UNDEF', 'ERROR', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
245 ('INF.UNDEF', 'WARNING', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
246 ('INF.UNDEF', 'INFO', '4'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
247 ('INF.ERR.UNDEF', 'CRITICAL', '5'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
248 ('INF.ERR.UNDEF', 'ERROR', '6'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
249 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
250
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
251 def test_nested_with_virtual_parent(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
252 # Logging levels when some parent does not exist yet.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
253 m = self.next_message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
254
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
255 INF = logging.getLogger("INF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
256 GRANDCHILD = logging.getLogger("INF.BADPARENT.UNDEF")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
257 CHILD = logging.getLogger("INF.BADPARENT")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
258 INF.setLevel(logging.INFO)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
259
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
260 # These should log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
261 GRANDCHILD.log(logging.FATAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
262 GRANDCHILD.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
263 CHILD.log(logging.FATAL, m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
264 CHILD.info(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
265
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
266 # These should not log.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
267 GRANDCHILD.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
268 CHILD.debug(m())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
269
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
270 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
271 ('INF.BADPARENT.UNDEF', 'CRITICAL', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
272 ('INF.BADPARENT.UNDEF', 'INFO', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
273 ('INF.BADPARENT', 'CRITICAL', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
274 ('INF.BADPARENT', 'INFO', '4'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
275 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
276
73415
5f3b7528b144 Closes #13661: Check added for type of logger name.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 68420
diff changeset
277 def test_invalid_name(self):
73418
60dd1568bbd1 Closes #13361: Raise correct exception type.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73415
diff changeset
278 self.assertRaises(TypeError, logging.getLogger, any)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
279
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
280 class BasicFilterTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
281
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
282 """Test the bundled Filter class."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
283
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
284 def test_filter(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
285 # Only messages satisfying the specified criteria pass through the
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
286 # filter.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
287 filter_ = logging.Filter("spam.eggs")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
288 handler = self.root_logger.handlers[0]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
289 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
290 handler.addFilter(filter_)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
291 spam = logging.getLogger("spam")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
292 spam_eggs = logging.getLogger("spam.eggs")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
293 spam_eggs_fish = logging.getLogger("spam.eggs.fish")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
294 spam_bakedbeans = logging.getLogger("spam.bakedbeans")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
295
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
296 spam.info(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
297 spam_eggs.info(self.next_message()) # Good.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
298 spam_eggs_fish.info(self.next_message()) # Good.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
299 spam_bakedbeans.info(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
300
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
301 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
302 ('spam.eggs', 'INFO', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
303 ('spam.eggs.fish', 'INFO', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
304 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
305 finally:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
306 handler.removeFilter(filter_)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
307
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
308
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
309 #
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
310 # First, we define our levels. There can be as many as you want - the only
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
311 # limitations are that they should be integers, the lowest should be > 0 and
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
312 # larger values mean less information being logged. If you need specific
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
313 # level values which do not fit into these limitations, you can use a
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
314 # mapping dictionary to convert between your application levels and the
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
315 # logging system.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
316 #
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
317 SILENT = 120
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
318 TACITURN = 119
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
319 TERSE = 118
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
320 EFFUSIVE = 117
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
321 SOCIABLE = 116
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
322 VERBOSE = 115
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
323 TALKATIVE = 114
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
324 GARRULOUS = 113
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
325 CHATTERBOX = 112
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
326 BORING = 111
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
327
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
328 LEVEL_RANGE = range(BORING, SILENT + 1)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
329
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
330 #
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
331 # Next, we define names for our levels. You don't need to do this - in which
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
332 # case the system will use "Level n" to denote the text for the level.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
333 #
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
334 my_logging_levels = {
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
335 SILENT : 'Silent',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
336 TACITURN : 'Taciturn',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
337 TERSE : 'Terse',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
338 EFFUSIVE : 'Effusive',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
339 SOCIABLE : 'Sociable',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
340 VERBOSE : 'Verbose',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
341 TALKATIVE : 'Talkative',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
342 GARRULOUS : 'Garrulous',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
343 CHATTERBOX : 'Chatterbox',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
344 BORING : 'Boring',
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
345 }
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
346
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
347 class GarrulousFilter(logging.Filter):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
348
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
349 """A filter which blocks garrulous messages."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
350
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
351 def filter(self, record):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
352 return record.levelno != GARRULOUS
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
353
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
354 class VerySpecificFilter(logging.Filter):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
355
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
356 """A filter which blocks sociable and taciturn messages."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
357
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
358 def filter(self, record):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
359 return record.levelno not in [SOCIABLE, TACITURN]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
360
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
361
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
362 class CustomLevelsAndFiltersTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
363
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
364 """Test various filtering possibilities with custom logging levels."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
365
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
366 # Skip the logger name group.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
367 expected_log_pat = r"^[\w.]+ -> ([\w]+): ([\d]+)$"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
368
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
369 def setUp(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
370 BaseTest.setUp(self)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
371 for k, v in my_logging_levels.items():
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
372 logging.addLevelName(k, v)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
373
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
374 def log_at_all_levels(self, logger):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
375 for lvl in LEVEL_RANGE:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
376 logger.log(lvl, self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
377
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
378 def test_logger_filter(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
379 # Filter at logger level.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
380 self.root_logger.setLevel(VERBOSE)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
381 # Levels >= 'Verbose' are good.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
382 self.log_at_all_levels(self.root_logger)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
383 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
384 ('Verbose', '5'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
385 ('Sociable', '6'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
386 ('Effusive', '7'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
387 ('Terse', '8'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
388 ('Taciturn', '9'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
389 ('Silent', '10'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
390 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
391
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
392 def test_handler_filter(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
393 # Filter at handler level.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
394 self.root_logger.handlers[0].setLevel(SOCIABLE)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
395 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
396 # Levels >= 'Sociable' are good.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
397 self.log_at_all_levels(self.root_logger)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
398 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
399 ('Sociable', '6'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
400 ('Effusive', '7'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
401 ('Terse', '8'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
402 ('Taciturn', '9'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
403 ('Silent', '10'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
404 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
405 finally:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
406 self.root_logger.handlers[0].setLevel(logging.NOTSET)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
407
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
408 def test_specific_filters(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
409 # Set a specific filter object on the handler, and then add another
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
410 # filter object on the logger itself.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
411 handler = self.root_logger.handlers[0]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
412 specific_filter = None
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
413 garr = GarrulousFilter()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
414 handler.addFilter(garr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
415 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
416 self.log_at_all_levels(self.root_logger)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
417 first_lines = [
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
418 # Notice how 'Garrulous' is missing
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
419 ('Boring', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
420 ('Chatterbox', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
421 ('Talkative', '4'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
422 ('Verbose', '5'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
423 ('Sociable', '6'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
424 ('Effusive', '7'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
425 ('Terse', '8'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
426 ('Taciturn', '9'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
427 ('Silent', '10'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
428 ]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
429 self.assert_log_lines(first_lines)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
430
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
431 specific_filter = VerySpecificFilter()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
432 self.root_logger.addFilter(specific_filter)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
433 self.log_at_all_levels(self.root_logger)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
434 self.assert_log_lines(first_lines + [
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
435 # Not only 'Garrulous' is still missing, but also 'Sociable'
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
436 # and 'Taciturn'
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
437 ('Boring', '11'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
438 ('Chatterbox', '12'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
439 ('Talkative', '14'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
440 ('Verbose', '15'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
441 ('Effusive', '17'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
442 ('Terse', '18'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
443 ('Silent', '20'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
444 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
445 finally:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
446 if specific_filter:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
447 self.root_logger.removeFilter(specific_filter)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
448 handler.removeFilter(garr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
449
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
450
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
451 class MemoryHandlerTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
452
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
453 """Tests for the MemoryHandler."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
454
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
455 # Do not bother with a logger name group.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
456 expected_log_pat = r"^[\w.]+ -> ([\w]+): ([\d]+)$"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
457
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
458 def setUp(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
459 BaseTest.setUp(self)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
460 self.mem_hdlr = logging.handlers.MemoryHandler(10, logging.WARNING,
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
461 self.root_hdlr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
462 self.mem_logger = logging.getLogger('mem')
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
463 self.mem_logger.propagate = 0
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
464 self.mem_logger.addHandler(self.mem_hdlr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
465
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
466 def tearDown(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
467 self.mem_hdlr.close()
46183
c440a5737149 Correctly call the base class tearDown();
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 45623
diff changeset
468 BaseTest.tearDown(self)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
469
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
470 def test_flush(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
471 # The memory handler flushes to its target handler based on specific
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
472 # criteria (message count and message level).
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
473 self.mem_logger.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
474 self.assert_log_lines([])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
475 self.mem_logger.info(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
476 self.assert_log_lines([])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
477 # This will flush because the level is >= logging.WARNING
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
478 self.mem_logger.warn(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
479 lines = [
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
480 ('DEBUG', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
481 ('INFO', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
482 ('WARNING', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
483 ]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
484 self.assert_log_lines(lines)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
485 for n in (4, 14):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
486 for i in range(9):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
487 self.mem_logger.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
488 self.assert_log_lines(lines)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
489 # This will flush because it's the 10th message since the last
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
490 # flush.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
491 self.mem_logger.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
492 lines = lines + [('DEBUG', str(i)) for i in range(n, n + 10)]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
493 self.assert_log_lines(lines)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
494
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
495 self.mem_logger.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
496 self.assert_log_lines(lines)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
497
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
498
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
499 class ExceptionFormatter(logging.Formatter):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
500 """A special exception formatter."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
501 def formatException(self, ei):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
502 return "Got a [%s]" % ei[0].__name__
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
503
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
504
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
505 class ConfigFileTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
506
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
507 """Reading logging config from a .ini-style config file."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
508
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
509 expected_log_pat = r"^([\w]+) \+\+ ([\w]+)$"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
510
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
511 # config0 is a standard configuration.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
512 config0 = """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
513 [loggers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
514 keys=root
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
515
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
516 [handlers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
517 keys=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
518
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
519 [formatters]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
520 keys=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
521
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
522 [logger_root]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
523 level=WARNING
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
524 handlers=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
525
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
526 [handler_hand1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
527 class=StreamHandler
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
528 level=NOTSET
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
529 formatter=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
530 args=(sys.stdout,)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
531
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
532 [formatter_form1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
533 format=%(levelname)s ++ %(message)s
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
534 datefmt=
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
535 """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
536
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
537 # config1 adds a little to the standard configuration.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
538 config1 = """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
539 [loggers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
540 keys=root,parser
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
541
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
542 [handlers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
543 keys=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
544
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
545 [formatters]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
546 keys=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
547
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
548 [logger_root]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
549 level=WARNING
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
550 handlers=
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
551
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
552 [logger_parser]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
553 level=DEBUG
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
554 handlers=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
555 propagate=1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
556 qualname=compiler.parser
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
557
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
558 [handler_hand1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
559 class=StreamHandler
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
560 level=NOTSET
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
561 formatter=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
562 args=(sys.stdout,)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
563
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
564 [formatter_form1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
565 format=%(levelname)s ++ %(message)s
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
566 datefmt=
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
567 """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
568
68315
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
569 # config1a moves the handler to the root.
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
570 config1a = """
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
571 [loggers]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
572 keys=root,parser
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
573
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
574 [handlers]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
575 keys=hand1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
576
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
577 [formatters]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
578 keys=form1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
579
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
580 [logger_root]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
581 level=WARNING
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
582 handlers=hand1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
583
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
584 [logger_parser]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
585 level=DEBUG
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
586 handlers=
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
587 propagate=1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
588 qualname=compiler.parser
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
589
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
590 [handler_hand1]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
591 class=StreamHandler
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
592 level=NOTSET
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
593 formatter=form1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
594 args=(sys.stdout,)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
595
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
596 [formatter_form1]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
597 format=%(levelname)s ++ %(message)s
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
598 datefmt=
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
599 """
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
600
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
601 # config2 has a subtle configuration error that should be reported
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
602 config2 = config1.replace("sys.stdout", "sys.stbout")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
603
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
604 # config3 has a less subtle configuration error
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
605 config3 = config1.replace("formatter=form1", "formatter=misspelled_name")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
606
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
607 # config4 specifies a custom formatter class to be loaded
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
608 config4 = """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
609 [loggers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
610 keys=root
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
611
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
612 [handlers]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
613 keys=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
614
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
615 [formatters]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
616 keys=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
617
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
618 [logger_root]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
619 level=NOTSET
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
620 handlers=hand1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
621
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
622 [handler_hand1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
623 class=StreamHandler
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
624 level=NOTSET
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
625 formatter=form1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
626 args=(sys.stdout,)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
627
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
628 [formatter_form1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
629 class=""" + __name__ + """.ExceptionFormatter
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
630 format=%(levelname)s:%(name)s:%(message)s
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
631 datefmt=
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
632 """
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
633
48010
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
634 # config5 specifies a custom handler class to be loaded
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
635 config5 = config1.replace('class=StreamHandler', 'class=logging.StreamHandler')
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
636
48980
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
637 # config6 uses ', ' delimiters in the handlers and formatters sections
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
638 config6 = """
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
639 [loggers]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
640 keys=root,parser
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
641
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
642 [handlers]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
643 keys=hand1, hand2
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
644
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
645 [formatters]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
646 keys=form1, form2
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
647
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
648 [logger_root]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
649 level=WARNING
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
650 handlers=
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
651
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
652 [logger_parser]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
653 level=DEBUG
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
654 handlers=hand1
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
655 propagate=1
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
656 qualname=compiler.parser
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
657
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
658 [handler_hand1]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
659 class=StreamHandler
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
660 level=NOTSET
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
661 formatter=form1
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
662 args=(sys.stdout,)
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
663
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
664 [handler_hand2]
49109
36b2d674fc8c Issue #3809: Fixed spurious 'test.blah' file left behind by test_logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49009
diff changeset
665 class=StreamHandler
48980
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
666 level=NOTSET
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
667 formatter=form1
49109
36b2d674fc8c Issue #3809: Fixed spurious 'test.blah' file left behind by test_logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49009
diff changeset
668 args=(sys.stderr,)
48980
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
669
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
670 [formatter_form1]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
671 format=%(levelname)s ++ %(message)s
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
672 datefmt=
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
673
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
674 [formatter_form2]
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
675 format=%(message)s
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
676 datefmt=
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
677 """
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
678
68315
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
679 # config7 adds a compiler logger.
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
680 config7 = """
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
681 [loggers]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
682 keys=root,parser,compiler
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
683
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
684 [handlers]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
685 keys=hand1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
686
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
687 [formatters]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
688 keys=form1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
689
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
690 [logger_root]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
691 level=WARNING
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
692 handlers=hand1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
693
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
694 [logger_compiler]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
695 level=DEBUG
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
696 handlers=
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
697 propagate=1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
698 qualname=compiler
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
699
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
700 [logger_parser]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
701 level=DEBUG
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
702 handlers=
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
703 propagate=1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
704 qualname=compiler.parser
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
705
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
706 [handler_hand1]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
707 class=StreamHandler
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
708 level=NOTSET
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
709 formatter=form1
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
710 args=(sys.stdout,)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
711
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
712 [formatter_form1]
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
713 format=%(levelname)s ++ %(message)s
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
714 datefmt=
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
715 """
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
716
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
717 def apply_config(self, conf):
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
718 file = cStringIO.StringIO(textwrap.dedent(conf))
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
719 logging.config.fileConfig(file)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
720
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
721 def test_config0_ok(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
722 # A simple config file which overrides the default settings.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
723 with captured_stdout() as output:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
724 self.apply_config(self.config0)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
725 logger = logging.getLogger()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
726 # Won't output anything
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
727 logger.info(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
728 # Outputs a message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
729 logger.error(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
730 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
731 ('ERROR', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
732 ], stream=output)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
733 # Original logger output is empty.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
734 self.assert_log_lines([])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
735
48010
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
736 def test_config1_ok(self, config=config1):
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
737 # A config file defining a sub-parser as well.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
738 with captured_stdout() as output:
48010
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
739 self.apply_config(config)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
740 logger = logging.getLogger("compiler.parser")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
741 # Both will output a message
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
742 logger.info(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
743 logger.error(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
744 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
745 ('INFO', '1'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
746 ('ERROR', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
747 ], stream=output)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
748 # Original logger output is empty.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
749 self.assert_log_lines([])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
750
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
751 def test_config2_failure(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
752 # A simple config file which overrides the default settings.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
753 self.assertRaises(StandardError, self.apply_config, self.config2)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
754
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
755 def test_config3_failure(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
756 # A simple config file which overrides the default settings.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
757 self.assertRaises(StandardError, self.apply_config, self.config3)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
758
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
759 def test_config4_ok(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
760 # A config file specifying a custom formatter class.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
761 with captured_stdout() as output:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
762 self.apply_config(self.config4)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
763 logger = logging.getLogger()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
764 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
765 raise RuntimeError()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
766 except RuntimeError:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
767 logging.exception("just testing")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
768 sys.stdout.seek(0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
769 self.assertEqual(output.getvalue(),
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
770 "ERROR:root:just testing\nGot a [RuntimeError]\n")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
771 # Original logger output is empty
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
772 self.assert_log_lines([])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
773
48010
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
774 def test_config5_ok(self):
8ec1830d5719 Issue #3389: Allow resolving dotted names for handlers in logging configuration files. Thanks to Philip Jenvey for the patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 47241
diff changeset
775 self.test_config1_ok(config=self.config5)
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
776
48980
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
777 def test_config6_ok(self):
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
778 self.test_config1_ok(config=self.config6)
5fd39b84fc29 Issue #3726: Allowed spaces in separators in logging configuration files.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48010
diff changeset
779
68315
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
780 def test_config7_ok(self):
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
781 with captured_stdout() as output:
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
782 self.apply_config(self.config1a)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
783 logger = logging.getLogger("compiler.parser")
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
784 # See issue #11424. compiler-hyphenated sorts
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
785 # between compiler and compiler.xyz and this
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
786 # was preventing compiler.xyz from being included
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
787 # in the child loggers of compiler because of an
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
788 # overzealous loop termination condition.
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
789 hyphenated = logging.getLogger('compiler-hyphenated')
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
790 # All will output a message
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
791 logger.info(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
792 logger.error(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
793 hyphenated.critical(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
794 self.assert_log_lines([
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
795 ('INFO', '1'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
796 ('ERROR', '2'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
797 ('CRITICAL', '3'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
798 ], stream=output)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
799 # Original logger output is empty.
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
800 self.assert_log_lines([])
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
801 with captured_stdout() as output:
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
802 self.apply_config(self.config7)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
803 logger = logging.getLogger("compiler.parser")
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
804 self.assertFalse(logger.disabled)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
805 # Both will output a message
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
806 logger.info(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
807 logger.error(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
808 logger = logging.getLogger("compiler.lexer")
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
809 # Both will output a message
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
810 logger.info(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
811 logger.error(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
812 # Will not appear
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
813 hyphenated.critical(self.next_message())
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
814 self.assert_log_lines([
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
815 ('INFO', '4'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
816 ('ERROR', '5'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
817 ('INFO', '6'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
818 ('ERROR', '7'),
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
819 ], stream=output)
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
820 # Original logger output is empty.
b9d76846bb1c Issue #11424: Fix bug in determining child loggers.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 63111
diff changeset
821 self.assert_log_lines([])
68321
d9cc58f93d72 Whitespace normalization.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 68316
diff changeset
822
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
823 class LogRecordStreamHandler(StreamRequestHandler):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
824
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
825 """Handler for a streaming logging request. It saves the log message in the
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
826 TCP server's 'log_output' attribute."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
827
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
828 TCP_LOG_END = "!!!END!!!"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
829
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
830 def handle(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
831 """Handle multiple requests - each expected to be of 4-byte length,
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
832 followed by the LogRecord in pickle format. Logs the record
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
833 according to whatever policy is configured locally."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
834 while True:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
835 chunk = self.connection.recv(4)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
836 if len(chunk) < 4:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
837 break
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
838 slen = struct.unpack(">L", chunk)[0]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
839 chunk = self.connection.recv(slen)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
840 while len(chunk) < slen:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
841 chunk = chunk + self.connection.recv(slen - len(chunk))
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
842 obj = self.unpickle(chunk)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
843 record = logging.makeLogRecord(obj)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
844 self.handle_log_record(record)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
845
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
846 def unpickle(self, data):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
847 return cPickle.loads(data)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
848
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
849 def handle_log_record(self, record):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
850 # If the end-of-messages sentinel is seen, tell the server to
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
851 # terminate.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
852 if self.TCP_LOG_END in record.msg:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
853 self.server.abort = 1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
854 return
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
855 self.server.log_output += record.msg + "\n"
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
856
28824
0cd8d570c591 New version from Vinaj, should solve the threading problems (hopefully).
Guido van Rossum <guido@python.org>
parents: 27932
diff changeset
857
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
858 class LogRecordSocketReceiver(ThreadingTCPServer):
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
859
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
860 """A simple-minded TCP socket-based logging receiver suitable for test
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
861 purposes."""
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
862
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
863 allow_reuse_address = 1
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
864 log_output = ""
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
865
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
866 def __init__(self, host='localhost',
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
867 port=logging.handlers.DEFAULT_TCP_LOGGING_PORT,
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
868 handler=LogRecordStreamHandler):
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
869 ThreadingTCPServer.__init__(self, (host, port), handler)
45451
8f994d697747 #2165: fix test_logging failure on some machines.
Georg Brandl <georg@python.org>
parents: 45375
diff changeset
870 self.abort = False
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
871 self.timeout = 0.1
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
872 self.finished = threading.Event()
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
873
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
874 def serve_until_stopped(self):
36448
388a583e7a63 Get test_logging to not hang when running under regrtest.py -R ::
Neal Norwitz <nnorwitz@gmail.com>
parents: 36425
diff changeset
875 while not self.abort:
36843
1848d75bbdb3 Backout the last hack and add in this new one.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36825
diff changeset
876 rd, wr, ex = select.select([self.socket.fileno()], [], [],
1848d75bbdb3 Backout the last hack and add in this new one.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36825
diff changeset
877 self.timeout)
1848d75bbdb3 Backout the last hack and add in this new one.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36825
diff changeset
878 if rd:
1848d75bbdb3 Backout the last hack and add in this new one.
Neal Norwitz <nnorwitz@gmail.com>
parents: 36825
diff changeset
879 self.handle_request()
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
880 # Notify the main thread that we're about to exit
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
881 self.finished.set()
36423
29bfbb588d93 Explicitly close the server socket.
Martin v. Löwis <martin@v.loewis.de>
parents: 36350
diff changeset
882 # close the listen socket
29bfbb588d93 Explicitly close the server socket.
Martin v. Löwis <martin@v.loewis.de>
parents: 36350
diff changeset
883 self.server_close()
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
884
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
885
61046
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
886 @unittest.skipUnless(threading, 'Threading required for this test.')
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
887 class SocketHandlerTest(BaseTest):
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
888
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
889 """Test for SocketHandler objects."""
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
890
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
891 def setUp(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
892 """Set up a TCP server to receive log messages, and a SocketHandler
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
893 pointing to that server's address and port."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
894 BaseTest.setUp(self)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
895 self.tcpserver = LogRecordSocketReceiver(port=0)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
896 self.port = self.tcpserver.socket.getsockname()[1]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
897 self.threads = [
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
898 threading.Thread(target=self.tcpserver.serve_until_stopped)]
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
899 for thread in self.threads:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
900 thread.start()
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
901
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
902 self.sock_hdlr = logging.handlers.SocketHandler('localhost', self.port)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
903 self.sock_hdlr.setFormatter(self.root_formatter)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
904 self.root_logger.removeHandler(self.root_logger.handlers[0])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
905 self.root_logger.addHandler(self.sock_hdlr)
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
906
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
907 def tearDown(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
908 """Shutdown the TCP server."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
909 try:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
910 self.tcpserver.abort = True
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
911 del self.tcpserver
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
912 self.root_logger.removeHandler(self.sock_hdlr)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
913 self.sock_hdlr.close()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
914 for thread in self.threads:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
915 thread.join(2.0)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
916 finally:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
917 BaseTest.tearDown(self)
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
918
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
919 def get_output(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
920 """Get the log output as received by the TCP server."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
921 # Signal the TCP receiver and wait for it to terminate.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
922 self.root_logger.critical(LogRecordStreamHandler.TCP_LOG_END)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
923 self.tcpserver.finished.wait(2.0)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
924 return self.tcpserver.log_output
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
925
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
926 def test_output(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
927 # The log message sent to the SocketHandler is properly received.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
928 logger = logging.getLogger("tcp")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
929 logger.error("spam")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
930 logger.debug("eggs")
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
931 self.assertEqual(self.get_output(), "spam\neggs\n")
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
932
45451
8f994d697747 #2165: fix test_logging failure on some machines.
Georg Brandl <georg@python.org>
parents: 45375
diff changeset
933
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
934 class MemoryTest(BaseTest):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
935
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
936 """Test memory persistence of logger objects."""
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
937
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
938 def setUp(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
939 """Create a dict to remember potentially destroyed objects."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
940 BaseTest.setUp(self)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
941 self._survivors = {}
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
942
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
943 def _watch_for_survival(self, *args):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
944 """Watch the given objects for survival, by creating weakrefs to
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
945 them."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
946 for obj in args:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
947 key = id(obj), repr(obj)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
948 self._survivors[key] = weakref.ref(obj)
45375
6550659dbc9d Move test_logging over to doctest.
Brett Cannon <bcannon@gmail.com>
parents: 41114
diff changeset
949
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53179
diff changeset
950 def _assertTruesurvival(self):
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
951 """Assert that all objects watched for survival have survived."""
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
952 # Trigger cycle breaking.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
953 gc.collect()
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
954 dead = []
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
955 for (id_, repr_), ref in self._survivors.items():
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
956 if ref() is None:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
957 dead.append(repr_)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
958 if dead:
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
959 self.fail("%d objects should have survived "
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
960 "but have been destroyed: %s" % (len(dead), ", ".join(dead)))
36307
beceb8e66b0b Added test for fileConfig. Contributed by Shane Hathaway.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 36163
diff changeset
961
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
962 def test_persistent_loggers(self):
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
963 # Logger objects are persistent and retain their configuration, even
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
964 # if visible references are destroyed.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
965 self.root_logger.setLevel(logging.INFO)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
966 foo = logging.getLogger("foo")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
967 self._watch_for_survival(foo)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
968 foo.setLevel(logging.DEBUG)
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
969 self.root_logger.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
970 foo.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
971 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
972 ('foo', 'DEBUG', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
973 ])
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
974 del foo
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
975 # foo has survived.
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53179
diff changeset
976 self._assertTruesurvival()
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
977 # foo has retained its settings.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
978 bar = logging.getLogger("foo")
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
979 bar.debug(self.next_message())
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
980 self.assert_log_lines([
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
981 ('foo', 'DEBUG', '2'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
982 ('foo', 'DEBUG', '3'),
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
983 ])
36307
beceb8e66b0b Added test for fileConfig. Contributed by Shane Hathaway.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 36163
diff changeset
984
51475
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
985
49009
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
986 class EncodingTest(BaseTest):
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
987 def test_encoding_plain_file(self):
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
988 # In Python 2.x, a plain file object is treated as having no encoding.
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
989 log = logging.getLogger("test")
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
990 fn = tempfile.mktemp(".log")
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
991 # the non-ascii data we write to the log.
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
992 data = "foo\x80"
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
993 try:
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
994 handler = logging.FileHandler(fn)
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
995 log.addHandler(handler)
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
996 try:
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
997 # write non-ascii data to the log.
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
998 log.warning(data)
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
999 finally:
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1000 log.removeHandler(handler)
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1001 handler.close()
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1002 # check we wrote exactly those bytes, ignoring trailing \n etc
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1003 f = open(fn)
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1004 try:
55002
6768b2350c57 convert usage of fail* to assert*
Benjamin Peterson <benjamin@python.org>
parents: 53179
diff changeset
1005 self.assertEqual(f.read().rstrip(), data)
49009
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1006 finally:
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1007 f.close()
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1008 finally:
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1009 if os.path.isfile(fn):
833d3ecfbbf0 Issue #3772: Fixed regression problem in StreamHandler.emit().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 48980
diff changeset
1010 os.remove(fn)
36307
beceb8e66b0b Added test for fileConfig. Contributed by Shane Hathaway.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 36163
diff changeset
1011
51475
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1012 def test_encoding_cyrillic_unicode(self):
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1013 log = logging.getLogger("test")
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1014 #Get a message in Unicode: Do svidanya in Cyrillic (meaning goodbye)
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1015 message = u'\u0434\u043e \u0441\u0432\u0438\u0434\u0430\u043d\u0438\u044f'
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1016 #Ensure it's written in a Cyrillic encoding
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1017 writer_class = codecs.getwriter('cp1251')
53180
cf190ff2a72c Issue #5768: Change to Unicode output logic and test case for same.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 51476
diff changeset
1018 writer_class.encoding = 'cp1251'
51475
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1019 stream = cStringIO.StringIO()
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1020 writer = writer_class(stream, 'strict')
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1021 handler = logging.StreamHandler(writer)
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1022 log.addHandler(handler)
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1023 try:
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1024 log.warning(message)
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1025 finally:
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1026 log.removeHandler(handler)
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1027 handler.close()
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1028 # check we wrote exactly those bytes, ignoring trailing \n etc
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1029 s = stream.getvalue()
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1030 #Compare against what the data should be when encoded in CP-1251
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1031 self.assertEqual(s, '\xe4\xee \xf1\xe2\xe8\xe4\xe0\xed\xe8\xff\n')
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1032
c17f9281a856 Issue #5170: Fixed Unicode output bug in logging and added test case. This is a regression which did not occur in 2.5.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1033
49955
878d40468c4e Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1034 class WarningsTest(BaseTest):
52666
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1035
49955
878d40468c4e Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1036 def test_warnings(self):
52666
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1037 with warnings.catch_warnings():
52867
f550e2463062 Issue #5695: Moved logging.captureWarnings() call inside with statement in WarningsTest.test_warnings.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 52666
diff changeset
1038 logging.captureWarnings(True)
52666
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1039 try:
52965
e23252a8ff59 Issue #5695: Minor tweak to improve the code as suggested by Brett Cannon and as implemented in the Py3K branch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 52867
diff changeset
1040 warnings.filterwarnings("always", category=UserWarning)
52666
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1041 file = cStringIO.StringIO()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1042 h = logging.StreamHandler(file)
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1043 logger = logging.getLogger("py.warnings")
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1044 logger.addHandler(h)
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1045 warnings.warn("I'm warning you...")
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1046 logger.removeHandler(h)
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1047 s = file.getvalue()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1048 h.close()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1049 self.assertTrue(s.find("UserWarning: I'm warning you...\n") > 0)
49955
878d40468c4e Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1050
52666
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1051 #See if an explicit file uses the original implementation
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1052 file = cStringIO.StringIO()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1053 warnings.showwarning("Explicit", UserWarning, "dummy.py", 42,
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1054 file, "Dummy line")
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1055 s = file.getvalue()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1056 file.close()
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1057 self.assertEqual(s,
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1058 "dummy.py:42: UserWarning: Explicit\n Dummy line\n")
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1059 finally:
b814b0c35347 test_logging was blindly clearing the warnings filter. This caused
Brett Cannon <bcannon@gmail.com>
parents: 51474
diff changeset
1060 logging.captureWarnings(False)
49955
878d40468c4e Issue #4384: Added logging integration with warnings module using captureWarnings(). This change includes a NullHandler which does nothing; it will be of use to library developers who want to avoid the "No handlers could be found for logger XXX" message which can appear if the library user doesn't configure logging.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 49109
diff changeset
1061
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1062
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1063 def formatFunc(format, datefmt=None):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1064 return logging.Formatter(format, datefmt)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1065
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1066 def handlerFunc():
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1067 return logging.StreamHandler()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1068
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1069 class CustomHandler(logging.StreamHandler):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1070 pass
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1071
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1072 class ConfigDictTest(BaseTest):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1073
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1074 """Reading logging config from a dictionary."""
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1075
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1076 expected_log_pat = r"^([\w]+) \+\+ ([\w]+)$"
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1077
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1078 # config0 is a standard configuration.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1079 config0 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1080 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1081 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1082 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1083 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1084 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1085 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1086 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1087 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1088 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1089 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1090 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1091 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1092 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1093 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1094 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1095 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1096 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1097 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1098 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1099
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1100 # config1 adds a little to the standard configuration.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1101 config1 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1102 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1103 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1104 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1105 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1106 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1107 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1108 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1109 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1110 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1111 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1112 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1113 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1114 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1115 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1116 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1117 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1118 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1119 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1120 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1121 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1122 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1123 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1124 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1125 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1126
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1127 # config2 has a subtle configuration error that should be reported
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1128 config2 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1129 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1130 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1131 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1132 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1133 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1134 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1135 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1136 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1137 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1138 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1139 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1140 'stream' : 'ext://sys.stdbout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1141 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1142 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1143 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1144 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1145 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1146 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1147 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1148 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1149 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1150 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1151 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1152 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1153
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1154 #As config1 but with a misspelt level on a handler
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1155 config2a = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1156 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1157 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1158 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1159 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1160 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1161 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1162 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1163 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1164 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1165 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1166 'level' : 'NTOSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1167 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1168 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1169 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1170 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1171 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1172 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1173 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1174 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1175 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1176 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1177 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1178 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1179 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1180
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1181
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1182 #As config1 but with a misspelt level on a logger
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1183 config2b = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1184 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1185 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1186 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1187 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1188 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1189 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1190 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1191 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1192 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1193 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1194 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1195 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1196 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1197 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1198 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1199 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1200 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1201 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1202 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1203 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1204 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1205 'level' : 'WRANING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1206 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1207 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1208
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1209 # config3 has a less subtle configuration error
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1210 config3 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1211 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1212 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1213 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1214 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1215 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1216 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1217 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1218 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1219 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1220 'formatter' : 'misspelled_name',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1221 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1222 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1223 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1224 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1225 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1226 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1227 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1228 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1229 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1230 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1231 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1232 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1233 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1234 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1235
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1236 # config4 specifies a custom formatter class to be loaded
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1237 config4 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1238 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1239 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1240 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1241 '()' : __name__ + '.ExceptionFormatter',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1242 'format' : '%(levelname)s:%(name)s:%(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1243 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1244 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1245 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1246 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1247 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1248 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1249 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1250 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1251 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1252 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1253 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1254 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1255 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1256 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1257 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1258
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1259 # As config4 but using an actual callable rather than a string
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1260 config4a = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1261 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1262 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1263 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1264 '()' : ExceptionFormatter,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1265 'format' : '%(levelname)s:%(name)s:%(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1266 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1267 'form2' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1268 '()' : __name__ + '.formatFunc',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1269 'format' : '%(levelname)s:%(name)s:%(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1270 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1271 'form3' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1272 '()' : formatFunc,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1273 'format' : '%(levelname)s:%(name)s:%(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1274 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1275 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1276 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1277 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1278 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1279 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1280 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1281 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1282 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1283 'hand2' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1284 '()' : handlerFunc,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1285 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1286 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1287 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1288 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1289 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1290 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1291 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1292
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1293 # config5 specifies a custom handler class to be loaded
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1294 config5 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1295 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1296 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1297 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1298 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1299 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1300 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1301 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1302 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1303 'class' : __name__ + '.CustomHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1304 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1305 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1306 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1307 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1308 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1309 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1310 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1311 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1312 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1313 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1314 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1315 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1316 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1317 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1318 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1319
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1320 # config6 specifies a custom handler class to be loaded
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1321 # but has bad arguments
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1322 config6 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1323 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1324 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1325 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1326 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1327 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1328 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1329 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1330 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1331 'class' : __name__ + '.CustomHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1332 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1333 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1334 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1335 '9' : 'invalid parameter name',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1336 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1337 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1338 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1339 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1340 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1341 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1342 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1343 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1344 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1345 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1346 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1347 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1348
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1349 #config 7 does not define compiler.parser but defines compiler.lexer
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1350 #so compiler.parser should be disabled after applying it
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1351 config7 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1352 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1353 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1354 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1355 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1356 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1357 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1358 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1359 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1360 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1361 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1362 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1363 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1364 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1365 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1366 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1367 'compiler.lexer' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1368 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1369 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1370 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1371 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1372 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1373 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1374 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1375 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1376
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1377 config8 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1378 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1379 'disable_existing_loggers' : False,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1380 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1381 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1382 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1383 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1384 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1385 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1386 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1387 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1388 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1389 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1390 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1391 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1392 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1393 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1394 'compiler' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1395 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1396 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1397 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1398 'compiler.lexer' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1399 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1400 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1401 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1402 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1403 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1404 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1405
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1406 config9 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1407 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1408 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1409 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1410 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1411 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1412 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1413 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1414 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1415 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1416 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1417 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1418 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1419 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1420 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1421 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1422 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1423 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1424 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1425 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1426 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1427 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1428 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1429 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1430 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1431
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1432 config9a = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1433 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1434 'incremental' : True,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1435 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1436 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1437 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1438 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1439 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1440 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1441 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1442 'level' : 'INFO',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1443 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1444 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1445 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1446
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1447 config9b = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1448 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1449 'incremental' : True,
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1450 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1451 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1452 'level' : 'INFO',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1453 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1454 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1455 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1456 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1457 'level' : 'INFO',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1458 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1459 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1460 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1461
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1462 #As config1 but with a filter added
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1463 config10 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1464 'version': 1,
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1465 'formatters': {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1466 'form1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1467 'format' : '%(levelname)s ++ %(message)s',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1468 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1469 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1470 'filters' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1471 'filt1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1472 'name' : 'compiler.parser',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1473 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1474 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1475 'handlers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1476 'hand1' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1477 'class' : 'logging.StreamHandler',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1478 'formatter' : 'form1',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1479 'level' : 'NOTSET',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1480 'stream' : 'ext://sys.stdout',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1481 'filters' : ['filt1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1482 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1483 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1484 'loggers' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1485 'compiler.parser' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1486 'level' : 'DEBUG',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1487 'filters' : ['filt1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1488 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1489 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1490 'root' : {
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1491 'level' : 'WARNING',
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1492 'handlers' : ['hand1'],
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1493 },
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1494 }
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1495
58703
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1496 #As config1 but using cfg:// references
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1497 config11 = {
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1498 'version': 1,
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1499 'true_formatters': {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1500 'form1' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1501 'format' : '%(levelname)s ++ %(message)s',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1502 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1503 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1504 'handler_configs': {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1505 'hand1' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1506 'class' : 'logging.StreamHandler',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1507 'formatter' : 'form1',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1508 'level' : 'NOTSET',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1509 'stream' : 'ext://sys.stdout',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1510 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1511 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1512 'formatters' : 'cfg://true_formatters',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1513 'handlers' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1514 'hand1' : 'cfg://handler_configs[hand1]',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1515 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1516 'loggers' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1517 'compiler.parser' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1518 'level' : 'DEBUG',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1519 'handlers' : ['hand1'],
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1520 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1521 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1522 'root' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1523 'level' : 'WARNING',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1524 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1525 }
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1526
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1527 #As config11 but missing the version key
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1528 config12 = {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1529 'true_formatters': {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1530 'form1' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1531 'format' : '%(levelname)s ++ %(message)s',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1532 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1533 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1534 'handler_configs': {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1535 'hand1' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1536 'class' : 'logging.StreamHandler',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1537 'formatter' : 'form1',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1538 'level' : 'NOTSET',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1539 'stream' : 'ext://sys.stdout',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1540 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1541 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1542 'formatters' : 'cfg://true_formatters',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1543 'handlers' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1544 'hand1' : 'cfg://handler_configs[hand1]',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1545 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1546 'loggers' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1547 'compiler.parser' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1548 'level' : 'DEBUG',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1549 'handlers' : ['hand1'],
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1550 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1551 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1552 'root' : {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1553 'level' : 'WARNING',
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1554 },
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1555 }
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1556
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1557 #As config11 but using an unsupported version
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1558 config13 = {
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1559 'version': 2,
58703
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1560 'true_formatters': {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1561 'form1' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1562 'format' : '%(levelname)s ++ %(message)s',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1563 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1564 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1565 'handler_configs': {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1566 'hand1' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1567 'class' : 'logging.StreamHandler',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1568 'formatter' : 'form1',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1569 'level' : 'NOTSET',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1570 'stream' : 'ext://sys.stdout',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1571 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1572 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1573 'formatters' : 'cfg://true_formatters',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1574 'handlers' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1575 'hand1' : 'cfg://handler_configs[hand1]',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1576 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1577 'loggers' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1578 'compiler.parser' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1579 'level' : 'DEBUG',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1580 'handlers' : ['hand1'],
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1581 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1582 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1583 'root' : {
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1584 'level' : 'WARNING',
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1585 },
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1586 }
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1587
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1588 def apply_config(self, conf):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1589 logging.config.dictConfig(conf)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1590
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1591 def test_config0_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1592 # A simple config which overrides the default settings.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1593 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1594 self.apply_config(self.config0)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1595 logger = logging.getLogger()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1596 # Won't output anything
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1597 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1598 # Outputs a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1599 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1600 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1601 ('ERROR', '2'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1602 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1603 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1604 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1605
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1606 def test_config1_ok(self, config=config1):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1607 # A config defining a sub-parser as well.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1608 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1609 self.apply_config(config)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1610 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1611 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1612 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1613 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1614 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1615 ('INFO', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1616 ('ERROR', '2'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1617 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1618 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1619 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1620
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1621 def test_config2_failure(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1622 # A simple config which overrides the default settings.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1623 self.assertRaises(StandardError, self.apply_config, self.config2)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1624
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1625 def test_config2a_failure(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1626 # A simple config which overrides the default settings.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1627 self.assertRaises(StandardError, self.apply_config, self.config2a)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1628
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1629 def test_config2b_failure(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1630 # A simple config which overrides the default settings.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1631 self.assertRaises(StandardError, self.apply_config, self.config2b)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1632
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1633 def test_config3_failure(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1634 # A simple config which overrides the default settings.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1635 self.assertRaises(StandardError, self.apply_config, self.config3)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1636
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1637 def test_config4_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1638 # A config specifying a custom formatter class.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1639 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1640 self.apply_config(self.config4)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1641 #logger = logging.getLogger()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1642 try:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1643 raise RuntimeError()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1644 except RuntimeError:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1645 logging.exception("just testing")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1646 sys.stdout.seek(0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
1647 self.assertEqual(output.getvalue(),
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1648 "ERROR:root:just testing\nGot a [RuntimeError]\n")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1649 # Original logger output is empty
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1650 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1651
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1652 def test_config4a_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1653 # A config specifying a custom formatter class.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1654 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1655 self.apply_config(self.config4a)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1656 #logger = logging.getLogger()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1657 try:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1658 raise RuntimeError()
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1659 except RuntimeError:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1660 logging.exception("just testing")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1661 sys.stdout.seek(0)
66348
614c84670c63 Merged revisions 86596 via svnmerge from
Ezio Melotti <ezio.melotti@gmail.com>
parents: 61172
diff changeset
1662 self.assertEqual(output.getvalue(),
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1663 "ERROR:root:just testing\nGot a [RuntimeError]\n")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1664 # Original logger output is empty
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1665 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1666
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1667 def test_config5_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1668 self.test_config1_ok(config=self.config5)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1669
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1670 def test_config6_failure(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1671 self.assertRaises(StandardError, self.apply_config, self.config6)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1672
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1673 def test_config7_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1674 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1675 self.apply_config(self.config1)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1676 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1677 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1678 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1679 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1680 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1681 ('INFO', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1682 ('ERROR', '2'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1683 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1684 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1685 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1686 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1687 self.apply_config(self.config7)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1688 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1689 self.assertTrue(logger.disabled)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1690 logger = logging.getLogger("compiler.lexer")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1691 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1692 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1693 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1694 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1695 ('INFO', '3'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1696 ('ERROR', '4'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1697 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1698 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1699 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1700
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1701 #Same as test_config_7_ok but don't disable old loggers.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1702 def test_config_8_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1703 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1704 self.apply_config(self.config1)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1705 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1706 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1707 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1708 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1709 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1710 ('INFO', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1711 ('ERROR', '2'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1712 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1713 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1714 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1715 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1716 self.apply_config(self.config8)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1717 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1718 self.assertFalse(logger.disabled)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1719 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1720 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1721 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1722 logger = logging.getLogger("compiler.lexer")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1723 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1724 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1725 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1726 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1727 ('INFO', '3'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1728 ('ERROR', '4'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1729 ('INFO', '5'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1730 ('ERROR', '6'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1731 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1732 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1733 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1734
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1735 def test_config_9_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1736 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1737 self.apply_config(self.config9)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1738 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1739 #Nothing will be output since both handler and logger are set to WARNING
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1740 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1741 self.assert_log_lines([], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1742 self.apply_config(self.config9a)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1743 #Nothing will be output since both handler is still set to WARNING
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1744 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1745 self.assert_log_lines([], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1746 self.apply_config(self.config9b)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1747 #Message should now be output
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1748 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1749 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1750 ('INFO', '3'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1751 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1752
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1753 def test_config_10_ok(self):
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1754 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1755 self.apply_config(self.config10)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1756 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1757 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1758 logger = logging.getLogger('compiler')
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1759 #Not output, because filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1760 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1761 logger = logging.getLogger('compiler.lexer')
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1762 #Not output, because filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1763 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1764 logger = logging.getLogger("compiler.parser.codegen")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1765 #Output, as not filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1766 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1767 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1768 ('WARNING', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1769 ('ERROR', '4'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1770 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1771
58703
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1772 def test_config11_ok(self):
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1773 self.test_config1_ok(self.config11)
304ce8fcc32a Added unit test for cfg:// resolution.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58692
diff changeset
1774
59402
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1775 def test_config12_failure(self):
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1776 self.assertRaises(StandardError, self.apply_config, self.config12)
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1777
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1778 def test_config13_failure(self):
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1779 self.assertRaises(StandardError, self.apply_config, self.config13)
120d6ccf26b0 Added schema version test in dictConfig.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58832
diff changeset
1780
61046
3a0484200034 Issue #7449, last part (11): fix many tests if thread support is disabled
Victor Stinner <victor.stinner@haypocalc.com>
parents: 59910
diff changeset
1781 @unittest.skipUnless(threading, 'listen() needs threading to work')
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1782 def setup_via_listener(self, text):
61172
56d831e6f508 Issue #8576: logging updated to remove usage of find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 61046
diff changeset
1783 # Ask for a randomly assigned port (by using port 0)
56d831e6f508 Issue #8576: logging updated to remove usage of find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 61046
diff changeset
1784 t = logging.config.listen(0)
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1785 t.start()
58757
609fa18b24bf make waiting for the server to start robust
Benjamin Peterson <benjamin@python.org>
parents: 58756
diff changeset
1786 t.ready.wait()
61172
56d831e6f508 Issue #8576: logging updated to remove usage of find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 61046
diff changeset
1787 # Now get the port allocated
56d831e6f508 Issue #8576: logging updated to remove usage of find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 61046
diff changeset
1788 port = t.port
58830
93676ae97c68 Issue #7857: Another attempt to keep the buildbots happy.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58829
diff changeset
1789 t.ready.clear()
58709
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1790 try:
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1791 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
58733
78e7992f2857 test_logging: minor tweaks to timeouts, listening tests marked as skipped.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58710
diff changeset
1792 sock.settimeout(2.0)
58709
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1793 sock.connect(('localhost', port))
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1794
58709
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1795 slen = struct.pack('>L', len(text))
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1796 s = slen + text
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1797 sentsofar = 0
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1798 left = len(s)
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1799 while left > 0:
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1800 sent = sock.send(s[sentsofar:])
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1801 sentsofar += sent
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1802 left -= sent
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1803 sock.close()
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1804 finally:
58830
93676ae97c68 Issue #7857: Another attempt to keep the buildbots happy.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58829
diff changeset
1805 t.ready.wait(2.0)
58709
b5ad2190dce8 Issue #7857: test_logging: listener test now uses find_unused_port().
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58703
diff changeset
1806 logging.config.stopListening()
58733
78e7992f2857 test_logging: minor tweaks to timeouts, listening tests marked as skipped.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58710
diff changeset
1807 t.join(2.0)
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1808
58733
78e7992f2857 test_logging: minor tweaks to timeouts, listening tests marked as skipped.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58710
diff changeset
1809 def test_listen_config_10_ok(self):
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1810 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1811 self.setup_via_listener(json.dumps(self.config10))
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1812 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1813 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1814 logger = logging.getLogger('compiler')
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1815 #Not output, because filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1816 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1817 logger = logging.getLogger('compiler.lexer')
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1818 #Not output, because filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1819 logger.warning(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1820 logger = logging.getLogger("compiler.parser.codegen")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1821 #Output, as not filtered
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1822 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1823 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1824 ('WARNING', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1825 ('ERROR', '4'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1826 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1827
58733
78e7992f2857 test_logging: minor tweaks to timeouts, listening tests marked as skipped.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58710
diff changeset
1828 def test_listen_config_1_ok(self):
58692
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1829 with captured_stdout() as output:
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1830 self.setup_via_listener(textwrap.dedent(ConfigFileTest.config1))
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1831 logger = logging.getLogger("compiler.parser")
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1832 # Both will output a message
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1833 logger.info(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1834 logger.error(self.next_message())
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1835 self.assert_log_lines([
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1836 ('INFO', '1'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1837 ('ERROR', '2'),
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1838 ], stream=output)
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1839 # Original logger output is empty.
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1840 self.assert_log_lines([])
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1841
f441422f6f55 Logging: Implemented PEP 391.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58063
diff changeset
1842
58779
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1843 class ManagerTest(BaseTest):
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1844 def test_manager_loggerclass(self):
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1845 logged = []
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1846
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1847 class MyLogger(logging.Logger):
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1848 def _log(self, level, msg, args, exc_info=None, extra=None):
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1849 logged.append(msg)
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1850
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1851 man = logging.Manager(None)
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1852 self.assertRaises(TypeError, man.setLoggerClass, int)
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1853 man.setLoggerClass(MyLogger)
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1854 logger = man.getLogger('test')
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1855 logger.warning('should appear in logged')
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1856 logging.warning('should not appear in logged')
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1857
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1858 self.assertEqual(logged, ['should appear in logged'])
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1859
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1860
59910
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1861 class ChildLoggerTest(BaseTest):
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1862 def test_child_loggers(self):
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1863 r = logging.getLogger()
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1864 l1 = logging.getLogger('abc')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1865 l2 = logging.getLogger('def.ghi')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1866 c1 = r.getChild('xyz')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1867 c2 = r.getChild('uvw.xyz')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1868 self.assertTrue(c1 is logging.getLogger('xyz'))
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1869 self.assertTrue(c2 is logging.getLogger('uvw.xyz'))
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1870 c1 = l1.getChild('def')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1871 c2 = c1.getChild('ghi')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1872 c3 = l1.getChild('def.ghi')
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1873 self.assertTrue(c1 is logging.getLogger('abc.def'))
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1874 self.assertTrue(c2 is logging.getLogger('abc.def.ghi'))
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1875 self.assertTrue(c2 is c3)
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1876
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1877
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1878 class HandlerTest(BaseTest):
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1879
77253
8817c295a8ee Changed comment on test skip.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 77073
diff changeset
1880 @unittest.skipIf(os.name == 'nt', 'WatchedFileHandler not appropriate for Windows.')
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1881 @unittest.skipUnless(threading, 'Threading required for this test.')
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1882 def test_race(self):
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1883 # Issue #14632 refers.
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1884 def remove_loop(fname, tries):
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1885 for _ in range(tries):
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1886 try:
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1887 os.unlink(fname)
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1888 except OSError:
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1889 pass
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1890 time.sleep(0.004 * random.randint(0, 4))
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1891
76550
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1892 del_count = 500
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1893 log_count = 500
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1894
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1895 for delay in (False, True):
76550
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1896 fd, fn = tempfile.mkstemp('.log', 'test_logging-3-')
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1897 os.close(fd)
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1898 remover = threading.Thread(target=remove_loop, args=(fn, del_count))
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1899 remover.daemon = True
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1900 remover.start()
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1901 h = logging.handlers.WatchedFileHandler(fn, delay=delay)
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1902 f = logging.Formatter('%(asctime)s: %(levelname)s: %(message)s')
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1903 h.setFormatter(f)
76550
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1904 try:
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1905 for _ in range(log_count):
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1906 time.sleep(0.005)
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1907 r = logging.makeLogRecord({'msg': 'testing' })
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1908 h.handle(r)
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1909 finally:
76727
e606c123244f Changed order of cleanup operations to be more sensible.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76550
diff changeset
1910 remover.join()
77057
9ab9bf20a4ea Ignore exceptions on test handler closing.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76727
diff changeset
1911 try:
9ab9bf20a4ea Ignore exceptions on test handler closing.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76727
diff changeset
1912 h.close()
9ab9bf20a4ea Ignore exceptions on test handler closing.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76727
diff changeset
1913 except ValueError:
9ab9bf20a4ea Ignore exceptions on test handler closing.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76727
diff changeset
1914 pass
76550
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1915 if os.path.exists(fn):
8b8b580e3fd3 Fixed test to work on Windows.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 76543
diff changeset
1916 os.unlink(fn)
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1917
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1918
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1919 # Set the locale to the platform-dependent default. I have no idea
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1920 # why the test does this, but in any case we save the current locale
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1921 # first and restore it at the end.
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1922 @run_with_locale('LC_ALL', '')
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1923 def test_main():
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1924 run_unittest(BuiltinLevelsTest, BasicFilterTest,
58779
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1925 CustomLevelsAndFiltersTest, MemoryHandlerTest,
6b82a2323501 Issue #7868: logging: added loggerClass attribute to Manager.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 58757
diff changeset
1926 ConfigFileTest, SocketHandlerTest, MemoryTest,
59910
806a8cafc997 logging: Added getChild utility method to Logger and added isEnabledFor method to LoggerAdapter.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 59901
diff changeset
1927 EncodingTest, WarningsTest, ConfigDictTest, ManagerTest,
76542
15a33d7d2b50 Issue #14632: Updated WatchedFileHandler to deal with race condition. Thanks to John Mulligan for the problem report and patch.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 73418
diff changeset
1928 ChildLoggerTest, HandlerTest)
36307
beceb8e66b0b Added test for fileConfig. Contributed by Shane Hathaway.
Vinay Sajip <vinay_sajip@yahoo.co.uk>
parents: 36163
diff changeset
1929
45623
cf3a80f1da7d Refactor test_logging to use unittest. This should finally solve the flakiness
Brett Cannon <bcannon@gmail.com>
parents: 45468
diff changeset
1930 if __name__ == "__main__":
27024
1098ccc84d63 SF #660795
Neal Norwitz <nnorwitz@gmail.com>
parents:
diff changeset
1931 test_main()