Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SuccessResultOf
from testtools.matchers import Mismatch
class SuccessResultOf(object):
"""
Match if a Deferred has fired with a result.
"""
def __init__(self, resultMatcher=None):
self.resultMatcher = resultMatcher
def __str__(self):
return 'SuccessResultOf(%s)' % (self.resultMatcher or '')
def match(self, matchee):
result = []
matchee.addBoth(result.append)
if not result:
return Mismatch(
'Success result expected on %r, found no result instead' % (
matchee,))
elif isinstance(result[0], Failure):
return Mismatch(
'Success result expected on %r,'
' found failure result instead:\n%s' % (
matchee, result[0].getTraceback()))
elif self.resultMatcher:
return self.resultMatcher.match(result[0])
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment