portage.tests.TestCase: Add assertRaisesMsg() from pkgcore
authorSebastian Luther <SebastianLuther@gmx.de>
Fri, 23 Jul 2010 12:25:11 +0000 (14:25 +0200)
committerZac Medico <zmedico@gentoo.org>
Fri, 23 Jul 2010 16:47:13 +0000 (09:47 -0700)
pym/portage/tests/__init__.py

index 7048471984e69e128cff1051c2a95931e19018b9..393ecf78c6d18976ab11d0fa59086ceec483b6d1 100644 (file)
@@ -154,6 +154,23 @@ class TestCase(unittest.TestCase):
                        if ok: result.addSuccess(self)
                finally:
                        result.stopTest(self)
+
+       def assertRaisesMsg(self, msg, excClass, callableObj, *args, **kwargs):
+               """Fail unless an exception of class excClass is thrown
+                  by callableObj when invoked with arguments args and keyword
+                  arguments kwargs. If a different type of exception is
+                  thrown, it will not be caught, and the test case will be
+                  deemed to have suffered an error, exactly as for an
+                  unexpected exception.
+               """
+               try:
+                   callableObj(*args, **kwargs)
+               except excClass:
+                   return
+               else:
+                   if hasattr(excClass,'__name__'): excName = excClass.__name__
+                   else: excName = str(excClass)
+                   raise self.failureException("%s not raised: %s" % (excName, msg))
                        
 class TextTestRunner(unittest.TextTestRunner):
        """