-
Notifications
You must be signed in to change notification settings - Fork 69
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
feat: add support for context manager in client #987
Conversation
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.
Looks good, just some nits around testing.
I think it would be good to have some autogenerated unit tests as well so we can keep generated code coverage at 100%.
Maybe something that injects a dummy transport that can tell us that it was told to enter, something like (strawman expressions in the template, use the correct ones :P )
class DummyTransport:
def __init__(self):
self.trigger_state = 0
def __enter__(self):
self.trigger_state = 1
def __exit__(self, *args, **kwargs):
self.trigger_state = 2
client = {{ api.module_name }}.{{ service.client_name }}(transport=DummyTransport())
assert c.transport.trigger_state == 0
with client:
assert c.transport.trigger_state == 1
assert c.transport.trigger_state == 2
And then associated mox tests for the grpc and rest transport enter/exit methods (I always have to steal mox setup from existing code).
gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2
Outdated
Show resolved
Hide resolved
Looks like golden files need to be updated. I can't get |
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.
Looks good, just a few more obnoxious nitpicking comments :)
gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Show resolved
Hide resolved
gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2
Outdated
Show resolved
Hide resolved
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.
gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2
Show resolved
Hide resolved
gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2
Outdated
Show resolved
Hide resolved
gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2
Outdated
Show resolved
Hide resolved
@lidizheng PTAL async client |
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.
The added context manager method looks good, just one minor comment.
gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2
Show resolved
Hide resolved
@software-dov @tseaver @tswast @busunkim96 PTAL. I've addressed all your comments. |
gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2
Outdated
Show resolved
Hide resolved
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
def close(self): | ||
"""Closes resources associated with the transport. | ||
|
||
:: warning:: |
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.
:: warning:: | |
.. warning:: |
Addresses feature request filed in #575.