Skip to content
This repository has been archived by the owner on Nov 29, 2023. It is now read-only.

Commit

Permalink
fix: Add async context manager return types (#539)
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 2db15f0 commit 7c081a6
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1188,7 +1188,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1290,7 +1290,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1045,7 +1045,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1147,7 +1147,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1984,7 +1984,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1623,7 +1623,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1725,7 +1725,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1425,7 +1425,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1527,7 +1527,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -973,7 +973,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1075,7 +1075,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1773,7 +1773,7 @@ async def test_iam_permissions(
# Done; return the response.
return response

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

async def __aexit__(self, exc_type, exc, tb):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1563,7 +1563,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down Expand Up @@ -1665,7 +1665,7 @@ def __call__(
request_kwargs = json_format.MessageToDict(request)
transcoded_request = path_template.transcode(http_options, **request_kwargs)

body = json.loads(json.dumps(transcoded_request["body"]))
body = json.dumps(transcoded_request["body"])
uri = transcoded_request["uri"]
method = transcoded_request["method"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
],
"language": "PYTHON",
"name": "google-cloud-dataproc",
"version": "5.4.1"
"version": "0.1.0"
},
"snippets": [
{
Expand Down
36 changes: 4 additions & 32 deletions tests/unit/gapic/dataproc_v1/test_autoscaling_policy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -791,11 +791,6 @@ def test_create_autoscaling_policy(request_type, transport: str = "grpc"):
call.return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)
response = client.create_autoscaling_policy(request)

Expand Down Expand Up @@ -1057,11 +1052,6 @@ def test_update_autoscaling_policy(request_type, transport: str = "grpc"):
call.return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)
response = client.update_autoscaling_policy(request)

Expand Down Expand Up @@ -1313,11 +1303,6 @@ def test_get_autoscaling_policy(request_type, transport: str = "grpc"):
call.return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)
response = client.get_autoscaling_policy(request)

Expand Down Expand Up @@ -1983,9 +1968,11 @@ async def test_list_autoscaling_policies_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_autoscaling_policies(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 @@ -2266,11 +2253,6 @@ def test_create_autoscaling_policy_rest(request_type):
return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -2593,11 +2575,6 @@ def test_update_autoscaling_policy_rest(request_type):
return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)

# Wrap the value into a proper Response obj
Expand Down Expand Up @@ -2894,11 +2871,6 @@ def test_get_autoscaling_policy_rest(request_type):
return_value = autoscaling_policies.AutoscalingPolicy(
id="id_value",
name="name_value",
basic_algorithm=autoscaling_policies.BasicAutoscalingAlgorithm(
yarn_config=autoscaling_policies.BasicYarnAutoscalingConfig(
graceful_decommission_timeout=duration_pb2.Duration(seconds=751)
)
),
)

# Wrap the value into a proper Response obj
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/gapic/dataproc_v1/test_batch_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1015,9 +1015,6 @@ def test_get_batch(request_type, transport: str = "grpc"):
state_message="state_message_value",
creator="creator_value",
operation="operation_value",
pyspark_batch=batches.PySparkBatch(
main_python_file_uri="main_python_file_uri_value"
),
)
response = client.get_batch(request)

Expand Down Expand Up @@ -1651,9 +1648,11 @@ async def test_list_batches_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_batches(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 @@ -2343,9 +2342,6 @@ def test_get_batch_rest(request_type):
state_message="state_message_value",
creator="creator_value",
operation="operation_value",
pyspark_batch=batches.PySparkBatch(
main_python_file_uri="main_python_file_uri_value"
),
)

# Wrap the value into a proper Response obj
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/gapic/dataproc_v1/test_cluster_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -2513,9 +2513,11 @@ async def test_list_clusters_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_clusters(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
Loading

0 comments on commit 7c081a6

Please sign in to comment.