diff options
author | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 13:19:43 -0700 |
---|---|---|
committer | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 13:19:43 -0700 |
commit | e6838673bda9af1e9bf7c4f71b25cf3e3dfc1253 (patch) | |
tree | 9b3a790337eee838225caa031f8051123157e6f0 /test/__init__.py | |
parent | c9df3d807f7134f58f4a84dc8b80e9dc98c62f3a (diff) | |
download | python-urllib3-e6838673bda9af1e9bf7c4f71b25cf3e3dfc1253.tar python-urllib3-e6838673bda9af1e9bf7c4f71b25cf3e3dfc1253.tar.gz |
Imported Upstream version 1.11
Diffstat (limited to 'test/__init__.py')
-rw-r--r-- | test/__init__.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/__init__.py b/test/__init__.py index 2fce71c..172493c 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -2,6 +2,7 @@ import warnings import sys import errno import functools +import logging import socket from nose.plugins.skip import SkipTest @@ -91,3 +92,37 @@ def requires_network(test): raise SkipTest(msg) raise return wrapper + + +class _ListHandler(logging.Handler): + def __init__(self): + super(_ListHandler, self).__init__() + self.records = [] + + def emit(self, record): + self.records.append(record) + + +class LogRecorder(object): + def __init__(self, target=logging.root): + super(LogRecorder, self).__init__() + self._target = target + self._handler = _ListHandler() + + @property + def records(self): + return self._handler.records + + def install(self): + self._target.addHandler(self._handler) + + def uninstall(self): + self._target.removeHandler(self._handler) + + def __enter__(self): + self.install() + return self.records + + def __exit__(self, exc_type, exc_value, traceback): + self.uninstall() + return False |