|
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.resourcesettings_v1.services.resource_settings_service import (
|
@@ -1346,6 +1347,9 @@ def test_resource_settings_service_base_transport():
|
1346 | 1347 | with pytest.raises(NotImplementedError):
|
1347 | 1348 | getattr(transport, method)(request=object())
|
1348 | 1349 |
|
| 1350 | + with pytest.raises(NotImplementedError): |
| 1351 | + transport.close() |
| 1352 | + |
1349 | 1353 |
|
1350 | 1354 | @requires_google_auth_gte_1_25_0
|
1351 | 1355 | def test_resource_settings_service_base_transport_with_credentials_file():
|
@@ -1830,3 +1834,49 @@ def test_client_withDEFAULT_CLIENT_INFO():
|
1830 | 1834 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info,
|
1831 | 1835 | )
|
1832 | 1836 | prep.assert_called_once_with(client_info)
|
| 1837 | + |
| 1838 | + |
| 1839 | +@pytest.mark.asyncio |
| 1840 | +async def test_transport_close_async(): |
| 1841 | + client = ResourceSettingsServiceAsyncClient( |
| 1842 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 1843 | + ) |
| 1844 | + with mock.patch.object( |
| 1845 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 1846 | + ) as close: |
| 1847 | + async with client: |
| 1848 | + close.assert_not_called() |
| 1849 | + close.assert_called_once() |
| 1850 | + |
| 1851 | + |
| 1852 | +def test_transport_close(): |
| 1853 | + transports = { |
| 1854 | + "grpc": "_grpc_channel", |
| 1855 | + } |
| 1856 | + |
| 1857 | + for transport, close_name in transports.items(): |
| 1858 | + client = ResourceSettingsServiceClient( |
| 1859 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1860 | + ) |
| 1861 | + with mock.patch.object( |
| 1862 | + type(getattr(client.transport, close_name)), "close" |
| 1863 | + ) as close: |
| 1864 | + with client: |
| 1865 | + close.assert_not_called() |
| 1866 | + close.assert_called_once() |
| 1867 | + |
| 1868 | + |
| 1869 | +def test_client_ctx(): |
| 1870 | + transports = [ |
| 1871 | + "grpc", |
| 1872 | + ] |
| 1873 | + for transport in transports: |
| 1874 | + client = ResourceSettingsServiceClient( |
| 1875 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1876 | + ) |
| 1877 | + # Test client calls underlying transport. |
| 1878 | + with mock.patch.object(type(client.transport), "close") as close: |
| 1879 | + close.assert_not_called() |
| 1880 | + with client: |
| 1881 | + pass |
| 1882 | + close.assert_called() |
0 commit comments