Skip to content

Instantly share code, notes, and snippets.

@mithrandi
Created April 23, 2014 02:45
Show Gist options
  • Save mithrandi/11201260 to your computer and use it in GitHub Desktop.
Save mithrandi/11201260 to your computer and use it in GitHub Desktop.
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