]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
corrected assert_raises to be consistent with existing assertRaises() unittest method
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Mar 2008 18:59:23 +0000 (18:59 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Mar 2008 18:59:23 +0000 (18:59 +0000)
test/orm/expire.py
test/testlib/testing.py

index 9c4b98251ef283a8e6994bdafe9c7f94654bd672..8d622dd0cdbadf8a7523a23e544d6203802967f6 100644 (file)
@@ -55,7 +55,8 @@ class ExpireTest(FixtureTest):
         s = create_session()
         u = s.get(User, 7)
         s.clear()
-        self.assert_raises(lambda: s.expire(u), exceptions.InvalidRequestError, r"is not persistent within this Session")
+
+        self.assertRaisesMessage(exceptions.InvalidRequestError, r"is not persistent within this Session", lambda: s.expire(u))
 
     def test_expire_doesntload_on_set(self):
         mapper(User, users)
@@ -691,7 +692,7 @@ class RefreshTest(FixtureTest):
         s = create_session()
         u = s.get(User, 7)
         s.clear()
-        self.assert_raises(lambda: s.refresh(u), exceptions.InvalidRequestError, r"is not persistent within this Session")
+        self.assertRaisesMessage(exceptions.InvalidRequestError, r"is not persistent within this Session", lambda: s.refresh(u))
         
     def test_refresh_expired(self):
         mapper(User, users)
index 3406e3504e30ce05a42f3ae75762f31cd7e1bf8f..1e24108dd431d41dfe5619a171647d512064026a 100644 (file)
@@ -459,13 +459,12 @@ class TestBase(unittest.TestCase):
         """overridden to not return docstrings"""
         return None
     
-    def assert_raises(self, callable_, except_cls, reg):
+    def assertRaisesMessage(self, except_cls, msg, callable_, ):
         try:
             callable_()
             assert False, "Callable did not raise expected exception"
-        except Exception, e:
-            assert isinstance(e, except_cls), "Exception was not an instance of '%s' ('%s')" % (except_cls, type(e))
-            assert re.search(reg, str(e)), "Callable raised non-matching exception: '%s'" % str(e)
+        except except_cls, e:
+            assert re.search(msg, str(e)), "Exception message did not match: '%s'" % str(e)
         
     if not hasattr(unittest.TestCase, 'assertTrue'):
         assertTrue = unittest.TestCase.failUnless