Skip to content

Commit

Permalink
fix: Add async context manager return types (#828)
Browse files Browse the repository at this point in the history
* fix: Add async context manager return types

chore: Mock return_value should not populate oneof message fields

chore: Support snippet generation for services that only support REST transport

chore: Update gapic-generator-python to v1.11.0
PiperOrigin-RevId: 545430278

Source-Link: googleapis/googleapis@601b532

Source-Link: googleapis/googleapis-gen@b3f18d0
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYjNmMThkMGY2NTYwYTg1NTAyMmZkMDU4ODY1ZTc2MjA0NzlkN2FmOSJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Jul 4, 2023
1 parent d5720f8 commit 475a160
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 43 deletions.
Expand Up @@ -2355,7 +2355,7 @@ async def list_hot_tablets(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableInstanceAdminAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Expand Up @@ -2671,7 +2671,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableTableAdminAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
2 changes: 1 addition & 1 deletion google/cloud/bigtable_v2/services/bigtable/async_client.py
Expand Up @@ -1210,7 +1210,7 @@ def read_change_stream(
# Done; return the response.
return response

async def __aenter__(self):
async def __aenter__(self) -> "BigtableAsyncClient":
return self

async def __aexit__(self, exc_type, exc, tb):
Expand Down
4 changes: 2 additions & 2 deletions google/cloud/bigtable_v2/types/bigtable.py
Expand Up @@ -80,7 +80,7 @@ class ReadRowsRequest(proto.Message):
request_stats_view (google.cloud.bigtable_v2.types.ReadRowsRequest.RequestStatsView):
The view into RequestStats, as described
above.
reversed_ (bool):
reversed (bool):
Experimental API - Please note that this API is currently
experimental and can change in the future.
Expand Down Expand Up @@ -139,7 +139,7 @@ class RequestStatsView(proto.Enum):
number=6,
enum=RequestStatsView,
)
reversed_: bool = proto.Field(
reversed: bool = proto.Field(
proto.BOOL,
number=7,
)
Expand Down
2 changes: 1 addition & 1 deletion scripts/fixup_bigtable_v2_keywords.py
Expand Up @@ -46,7 +46,7 @@ class bigtableCallTransformer(cst.CSTTransformer):
'ping_and_warm': ('name', 'app_profile_id', ),
'read_change_stream': ('table_name', 'app_profile_id', 'partition', 'start_time', 'continuation_tokens', 'end_time', 'heartbeat_duration', ),
'read_modify_write_row': ('table_name', 'row_key', 'rules', 'app_profile_id', ),
'read_rows': ('table_name', 'app_profile_id', 'rows', 'filter', 'rows_limit', 'request_stats_view', 'reversed_', ),
'read_rows': ('table_name', 'app_profile_id', 'rows', 'filter', 'rows_limit', 'request_stats_view', 'reversed', ),
'sample_row_keys': ('table_name', 'app_profile_id', ),
}

Expand Down
34 changes: 8 additions & 26 deletions tests/unit/gapic/bigtable_admin_v2/test_bigtable_instance_admin.py
Expand Up @@ -2425,11 +2425,6 @@ def test_get_cluster(request_type, transport: str = "grpc"):
state=instance.Cluster.State.READY,
serve_nodes=1181,
default_storage_type=common.StorageType.SSD,
cluster_config=instance.Cluster.ClusterConfig(
cluster_autoscaling_config=instance.Cluster.ClusterAutoscalingConfig(
autoscaling_limits=instance.AutoscalingLimits(min_serve_nodes=1600)
)
),
)
response = client.get_cluster(request)

Expand Down Expand Up @@ -3529,9 +3524,6 @@ def test_create_app_profile(request_type, transport: str = "grpc"):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)
response = client.create_app_profile(request)

Expand Down Expand Up @@ -3801,9 +3793,6 @@ def test_get_app_profile(request_type, transport: str = "grpc"):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)
response = client.get_app_profile(request)

Expand Down Expand Up @@ -4456,9 +4445,11 @@ async def test_list_app_profiles_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_app_profiles(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -6138,9 +6129,11 @@ async def test_list_hot_tablets_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_hot_tablets(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -8088,11 +8081,6 @@ def test_get_cluster_rest(request_type):
state=instance.Cluster.State.READY,
serve_nodes=1181,
default_storage_type=common.StorageType.SSD,
cluster_config=instance.Cluster.ClusterConfig(
cluster_autoscaling_config=instance.Cluster.ClusterAutoscalingConfig(
autoscaling_limits=instance.AutoscalingLimits(min_serve_nodes=1600)
)
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -9345,9 +9333,6 @@ def test_create_app_profile_rest(request_type):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -9670,9 +9655,6 @@ def test_get_app_profile_rest(request_type):
name="name_value",
etag="etag_value",
description="description_value",
multi_cluster_routing_use_any=instance.AppProfile.MultiClusterRoutingUseAny(
cluster_ids=["cluster_ids_value"]
),
)

# Wrap the value into a proper Response obj
Expand Down
18 changes: 12 additions & 6 deletions tests/unit/gapic/bigtable_admin_v2/test_bigtable_table_admin.py
Expand Up @@ -1691,9 +1691,11 @@ async def test_list_tables_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_tables(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -4457,9 +4459,11 @@ async def test_list_snapshots_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_snapshots(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down Expand Up @@ -6058,9 +6062,11 @@ async def test_list_backups_async_pages():
RuntimeError,
)
pages = []
async for page_ in (
# Workaround issue in python 3.9 related to code coverage by adding `# pragma: no branch`
# See https://github.com/googleapis/gapic-generator-python/pull/1174#issuecomment-1025132372
async for page_ in ( # pragma: no branch
await client.list_backups(request={})
).pages: # pragma: no branch
).pages:
pages.append(page_)
for page_, token in zip(pages, ["abc", "def", "ghi", ""]):
assert page_.raw_page.next_page_token == token
Expand Down
6 changes: 1 addition & 5 deletions tests/unit/gapic/bigtable_v2/test_bigtable.py
Expand Up @@ -5316,11 +5316,7 @@ def test_read_change_stream_rest(request_type):
# Mock the http request call within the method and fake a response.
with mock.patch.object(type(client.transport._session), "request") as req:
# Designate an appropriate value for the returned response.
return_value = bigtable.ReadChangeStreamResponse(
data_change=bigtable.ReadChangeStreamResponse.DataChange(
type_=bigtable.ReadChangeStreamResponse.DataChange.Type.USER
),
)
return_value = bigtable.ReadChangeStreamResponse()

# Wrap the value into a proper Response obj
response_value = Response()
Expand Down

0 comments on commit 475a160

Please sign in to comment.