| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -3,7 +3,6 @@ | |
| import sys | ||
| import functools | ||
| import difflib | ||
| import logging | ||
| import pprint | ||
| import re | ||
| import warnings | ||
| Expand Down Expand Up | @@ -300,26 +299,6 @@ def __exit__(self, exc_type, exc_value, tb): | |
| _LoggingWatcher = collections.namedtuple("_LoggingWatcher", | ||
| ["records", "output"]) | ||
|
|
||
|
|
||
| class _CapturingHandler(logging.Handler): | ||
| """ | ||
| A logging handler capturing all (raw and formatted) logging output. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| logging.Handler.__init__(self) | ||
| self.watcher = _LoggingWatcher([], []) | ||
|
|
||
| def flush(self): | ||
| pass | ||
|
|
||
| def emit(self, record): | ||
| self.watcher.records.append(record) | ||
| msg = self.format(record) | ||
| self.watcher.output.append(msg) | ||
|
|
||
|
|
||
|
|
||
| class _AssertLogsContext(_BaseTestCaseContext): | ||
| """A context manager used to implement TestCase.assertLogs().""" | ||
|
|
||
| Expand All | @@ -328,18 +307,39 @@ class _AssertLogsContext(_BaseTestCaseContext): | |
| def __init__(self, test_case, logger_name, level): | ||
| _BaseTestCaseContext.__init__(self, test_case) | ||
| self.logger_name = logger_name | ||
| import logging | ||
| self.logging = logging | ||
| if level: | ||
| self.level = logging._nameToLevel.get(level, level) | ||
| else: | ||
| self.level = logging.INFO | ||
| self.msg = None | ||
|
|
||
| def __enter__(self): | ||
| logging = self.logging | ||
| if isinstance(self.logger_name, logging.Logger): | ||
| logger = self.logger = self.logger_name | ||
| else: | ||
| logger = self.logger = logging.getLogger(self.logger_name) | ||
| formatter = logging.Formatter(self.LOGGING_FORMAT) | ||
|
|
||
| class _CapturingHandler(logging.Handler): | ||
|
Comment thread
Outdated
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityI dislike defining a new _CapturingHandler class each time _AssertLogsContext context manager is used :-( Maybe a lazy import could be used, something similar to PR #19600?
Sorry, something went wrong.
serhiy-storchaka reacted with thumbs up emoji
All reactions
|
||
| """ | ||
| A logging handler capturing all (raw and formatted) logging output. | ||
| """ | ||
|
|
||
| def __init__(self): | ||
| logging.Handler.__init__(self) | ||
| self.watcher = _LoggingWatcher([], []) | ||
|
|
||
| def flush(self): | ||
| pass | ||
|
|
||
| def emit(self, record): | ||
| self.watcher.records.append(record) | ||
| msg = self.format(record) | ||
| self.watcher.output.append(msg) | ||
|
|
||
| handler = _CapturingHandler() | ||
| handler.setFormatter(formatter) | ||
| self.watcher = handler.watcher | ||
| Expand All | @@ -361,7 +361,7 @@ def __exit__(self, exc_type, exc_value, tb): | |
| if len(self.watcher.records) == 0: | ||
| self._raiseFailure( | ||
| "no logs of level {} or higher triggered on {}" | ||
| .format(logging.getLevelName(self.level), self.logger.name)) | ||
| .format(self.logging.getLevelName(self.level), self.logger.name)) | ||
|
|
||
|
|
||
| class _OrderedChainMap(collections.ChainMap): | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityHm, I am not sure it's only test_logging use this common class forever.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.