summaryrefslogtreecommitdiff
path: root/taskflow/test.py
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2014-02-20 11:12:48 +0000
committerGerrit Code Review <review@openstack.org>2014-02-20 11:12:48 +0000
commita285c3c39f85e8c7fb6837a8a99f3cdacbe3fea0 (patch)
treee283efad0a39a5df714e7f7fde3e16409ed9a43d /taskflow/test.py
parent05d69bc73589ba156c4c7b5b787668bb785fe2a9 (diff)
parent082b5c54d50c0c15146222f42f20c1e30661c111 (diff)
downloadtaskflow-a285c3c39f85e8c7fb6837a8a99f3cdacbe3fea0.tar.gz
Merge "Run action-engine tests with worker-based engine"
Diffstat (limited to 'taskflow/test.py')
-rw-r--r--taskflow/test.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/taskflow/test.py b/taskflow/test.py
index fb27fd0..fe69ffc 100644
--- a/taskflow/test.py
+++ b/taskflow/test.py
@@ -20,6 +20,9 @@ from testtools import compat
from testtools import matchers
from testtools import testcase
+from taskflow import exceptions
+from taskflow.tests import utils
+
class GreaterThanEqual(object):
"""Matches if the item is geq than the matchers reference object."""
@@ -33,6 +36,24 @@ class GreaterThanEqual(object):
return matchers.Mismatch("%s was not >= %s" % (other, self.source))
+class FailureRegexpMatcher(object):
+ """Matches if the failure was caused by the given exception and its string
+ matches to the given pattern.
+ """
+
+ def __init__(self, exc_class, pattern):
+ self.exc_class = exc_class
+ self.pattern = pattern
+
+ def match(self, failure):
+ for cause in failure:
+ if cause.check(self.exc_class) is not None:
+ return matchers.MatchesRegex(
+ self.pattern).match(cause.exception_str)
+ return matchers.Mismatch("The `%s` wasn't caused by the `%s`" %
+ (failure, self.exc_class))
+
+
class TestCase(testcase.TestCase):
"""Test case base class for all taskflow unit tests."""
@@ -89,6 +110,17 @@ class TestCase(testcase.TestCase):
else:
current_tail = current_tail[super_index + 1:]
+ def assertFailuresRegexp(self, exc_class, pattern, callable_obj, *args,
+ **kwargs):
+ """Assert that the callable failed with the given exception and its
+ string matches to the given pattern.
+ """
+ try:
+ with utils.wrap_all_failures():
+ callable_obj(*args, **kwargs)
+ except exceptions.WrappedFailure as e:
+ self.assertThat(e, FailureRegexpMatcher(exc_class, pattern))
+
class MockTestCase(TestCase):