summaryrefslogtreecommitdiff
path: root/test/testlib/testing.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2008-03-06 18:44:45 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2008-03-06 18:44:45 +0000
commit4f35e8120fa7269f4090cef3b5e19fe16ce6c15a (patch)
tree1750a656845bea0008f10fcd6761bd8ebf1e546a /test/testlib/testing.py
parent63b904881b02ac765ff2665eae57f51de5ce67b9 (diff)
downloadsqlalchemy-4f35e8120fa7269f4090cef3b5e19fe16ce6c15a.tar.gz
- added assert_raises() to TestBase class
- session.refresh() and session.expire() raise an error when called on instances which are not persistent within the session - session._validate_persistent() properly raises an error for false check
Diffstat (limited to 'test/testlib/testing.py')
-rw-r--r--test/testlib/testing.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/test/testlib/testing.py b/test/testlib/testing.py
index 1d7062c88..3406e3504 100644
--- a/test/testlib/testing.py
+++ b/test/testlib/testing.py
@@ -458,7 +458,15 @@ class TestBase(unittest.TestCase):
def shortDescription(self):
"""overridden to not return docstrings"""
return None
-
+
+ def assert_raises(self, callable_, except_cls, reg):
+ 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)
+
if not hasattr(unittest.TestCase, 'assertTrue'):
assertTrue = unittest.TestCase.failUnless
if not hasattr(unittest.TestCase, 'assertFalse'):
@@ -524,7 +532,7 @@ class AssertsExecutionResults(object):
result = list(result)
print repr(result)
self.assert_list(result, class_, objects)
-
+
def assert_list(self, result, class_, list):
self.assert_(len(result) == len(list),
"result list is not the same size as test list, " +