|
33 | 33 | from google.api_core import grpc_helpers_async
|
34 | 34 | from google.api_core import operation_async # type: ignore
|
35 | 35 | from google.api_core import operations_v1
|
| 36 | +from google.api_core import path_template |
36 | 37 | from google.auth import credentials as ga_credentials
|
37 | 38 | from google.auth.exceptions import MutualTLSChannelError
|
38 | 39 | from google.cloud.devtools.cloudbuild_v1.services.cloud_build import (
|
@@ -4386,6 +4387,9 @@ def test_cloud_build_base_transport():
|
4386 | 4387 | with pytest.raises(NotImplementedError):
|
4387 | 4388 | getattr(transport, method)(request=object())
|
4388 | 4389 |
|
| 4390 | + with pytest.raises(NotImplementedError): |
| 4391 | + transport.close() |
| 4392 | + |
4389 | 4393 | # Additionally, the LRO client (a property) should
|
4390 | 4394 | # also raise NotImplementedError
|
4391 | 4395 | with pytest.raises(NotImplementedError):
|
@@ -5060,3 +5064,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
5060 | 5064 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
5061 | 5065 | )
|
5062 | 5066 | prep.assert_called_once_with(client_info)
|
| 5067 | + |
| 5068 | + |
| 5069 | +@pytest.mark.asyncio |
| 5070 | +async def test_transport_close_async(): |
| 5071 | + client = CloudBuildAsyncClient( |
| 5072 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 5073 | + ) |
| 5074 | + with mock.patch.object( |
| 5075 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 5076 | + ) as close: |
| 5077 | + async with client: |
| 5078 | + close.assert_not_called() |
| 5079 | + close.assert_called_once() |
| 5080 | + |
| 5081 | + |
| 5082 | +def test_transport_close(): |
| 5083 | + transports = { |
| 5084 | + "grpc": "_grpc_channel", |
| 5085 | + } |
| 5086 | + |
| 5087 | + for transport, close_name in transports.items(): |
| 5088 | + client = CloudBuildClient( |
| 5089 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 5090 | + ) |
| 5091 | + with mock.patch.object( |
| 5092 | + type(getattr(client.transport, close_name)), "close" |
| 5093 | + ) as close: |
| 5094 | + with client: |
| 5095 | + close.assert_not_called() |
| 5096 | + close.assert_called_once() |
| 5097 | + |
| 5098 | + |
| 5099 | +def test_client_ctx(): |
| 5100 | + transports = [ |
| 5101 | + "grpc", |
| 5102 | + ] |
| 5103 | + for transport in transports: |
| 5104 | + client = CloudBuildClient( |
| 5105 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 5106 | + ) |
| 5107 | + # Test client calls underlying transport. |
| 5108 | + with mock.patch.object(type(client.transport), "close") as close: |
| 5109 | + close.assert_not_called() |
| 5110 | + with client: |
| 5111 | + pass |
| 5112 | + close.assert_called() |
0 commit comments