Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add loggingutils in test.support
  • Loading branch information
shihai1991 committed Apr 19, 2020
commit 9545fba75106726098dac9defaacbbc18c311ce3
33 changes: 0 additions & 33 deletions Lib/test/support/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import importlib
import importlib.util
import locale
import logging.handlers
import nntplib
import os
import platform
Expand Down Expand Up @@ -2522,38 +2521,6 @@ def optim_args_from_interpreter_flags():
optimization settings in sys.flags."""
return subprocess._optim_args_from_interpreter_flags()

#============================================================
# Support for assertions about logging.
#============================================================

class TestHandler(logging.handlers.BufferingHandler):
def __init__(self, matcher):
# BufferingHandler takes a "capacity" argument
# so as to know when to flush. As we're overriding
# shouldFlush anyway, we can set a capacity of zero.
# You can call flush() manually to clear out the
# buffer.
logging.handlers.BufferingHandler.__init__(self, 0)
self.matcher = matcher

def shouldFlush(self):
return False

def emit(self, record):
self.format(record)
self.buffer.append(record.__dict__)

def matches(self, **kwargs):
"""
Look for a saved dict whose keys/values match the supplied arguments.
"""
result = False
for d in self.buffer:
if self.matcher.matches(d, **kwargs):
result = True
break
return result

class Matcher(object):

_partial_matches = ('msg', 'message')
Expand Down
40 changes: 40 additions & 0 deletions Lib/test/support/loggingutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Utilities to support asyncio in the Python regression tests."""

import logging.handlers

__all__ = [
# logging
"TestHandler",
]

#============================================================
# Support for assertions about logging.
#============================================================

class TestHandler(logging.handlers.BufferingHandler):
def __init__(self, matcher):
# BufferingHandler takes a "capacity" argument
# so as to know when to flush. As we're overriding
# shouldFlush anyway, we can set a capacity of zero.
# You can call flush() manually to clear out the
# buffer.
logging.handlers.BufferingHandler.__init__(self, 0)
self.matcher = matcher

def shouldFlush(self):
return False

def emit(self, record):
self.format(record)
self.buffer.append(record.__dict__)

def matches(self, **kwargs):
"""
Look for a saved dict whose keys/values match the supplied arguments.
"""
result = False
for d in self.buffer:
if self.matcher.matches(d, **kwargs):
result = True
break
return result