|
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.privatecatalog_v1beta1.services.private_catalog import ( |
@@ -1431,6 +1432,9 @@ def test_private_catalog_base_transport(): |
1431 | 1432 | with pytest.raises(NotImplementedError): |
1432 | 1433 | getattr(transport, method)(request=object()) |
1433 | 1434 |
|
| 1435 | + with pytest.raises(NotImplementedError): |
| 1436 | + transport.close() |
| 1437 | + |
1434 | 1438 |
|
1435 | 1439 | @requires_google_auth_gte_1_25_0 |
1436 | 1440 | def test_private_catalog_base_transport_with_credentials_file(): |
@@ -1949,3 +1953,49 @@ def test_client_withDEFAULT_CLIENT_INFO(): |
1949 | 1953 | credentials=ga_credentials.AnonymousCredentials(), client_info=client_info, |
1950 | 1954 | ) |
1951 | 1955 | prep.assert_called_once_with(client_info) |
| 1956 | + |
| 1957 | + |
| 1958 | +@pytest.mark.asyncio |
| 1959 | +async def test_transport_close_async(): |
| 1960 | + client = PrivateCatalogAsyncClient( |
| 1961 | + credentials=ga_credentials.AnonymousCredentials(), transport="grpc_asyncio", |
| 1962 | + ) |
| 1963 | + with mock.patch.object( |
| 1964 | + type(getattr(client.transport, "grpc_channel")), "close" |
| 1965 | + ) as close: |
| 1966 | + async with client: |
| 1967 | + close.assert_not_called() |
| 1968 | + close.assert_called_once() |
| 1969 | + |
| 1970 | + |
| 1971 | +def test_transport_close(): |
| 1972 | + transports = { |
| 1973 | + "grpc": "_grpc_channel", |
| 1974 | + } |
| 1975 | + |
| 1976 | + for transport, close_name in transports.items(): |
| 1977 | + client = PrivateCatalogClient( |
| 1978 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1979 | + ) |
| 1980 | + with mock.patch.object( |
| 1981 | + type(getattr(client.transport, close_name)), "close" |
| 1982 | + ) as close: |
| 1983 | + with client: |
| 1984 | + close.assert_not_called() |
| 1985 | + close.assert_called_once() |
| 1986 | + |
| 1987 | + |
| 1988 | +def test_client_ctx(): |
| 1989 | + transports = [ |
| 1990 | + "grpc", |
| 1991 | + ] |
| 1992 | + for transport in transports: |
| 1993 | + client = PrivateCatalogClient( |
| 1994 | + credentials=ga_credentials.AnonymousCredentials(), transport=transport |
| 1995 | + ) |
| 1996 | + # Test client calls underlying transport. |
| 1997 | + with mock.patch.object(type(client.transport), "close") as close: |
| 1998 | + close.assert_not_called() |
| 1999 | + with client: |
| 2000 | + pass |
| 2001 | + close.assert_called() |
0 commit comments