Created
November 17, 2012 09:57
-
-
Save truemped/4094605 to your computer and use it in GitHub Desktop.
Tornado Asynchronous Mock
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 mock import CallableMixin, NonCallableMock | |
class AsyncCallableMixin(CallableMixin): | |
"""Change the __call__ method such that it does not return but call the | |
`callback` kwarg with the return value. | |
""" | |
def __call__(_mock_self, *args, **kwargs): | |
cb = kwargs.get('callback', None) | |
_mock_self._mock_check_sig(*args, **kwargs) | |
if cb: | |
del kwargs['callback'] | |
result = _mock_self._mock_call(*args, **kwargs) | |
cb(result) | |
else: | |
return _mock_self._mock_call(*args, **kwargs) | |
class AsyncMock(AsyncCallableMixin, NonCallableMock): | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment