Commits

Olemis Lang committed c2b7edc

Fix regressions in tracrpc test suite by bringing back again TracRpcTestCase.failUnlessRaises

Comments (0)

Files changed (2)

trunk/bhrpc/tests/__init__.py

         rpc_testenv.env.config.save()
         TracRpcTestCase.tearDown(self)
 
+    def failUnlessRaises(self, excClass, callableObj=None, *args, **kwargs):
+        """Fallback to unittest(2) implementation.
+        """
+        return unittest.TestCase.assertRaises(self, excClass, callableObj,
+                                     *args, **kwargs)
+
+    assertRaises = failUnlessRaises
+
 def test_suite():
     suite = unittest.TestSuite()
 

trunk/tracrpc/tests/__init__.py

                             self._testMethodName)
             log.info('=' * 70)
 
+        def failUnlessRaises(self, excClass, callableObj=None, *args, **kwargs):
+            """Enhanced assertions to detect exceptions."""
+            try:
+                callableObj(*args, **kwargs)
+            except excClass, e:
+                return e
+            except self.failureException :
+                raise
+            except Exception, e :
+                if hasattr(excClass, '__name__'): excName = excClass.__name__
+                else: excName = str(excClass)
+
+                if hasattr(e, '__name__'): excMsg = e.__name__
+                else: excMsg = str(e)
+
+                raise self.failureException("\n\nExpected %s\n\nGot %s : %s" % (
+                                        excName, e.__class__.__name__, excMsg))
+            else:
+                if hasattr(excClass,'__name__'): excName = excClass.__name__
+                else: excName = str(excClass)
+                raise self.failureException, "Expected %s\n\nNothing raised" % excName
+
+        assertRaises = failUnlessRaises