summaryrefslogtreecommitdiff
path: root/src/distutils2/tests/support.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/distutils2/tests/support.py')
-rw-r--r--src/distutils2/tests/support.py62
1 files changed, 34 insertions, 28 deletions
diff --git a/src/distutils2/tests/support.py b/src/distutils2/tests/support.py
index 0c69e58..1ff2217 100644
--- a/src/distutils2/tests/support.py
+++ b/src/distutils2/tests/support.py
@@ -4,13 +4,14 @@ Always import unittest from this module, it will be the right version
(standard library unittest for 3.2 and higher, third-party unittest2
release for older versions).
-Four helper classes are provided: LoggingSilencer, TempdirManager, EnvironGuard
-and WarningsCatcher. They are written to be used as mixins, e.g. ::
+Four helper classes are provided: LoggingCatcher, TempdirManager,
+EnvironGuard and WarningsCatcher. They are written to be used as mixins,
+e.g. ::
from distutils2.tests.support import unittest
- from distutils2.tests.support import LoggingSilencer
+ from distutils2.tests.support import LoggingCatcher
- class SomeTestCase(LoggingSilencer, unittest.TestCase):
+ class SomeTestCase(LoggingCatcher, unittest.TestCase):
If you need to define a setUp method on your test class, you have to
call the mixin class' setUp method or it won't work (same thing for
@@ -43,11 +44,11 @@ else:
# external release of same package for older versions
import unittest2 as unittest
-__all__ = ['LoggingSilencer', 'TempdirManager', 'EnvironGuard',
- 'DummyCommand', 'unittest']
+__all__ = ['LoggingCatcher', 'WarningsCatcher', 'TempdirManager',
+ 'EnvironGuard', 'DummyCommand', 'unittest']
-class LoggingSilencer(object):
+class LoggingCatcher(object):
"""TestCase-compatible mixin to catch logging calls.
Every log message that goes through distutils2.log will get appended to
@@ -57,7 +58,7 @@ class LoggingSilencer(object):
"""
def setUp(self):
- super(LoggingSilencer, self).setUp()
+ super(LoggingCatcher, self).setUp()
self.threshold = log.set_threshold(FATAL)
# when log is replaced by logging we won't need
# such monkey-patching anymore
@@ -68,7 +69,7 @@ class LoggingSilencer(object):
def tearDown(self):
log.set_threshold(self.threshold)
log.Log._log = self._old_log
- super(LoggingSilencer, self).tearDown()
+ super(LoggingCatcher, self).tearDown()
def _log(self, level, msg, args):
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
@@ -92,6 +93,30 @@ class LoggingSilencer(object):
del self.logs[:]
+class LoggingSilencer(object):
+ "Class that raises an exception to make sure the renaming is noticed."
+
+ def __init__(self, *args):
+ raise DeprecationWarning("LoggingSilencer renamed to LoggingCatcher")
+
+
+class WarningsCatcher(object):
+
+ def setUp(self):
+ self._orig_showwarning = warnings.showwarning
+ warnings.showwarning = self._record_showwarning
+ self.warnings = []
+
+ def _record_showwarning(self, message, category, filename, lineno,
+ file=None, line=None):
+ self.warnings.append({"message": message, "category": category,
+ "filename": filename, "lineno": lineno,
+ "file": file, "line": line})
+
+ def tearDown(self):
+ warnings.showwarning = self._orig_showwarning
+
+
class TempdirManager(object):
"""TestCase-compatible mixin to create temporary directories and files.
@@ -172,25 +197,6 @@ class EnvironGuard(object):
super(EnvironGuard, self).tearDown()
-class WarningsCatcher(object):
-
- def setUp(self):
- self._orig_showwarning = warnings.showwarning
- warnings.showwarning = self._record_showwarning
- self.warnings = []
-
- def _record_showwarning(self, message, category, filename, lineno, file=None, line=None):
- self.warnings.append({"message": message,
- "category": category,
- "filename": filename,
- "lineno": lineno,
- "file": file,
- "line": line})
-
- def tearDown(self):
- warnings.showwarning = self._orig_showwarning
-
-
class DummyCommand(object):
"""Class to store options for retrieval via set_undefined_options().