- Notifications
You must be signed in to change notification settings - Fork95
feat: AsyncIO Integration [Part 3]#29
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
| classFakeUnaryUnaryCall(_WrappedUnaryUnaryCall): | ||
| """Fake implementation for unary-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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| classFakeStreamUnaryCall(_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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| asyncdefwait_for_connection(self): | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Are these intended for use by tests only? I'd prefer they be namedMock... instead ofFake... but don't feel too strongly about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I consideredMock... naming, but they are not magic mock objects. It might misdirect users' expectation of its behavior. I'm happy to change if you have better naming.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Let's leave it as is then.@software-dov do you have any thoughts here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
+1 to not mock naming, although I'm a little confused as to why they don't live in the unit test file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think leaving them here makes it easier for dependent libraries to use it in their own tests.
(HttpMock in the apiary library for instance)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I think the 'correct' think to do then would be to have a testlib. I am in general not a fan of mixing test code and production code, but it's not a hill I'm willing to die on.
lidizheng left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
@busunkim96 Thank you for the suggestions. PTALA.
Uh oh!
There was an error while loading.Please reload this page.
| classFakeUnaryUnaryCall(_WrappedUnaryUnaryCall): | ||
| """Fake implementation for unary-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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| classFakeStreamUnaryCall(_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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| asyncdefwait_for_connection(self): | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I consideredMock... naming, but they are not magic mock objects. It might misdirect users' expectation of its behavior. I'm happy to change if you have better naming.
| ifclient_infoisnotNone: | ||
| user_agent_metadata= [client_info.to_grpc_metadata()] | ||
| else: | ||
| user_agent_metadata=None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Style nit: what about
metadata= [client_info.to_grpc_metadata()]ifclient_infoisnotNoneelseNone
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Good idea. Updated to the suggested style.
| classFakeUnaryUnaryCall(_WrappedUnaryUnaryCall): | ||
| """Fake implementation for unary-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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| classFakeStreamUnaryCall(_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=yieldfromself._future.__await__() | ||
| returnresponse | ||
| asyncdefwait_for_connection(self): | ||
| pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
+1 to not mock naming, although I'm a little confused as to why they don't live in the unit test file.
lidizheng commentedJun 3, 2020
@software-dov PTALA. |
busunkim96 commentedJun 4, 2020
@lidizheng It looks like the unit tests need to be tweaked: |
software-dov left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
LGTM. Just one minor optional tweak and a vote from my end that the test classes be moved into a standalone test library.
Uh oh!
There was an error while loading.Please reload this page.
* LRO client* gRPC wrappers & helpers* With unit tests & docs
🤖 I have created a release \*beep\* \*boop\* ---## [1.18.0](https://www.github.com/googleapis/python-api-core/compare/v1.17.0...v1.18.0) (2020-06-04)### Features* [CBT-6 helper] Exposing Retry._deadline as a property ([#20](https://www.github.com/googleapis/python-api-core/issues/20)) ([7be1e59](https://www.github.com/googleapis/python-api-core/commit/7be1e59e9d75c112f346d2b76dce3dd60e3584a1))* add client_encryped_cert_source to ClientOptions ([#31](https://www.github.com/googleapis/python-api-core/issues/31)) ([e4eaec0](https://www.github.com/googleapis/python-api-core/commit/e4eaec0ff255114138d3715280f86d34d861a6fa))* AsyncIO Integration [Part 2] ([#28](https://www.github.com/googleapis/python-api-core/issues/28)) ([dd9b2f3](https://www.github.com/googleapis/python-api-core/commit/dd9b2f38a70e85952cc05552ec8070cdf29ddbb4)), closes [#23](https://www.github.com/googleapis/python-api-core/issues/23)* First batch of AIO integration ([#26](https://www.github.com/googleapis/python-api-core/issues/26)) ([a82f289](https://www.github.com/googleapis/python-api-core/commit/a82f2892b8f219b82e120e6ed9f4070869c28be7))* third batch of AsyncIO integration ([#29](https://www.github.com/googleapis/python-api-core/issues/29)) ([7d8d580](https://www.github.com/googleapis/python-api-core/commit/7d8d58075a92e93662747d36a2d55b5e9f0943e1))---This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Children PR of#26 and#28.
This PR includes AsyncIO version of:
Related#23