Skip to content
Permalink
Browse files
feat: add context manager support in client (#187)
- [ ] Regenerate this pull request now.

chore: fix docstring for first attribute of protos

committer: @busunkim96
PiperOrigin-RevId: 401271153

Source-Link: googleapis/googleapis@787f8c9

Source-Link: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot committed Oct 8, 2021
1 parent f4f200f commit a4e2cd4654ae6b3f785727e279ce362798368598
Showing with 268 additions and 14 deletions.
  1. +6 −0 google/cloud/errorreporting_v1beta1/services/error_group_service/async_client.py
  2. +14 −4 google/cloud/errorreporting_v1beta1/services/error_group_service/client.py
  3. +9 −0 google/cloud/errorreporting_v1beta1/services/error_group_service/transports/base.py
  4. +3 −0 google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc.py
  5. +3 −0 google/cloud/errorreporting_v1beta1/services/error_group_service/transports/grpc_asyncio.py
  6. +6 −0 google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py
  7. +14 −4 google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py
  8. +9 −0 google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/base.py
  9. +3 −0 google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc.py
  10. +3 −0 google/cloud/errorreporting_v1beta1/services/error_stats_service/transports/grpc_asyncio.py
  11. +6 −0 google/cloud/errorreporting_v1beta1/services/report_errors_service/async_client.py
  12. +14 −4 google/cloud/errorreporting_v1beta1/services/report_errors_service/client.py
  13. +9 −0 google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/base.py
  14. +3 −0 google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc.py
  15. +3 −0 google/cloud/errorreporting_v1beta1/services/report_errors_service/transports/grpc_asyncio.py
  16. +1 −0 google/cloud/errorreporting_v1beta1/types/common.py
  17. +2 −0 google/cloud/errorreporting_v1beta1/types/error_group_service.py
  18. +7 −1 google/cloud/errorreporting_v1beta1/types/error_stats_service.py
  19. +3 −1 google/cloud/errorreporting_v1beta1/types/report_errors_service.py
  20. +50 −0 tests/unit/gapic/errorreporting_v1beta1/test_error_group_service.py
  21. +50 −0 tests/unit/gapic/errorreporting_v1beta1/test_error_stats_service.py
  22. +50 −0 tests/unit/gapic/errorreporting_v1beta1/test_report_errors_service.py
@@ -314,6 +314,12 @@ async def update_group(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -341,10 +341,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def get_group(
@@ -498,6 +495,19 @@ def update_group(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -163,6 +163,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def get_group(
self,
@@ -279,5 +279,8 @@ def update_group(
)
return self._stubs["update_group"]

def close(self):
self.grpc_channel.close()


__all__ = ("ErrorGroupServiceGrpcTransport",)
@@ -284,5 +284,8 @@ def update_group(
)
return self._stubs["update_group"]

def close(self):
return self.grpc_channel.close()


__all__ = ("ErrorGroupServiceGrpcAsyncIOTransport",)
@@ -442,6 +442,12 @@ async def delete_events(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -344,10 +344,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_group_stats(
@@ -626,6 +623,19 @@ def delete_events(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -165,6 +165,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def list_group_stats(
self,
@@ -312,5 +312,8 @@ def delete_events(
)
return self._stubs["delete_events"]

def close(self):
self.grpc_channel.close()


__all__ = ("ErrorStatsServiceGrpcTransport",)
@@ -316,5 +316,8 @@ def delete_events(
)
return self._stubs["delete_events"]

def close(self):
return self.grpc_channel.close()


__all__ = ("ErrorStatsServiceGrpcAsyncIOTransport",)
@@ -262,6 +262,12 @@ async def report_error_event(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -329,10 +329,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def report_error_event(
@@ -438,6 +435,19 @@ def report_error_event(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
@@ -159,6 +159,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def report_error_event(
self,
@@ -269,5 +269,8 @@ def report_error_event(
)
return self._stubs["report_error_event"]

def close(self):
self.grpc_channel.close()


__all__ = ("ReportErrorsServiceGrpcTransport",)
@@ -272,5 +272,8 @@ def report_error_event(
)
return self._stubs["report_error_event"]

def close(self):
return self.grpc_channel.close()


__all__ = ("ReportErrorsServiceGrpcAsyncIOTransport",)
@@ -44,6 +44,7 @@ class ResolutionStatus(proto.Enum):

class ErrorGroup(proto.Message):
r"""Description of a group of similar error events.
Attributes:
name (str):
The group resource name.
@@ -26,6 +26,7 @@

class GetGroupRequest(proto.Message):
r"""A request to return an individual group.
Attributes:
group_name (str):
Required. The group resource name. Written as
@@ -41,6 +42,7 @@ class GetGroupRequest(proto.Message):

class UpdateGroupRequest(proto.Message):
r"""A request to replace the existing data for the given group.
Attributes:
group (google.cloud.errorreporting_v1beta1.types.ErrorGroup):
Required. The group which replaces the
@@ -59,6 +59,7 @@ class ErrorGroupOrder(proto.Enum):

class ListGroupStatsRequest(proto.Message):
r"""Specifies a set of ``ErrorGroupStats`` to return.
Attributes:
project_name (str):
Required. The resource name of the Google Cloud Platform
@@ -127,6 +128,7 @@ class ListGroupStatsRequest(proto.Message):

class ListGroupStatsResponse(proto.Message):
r"""Contains a set of requested error group stats.
Attributes:
error_group_stats (Sequence[google.cloud.errorreporting_v1beta1.types.ErrorGroupStats]):
The error group stats which match the given
@@ -255,6 +257,7 @@ class TimedCount(proto.Message):

class ListEventsRequest(proto.Message):
r"""Specifies a set of error events to return.
Attributes:
project_name (str):
Required. The resource name of the Google Cloud Platform
@@ -296,6 +299,7 @@ class ListEventsRequest(proto.Message):

class ListEventsResponse(proto.Message):
r"""Contains a set of requested error events.
Attributes:
error_events (Sequence[google.cloud.errorreporting_v1beta1.types.ErrorEvent]):
The error events which match the given
@@ -370,6 +374,7 @@ class ServiceContextFilter(proto.Message):

class DeleteEventsRequest(proto.Message):
r"""Deletes all events in the project.
Attributes:
project_name (str):
Required. The resource name of the Google Cloud Platform
@@ -384,7 +389,8 @@ class DeleteEventsRequest(proto.Message):


class DeleteEventsResponse(proto.Message):
r"""Response message for deleting error events. """
r"""Response message for deleting error events.
"""


__all__ = tuple(sorted(__protobuf__.manifest))
@@ -31,6 +31,7 @@

class ReportErrorEventRequest(proto.Message):
r"""A request for reporting an individual error event.
Attributes:
project_name (str):
Required. The resource name of the Google Cloud Platform
@@ -50,7 +51,8 @@ class ReportErrorEventRequest(proto.Message):
class ReportErrorEventResponse(proto.Message):
r"""Response for reporting an individual error event.
Data may be added to this message in the future.
"""
"""


class ReportedErrorEvent(proto.Message):
@@ -29,6 +29,7 @@
from google.api_core import gapic_v1
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import path_template
from google.auth import credentials as ga_credentials
from google.auth.exceptions import MutualTLSChannelError
from google.cloud.errorreporting_v1beta1.services.error_group_service import (
@@ -1037,6 +1038,9 @@ def test_error_group_service_base_transport():
with pytest.raises(NotImplementedError):
getattr(transport, method)(request=object())

with pytest.raises(NotImplementedError):
transport.close()


@requires_google_auth_gte_1_25_0
def test_error_group_service_base_transport_with_credentials_file():
@@ -1517,3 +1521,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
)
prep.assert_called_once_with(client_info)


@pytest.mark.asyncio
async def test_transport_close_async():
client = ErrorGroupServiceAsyncClient(
credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio",
)
with mock.patch.object(
type(getattr(client.transport, "grpc_channel")), "close"
) as close:
async with client:
close.assert_not_called()
close.assert_called_once()


def test_transport_close():
transports = {
"grpc": "_grpc_channel",
}

for transport, close_name in transports.items():
client = ErrorGroupServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport
)
with mock.patch.object(
type(getattr(client.transport, close_name)), "close"
) as close:
with client:
close.assert_not_called()
close.assert_called_once()


def test_client_ctx():
transports = [
"grpc",
]
for transport in transports:
client = ErrorGroupServiceClient(
credentials=ga_credentials.AnonymousCredentials(), transport=transport
)
# Test client calls underlying transport.
with mock.patch.object(type(client.transport), "close") as close:
close.assert_not_called()
with client:
pass
close.assert_called()
Loading

0 comments on commit a4e2cd4

Please sign in to comment.