Created
April 23, 2014 02:45
-
-
Save mithrandi/11201260 to your computer and use it in GitHub Desktop.
SuccessResultOf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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