|
29 | 29 | from google.api_core import gapic_v1
|
30 | 30 | from google.api_core import grpc_helpers
|
31 | 31 | from google.api_core import grpc_helpers_async
|
| 32 | +from google.api_core import path_template |
32 | 33 | from google.auth import credentials as ga_credentials
|
33 | 34 | from google.auth.exceptions import MutualTLSChannelError
|
34 | 35 | from google.cloud.bigquery_connection_v1.services.connection_service import (
|
@@ -2608,6 +2609,9 @@ def test_connection_service_base_transport():
|
2608 | 2609 | with pytest.raises(NotImplementedError):
|
2609 | 2610 | getattr(transport, method)(request=object())
|
2610 | 2611 |
|
| 2612 | + with pytest.raises(NotImplementedError): |
| 2613 | + transport.close() |
| 2614 | + |
2611 | 2615 |
|
2612 | 2616 | @requires_google_auth_gte_1_25_0
|
2613 | 2617 | def test_connection_service_base_transport_with_credentials_file():
|
@@ -3111,3 +3115,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
3111 | 3115 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
3112 | 3116 | )
|
3113 | 3117 | prep.assert_called_once_with(client_info)
|
| 3118 | + |
| 3119 | + |
| 3120 | +@pytest.mark.asyncio |
| 3121 | +async def test_transport_close_async(): |
| 3122 | + client = ConnectionServiceAsyncClient( |
| 3123 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 3124 | + ) |
| 3125 | + with mock.patch.object( |
| 3126 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 3127 | + ) as close: |
| 3128 | + async with client: |
| 3129 | + close.assert_not_called() |
| 3130 | + close.assert_called_once() |
| 3131 | + |
| 3132 | + |
| 3133 | +def test_transport_close(): |
| 3134 | + transports = { |
| 3135 | + "grpc": "_grpc_channel", |
| 3136 | + } |
| 3137 | + |
| 3138 | + for transport, close_name in transports.items(): |
| 3139 | + client = ConnectionServiceClient( |
| 3140 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 3141 | + ) |
| 3142 | + with mock.patch.object( |
| 3143 | + type(getattr(client.transport, close_name)), "close" |
| 3144 | + ) as close: |
| 3145 | + with client: |
| 3146 | + close.assert_not_called() |
| 3147 | + close.assert_called_once() |
| 3148 | + |
| 3149 | + |
| 3150 | +def test_client_ctx(): |
| 3151 | + transports = [ |
| 3152 | + "grpc", |
| 3153 | + ] |
| 3154 | + for transport in transports: |
| 3155 | + client = ConnectionServiceClient( |
| 3156 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 3157 | + ) |
| 3158 | + # Test client calls underlying transport. |
| 3159 | + with mock.patch.object(type(client.transport), "close") as close: |
| 3160 | + close.assert_not_called() |
| 3161 | + with client: |
| 3162 | + pass |
| 3163 | + close.assert_called() |
0 commit comments