Skip to content

Commit

Permalink
fixed lint
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Nov 11, 2024
1 parent 7fb2134 commit e8d122e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
4 changes: 3 additions & 1 deletion google/cloud/bigtable/data/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ async def close(self, timeout: float | None = 2.0):

@CrossSync.convert
async def _ping_and_warm_instances(
self, instance_key: _WarmedInstanceKey | None = None, channel: Channel | None = None
self,
instance_key: _WarmedInstanceKey | None = None,
channel: Channel | None = None,
) -> list[BaseException | None]:
"""
Prepares the backend for requests on a channel
Expand Down
25 changes: 12 additions & 13 deletions tests/unit/data/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,11 @@ async def test_ctor(self):
async def test_ctor_super_inits(self):
from google.cloud.client import ClientWithProject
from google.api_core import client_options as client_options_lib
from google.cloud.bigtable import __version__ as bigtable_version

project = "project-id"
credentials = AnonymousCredentials()
client_options = {"api_endpoint": "foo.bar:1234"}
options_parsed = client_options_lib.from_dict(client_options)
asyncio_portion = "-async" if CrossSync.is_async else ""
with mock.patch.object(
CrossSync.GapicClient, "__init__"
) as bigtable_client_init:
Expand Down Expand Up @@ -214,7 +212,9 @@ async def test__start_background_channel_refresh_task_exists(self):
async def test__start_background_channel_refresh(self):
# should create background tasks for each channel
client = self._make_client(project="project-id")
with mock.patch.object(client, "_ping_and_warm_instances", CrossSync.Mock()) as ping_and_warm:
with mock.patch.object(
client, "_ping_and_warm_instances", CrossSync.Mock()
) as ping_and_warm:
client._emulator_host = None
client._start_background_channel_refresh()
assert client._channel_refresh_task is not None
Expand Down Expand Up @@ -310,7 +310,6 @@ async def test__ping_and_warm_single_instance(self):
CrossSync, "gather_partials", CrossSync.Mock()
) as gather:
gather.side_effect = lambda *args, **kwargs: [fn() for fn in args[0]]
channel = mock.Mock()
# test with large set of instances
client_mock._active_instances = [mock.Mock()] * 100
test_key = ("test-instance", "test-table", "test-app-profile")
Expand Down Expand Up @@ -419,7 +418,6 @@ async def test__manage_channel_sleeps(
# make sure that sleeps work as expected
import time
import random
import threading

channel = mock.Mock()
channel.close = CrossSync.Mock()
Expand Down Expand Up @@ -452,7 +450,6 @@ async def test__manage_channel_sleeps(
@CrossSync.pytest
async def test__manage_channel_random(self):
import random
import threading

with mock.patch.object(CrossSync, "event_wait") as sleep:
with mock.patch.object(random, "uniform") as uniform:
Expand Down Expand Up @@ -488,9 +485,7 @@ async def test__manage_channel_refresh(self, num_cycles):
new_channel = grpc_lib.insecure_channel("localhost:8080")

with mock.patch.object(CrossSync, "event_wait") as sleep:
sleep.side_effect = [None for i in range(num_cycles)] + [
RuntimeError
]
sleep.side_effect = [None for i in range(num_cycles)] + [RuntimeError]
with mock.patch.object(
CrossSync.grpc_helpers, "create_channel"
) as create_channel:
Expand Down Expand Up @@ -918,7 +913,9 @@ async def test_close(self):
task = client._channel_refresh_task
assert task is not None
assert not task.done()
with mock.patch.object(client.transport, "close", CrossSync.Mock()) as close_mock:
with mock.patch.object(
client.transport, "close", CrossSync.Mock()
) as close_mock:
await client.close()
close_mock.assert_called_once()
if CrossSync.is_async:
Expand All @@ -941,10 +938,13 @@ async def test_close_with_timeout(self):
@CrossSync.pytest
async def test_context_manager(self):
from functools import partial

# context manager should close the client cleanly
close_mock = CrossSync.Mock()
true_close = None
async with self._make_client(project="project-id", use_emulator=False) as client:
async with self._make_client(
project="project-id", use_emulator=False
) as client:
# grab reference to close coro for async test
true_close = partial(client.close)
client.close = close_mock
Expand Down Expand Up @@ -1255,8 +1255,6 @@ async def test_customizable_retryable_errors(
@CrossSync.pytest
@CrossSync.convert
async def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_fn):
from google.cloud.bigtable.data import TableAsync

profile = "profile" if include_app_profile else None
client = self._make_client()
# create mock for rpc stub
Expand Down Expand Up @@ -1291,6 +1289,7 @@ async def test_call_metadata(self, include_app_profile, fn_name, fn_args, gapic_
else:
assert "app_profile_id=" not in routing_str


@CrossSync.convert_class(
"TestReadRows",
add_mapping_for_name="TestReadRows",
Expand Down

0 comments on commit e8d122e

Please sign in to comment.