From afc0cdfe7449c7821e22fe8ff9c27cf9eca1e7e0 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 6 Mar 2008 18:59:23 +0000 Subject: [PATCH] corrected assert_raises to be consistent with existing assertRaises() unittest method --- test/orm/expire.py | 5 +++-- test/testlib/testing.py | 7 +++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/orm/expire.py b/test/orm/expire.py index 9c4b98251e..8d622dd0cd 100644 --- a/test/orm/expire.py +++ b/test/orm/expire.py @@ -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) diff --git a/test/testlib/testing.py b/test/testlib/testing.py index 3406e3504e..1e24108dd4 100644 --- a/test/testlib/testing.py +++ b/test/testlib/testing.py @@ -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 -- 2.47.3