From 866b8e22dbdf49806d3108959eb645eda0b950ac Mon Sep 17 00:00:00 2001 From: rhatgadkar-goog Date: Thu, 14 Nov 2024 00:10:35 +0000 Subject: [PATCH] Fix lint errors using black --- google/cloud/alloydb/connector/async_connector.py | 4 +--- google/cloud/alloydb/connector/connector.py | 4 +--- tests/unit/mocks.py | 12 +++++++++--- tests/unit/test_async_connector.py | 9 +++++++-- tests/unit/test_connector.py | 10 +++++++--- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/google/cloud/alloydb/connector/async_connector.py b/google/cloud/alloydb/connector/async_connector.py index 0086bb0..349b880 100644 --- a/google/cloud/alloydb/connector/async_connector.py +++ b/google/cloud/alloydb/connector/async_connector.py @@ -212,9 +212,7 @@ async def _remove_cached(self, instance_uri: str) -> None: """Stops all background refreshes and deletes the connection info cache from the map of caches. """ - logger.debug( - f"['{instance_uri}']: Removing connection info from cache" - ) + logger.debug(f"['{instance_uri}']: Removing connection info from cache") # remove cache from stored caches and close it cache = self._cache.pop(instance_uri) await cache.close() diff --git a/google/cloud/alloydb/connector/connector.py b/google/cloud/alloydb/connector/connector.py index 25047ba..c833f62 100644 --- a/google/cloud/alloydb/connector/connector.py +++ b/google/cloud/alloydb/connector/connector.py @@ -344,9 +344,7 @@ async def _remove_cached(self, instance_uri: str) -> None: """Stops all background refreshes and deletes the connection info cache from the map of caches. """ - logger.debug( - f"['{instance_uri}']: Removing connection info from cache" - ) + logger.debug(f"['{instance_uri}']: Removing connection info from cache") # remove cache from stored caches and close it cache = self._cache.pop(instance_uri) await cache.close() diff --git a/tests/unit/mocks.py b/tests/unit/mocks.py index b35b14e..e9074f3 100644 --- a/tests/unit/mocks.py +++ b/tests/unit/mocks.py @@ -210,12 +210,16 @@ def __init__( i = FakeInstance() # The instances that currently exist and the client can send API requests to. - self.existing_instances = [f"projects/{i.project}/locations/{i.region}/clusters/{i.cluster}/instances/{i.name}"] + self.existing_instances = [ + f"projects/{i.project}/locations/{i.region}/clusters/{i.cluster}/instances/{i.name}" + ] async def _get_metadata(self, *args: Any, **kwargs: Any) -> str: instance_uri = f"projects/{self.instance.project}/locations/{self.instance.region}/clusters/{self.instance.cluster}/instances/{self.instance.name}" if instance_uri not in self.existing_instances: - raise ClientResponseError(RequestInfo(url = instance_uri, method = "GET", headers = None), 404) + raise ClientResponseError( + RequestInfo(url=instance_uri, method="GET", headers=None), 404 + ) return self.instance.ip_addrs async def _get_client_certificate( @@ -227,7 +231,9 @@ async def _get_client_certificate( ) -> Tuple[str, List[str]]: instance_uri = f"projects/{self.instance.project}/locations/{self.instance.region}/clusters/{self.instance.cluster}/instances/{self.instance.name}" if instance_uri not in self.existing_instances: - raise ClientResponseError(RequestInfo(url = instance_uri, method = "POST", headers = None), 404) + raise ClientResponseError( + RequestInfo(url=instance_uri, method="POST", headers=None), 404 + ) root_cert, intermediate_cert, server_cert = self.instance.get_pem_certs() # encode public key to bytes pub_key_bytes: rsa.RSAPublicKey = serialization.load_pem_public_key( diff --git a/tests/unit/test_async_connector.py b/tests/unit/test_async_connector.py index 2db0b94..2649be4 100644 --- a/tests/unit/test_async_connector.py +++ b/tests/unit/test_async_connector.py @@ -299,7 +299,10 @@ async def test_async_connect_bad_ip_type( == f"Incorrect value for ip_type, got '{bad_ip_type}'. Want one of: 'PUBLIC', 'PRIVATE', 'PSC'." ) -async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials) -> None: + +async def test_Connector_remove_cached_bad_instance( + credentials: FakeCredentials, +) -> None: """When a Connector attempts to retrieve connection info for a non-existent instance, it should delete the instance from the cache and ensure no background refresh happens (which would be @@ -307,7 +310,9 @@ async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials """ instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance" async with AsyncConnector(credentials=credentials) as connector: - connector._client = FakeAlloyDBClient(instance = FakeInstance(name = "bad-test-instance")) + connector._client = FakeAlloyDBClient( + instance=FakeInstance(name="bad-test-instance") + ) cache = RefreshAheadCache(instance_uri, connector._client, connector._keys) connector._cache[instance_uri] = cache with pytest.raises(ClientResponseError): diff --git a/tests/unit/test_connector.py b/tests/unit/test_connector.py index 603b67d..65ef8a7 100644 --- a/tests/unit/test_connector.py +++ b/tests/unit/test_connector.py @@ -210,7 +210,9 @@ def test_Connector_close_called_multiple_times(credentials: FakeCredentials) -> connector.close() -async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials) -> None: +async def test_Connector_remove_cached_bad_instance( + credentials: FakeCredentials, +) -> None: """When a Connector attempts to retrieve connection info for a non-existent instance, it should delete the instance from the cache and ensure no background refresh happens (which would be @@ -218,7 +220,9 @@ async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials """ instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance" with Connector(credentials) as connector: - connector._client = FakeAlloyDBClient(instance = FakeInstance(name = "bad-test-instance")) + connector._client = FakeAlloyDBClient( + instance=FakeInstance(name="bad-test-instance") + ) cache = RefreshAheadCache(instance_uri, connector._client, connector._keys) connector._cache[instance_uri] = cache with pytest.raises(ClientResponseError): @@ -249,4 +253,4 @@ async def test_Connector_remove_cached_no_ip_type( with pytest.raises(IPTypeNotFoundError): await connector.connect_async(instance_uri, "pg8000", ip_type="private") # check that cache has been removed from dict - assert instance_uri not in connector._cache \ No newline at end of file + assert instance_uri not in connector._cache