Skip to content

WIP: AsyncIO integration #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 20 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add FakeStreamUnaryCall to ease mocking
  • Loading branch information
lidizheng committed Apr 22, 2020
commit 96f8b170c7e1bbce5591f42698887a8ad227c050
21 changes: 21 additions & 0 deletions google/api_core/grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,24 @@ def __init__(self, response=object()):
def __await__(self):
response = yield from self._future.__await__()
return response


class FakeStreamUnaryCall(_WrappedStreamUnaryCall):
"""Fake implementation for stream-unary RPCs.

It is a dummy object for response message. Supply the intended response
upon the initialization, and the coroutine will return the exact response
message.
"""

def __init__(self, response=object()):
self.response = response
self._future = asyncio.get_event_loop().create_future()
self._future.set_result(self.response)

def __await__(self):
response = yield from self._future.__await__()
return response

async def wait_for_connection(self):
pass