[Checkins] SVN: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py Factor out custom 'assertRaises' for reuse.

Tres Seaver cvs-admin at zope.org
Wed May 9 05:50:59 UTC 2012


Log message for revision 125752:
  Factor out custom 'assertRaises' for reuse.

Changed:
  U   zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py

-=-
Modified: zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py
===================================================================
--- zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py	2012-05-09 05:50:51 UTC (rev 125751)
+++ zope.configuration/branches/tseaver-test_cleanup/src/zope/configuration/tests/test_config.py	2012-05-09 05:50:55 UTC (rev 125752)
@@ -15,9 +15,26 @@
 """
 import unittest
 
+class _Catchable(object):
+    # Mixin for classes which need to make assertions about the exception
+    # instance.
+    def assertRaises(self, excClass, callableObj, *args, **kwargs):
+        # Morph stdlib version to return the raised exception
+        try:
+            callableObj(*args, **kwargs)
+        except excClass as exc:
+            return exc
+        if hasattr(excClass,'__name__'):
+            excName = excClass.__name__
+        else:
+            excName = str(excClass)
+        raise self.failureException("%s not raised" % excName)
 
-class ConfigurationContextTests(unittest.TestCase):
 
+class ConfigurationContextTests(_Catchable,
+                                unittest.TestCase,
+                               ):
+
     def _getTargetClass(self):
         from zope.configuration.config import ConfigurationContext
         return ConfigurationContext
@@ -25,17 +42,6 @@
     def _makeOne(self, *args, **kw):
         return self._getTargetClass()(*args, **kw)
 
-    def assertRaises(self, excClass, callableObj, *args, **kwargs):
-        # Morph stdlib version to return the raised exception
-        try:
-            callableObj(*args, **kwargs)
-        except excClass as exc:
-            return exc
-        else:
-            if hasattr(excClass,'__name__'): excName = excClass.__name__
-            else: excName = str(excClass)
-            raise self.failureException("%s not raised" % excName)
-
     def test_resolve_blank(self):
         c = self._makeOne()
         self.assertRaises(ValueError, c.resolve, '')



More information about the checkins mailing list