MCPcopy Index your code
hub / github.com/python/cpython / test_subclass_logger_cache

Method test_subclass_logger_cache

Lib/test/test_logging.py:5224–5253  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5222 self.assertEqual(logging.getLoggerClass(), logging.Logger)
5223
5224 def test_subclass_logger_cache(self):
5225 # bpo-37258
5226 message = []
5227
5228 class MyLogger(logging.getLoggerClass()):
5229 def __init__(self, name='MyLogger', level=logging.NOTSET):
5230 super().__init__(name, level)
5231 message.append('initialized')
5232
5233 logging.setLoggerClass(MyLogger)
5234 logger = logging.getLogger('just_some_logger')
5235 self.assertEqual(message, ['initialized'])
5236 stream = io.StringIO()
5237 h = logging.StreamHandler(stream)
5238 logger.addHandler(h)
5239 try:
5240 logger.setLevel(logging.DEBUG)
5241 logger.debug("hello")
5242 self.assertEqual(stream.getvalue().strip(), "hello")
5243
5244 stream.truncate(0)
5245 stream.seek(0)
5246
5247 logger.setLevel(logging.INFO)
5248 logger.debug("hello")
5249 self.assertEqual(stream.getvalue(), "")
5250 finally:
5251 logger.removeHandler(h)
5252 h.close()
5253 logging.setLoggerClass(logging.Logger)
5254
5255 def test_logging_at_shutdown(self):
5256 # bpo-20037: Doing text I/O late at interpreter shutdown must not crash

Callers

nothing calls this directly

Calls 12

getvalueMethod · 0.95
setLoggerClassMethod · 0.80
getLoggerMethod · 0.80
addHandlerMethod · 0.80
removeHandlerMethod · 0.80
assertEqualMethod · 0.45
setLevelMethod · 0.45
debugMethod · 0.45
stripMethod · 0.45
truncateMethod · 0.45
seekMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected