|
32 | 32 | from google.api_core import grpc_helpers_async |
33 | 33 | from google.api_core import operation_async # type: ignore |
34 | 34 | from google.api_core import operations_v1 |
| 35 | +from google.api_core import path_template |
35 | 36 | from google.auth import credentials as ga_credentials |
36 | 37 | from google.auth.exceptions import MutualTLSChannelError |
37 | 38 | from google.cloud.vpcaccess_v1.services.vpc_access_service import ( |
@@ -1611,6 +1612,9 @@ def test_vpc_access_service_base_transport(): |
1611 | 1612 | with pytest.raises(NotImplementedError): |
1612 | 1613 | getattr(transport, method)(request=object()) |
1613 | 1614 |
|
| 1615 | + with pytest.raises(NotImplementedError): |
| 1616 | + transport.close() |
| 1617 | + |
1614 | 1618 | # Additionally, the LRO client (a property) should |
1615 | 1619 | # also raise NotImplementedError |
1616 | 1620 | with pytest.raises(NotImplementedError): |
@@ -2124,3 +2128,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): |
2124 | 2128 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, |
2125 | 2129 | ) |
2126 | 2130 | prep.assert_called_once_with(client_info) |
| 2131 | + |
| 2132 | + |
| 2133 | +@pytest.mark.asyncio |
| 2134 | +async def test_transport_close_async(): |
| 2135 | + client = VpcAccessServiceAsyncClient( |
| 2136 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 2137 | + ) |
| 2138 | + with mock.patch.object( |
| 2139 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 2140 | + ) as close: |
| 2141 | + async with client: |
| 2142 | + close.assert_not_called() |
| 2143 | + close.assert_called_once() |
| 2144 | + |
| 2145 | + |
| 2146 | +def test_transport_close(): |
| 2147 | + transports = { |
| 2148 | + "grpc": "_grpc_channel", |
| 2149 | + } |
| 2150 | + |
| 2151 | + for transport, close_name in transports.items(): |
| 2152 | + client = VpcAccessServiceClient( |
| 2153 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2154 | + ) |
| 2155 | + with mock.patch.object( |
| 2156 | + type(getattr(client.transport, close_name)), "close" |
| 2157 | + ) as close: |
| 2158 | + with client: |
| 2159 | + close.assert_not_called() |
| 2160 | + close.assert_called_once() |
| 2161 | + |
| 2162 | + |
| 2163 | +def test_client_ctx(): |
| 2164 | + transports = [ |
| 2165 | + "grpc", |
| 2166 | + ] |
| 2167 | + for transport in transports: |
| 2168 | + client = VpcAccessServiceClient( |
| 2169 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 2170 | + ) |
| 2171 | + # Test client calls underlying transport. |
| 2172 | + with mock.patch.object(type(client.transport), "close") as close: |
| 2173 | + close.assert_not_called() |
| 2174 | + with client: |
| 2175 | + pass |
| 2176 | + close.assert_called() |
0 commit comments