Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Dec 11, 2023
1 parent cef177f commit 2846e8b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 75 deletions.
10 changes: 5 additions & 5 deletions tests/unit/data/_async/test__mutate_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ async def test_mutate_rows_operation(self):
table = mock.Mock()
entries = [_make_mutation(), _make_mutation()]
operation_timeout = 0.05
instance = self._make_one(
client, table, entries, operation_timeout, operation_timeout
)
with mock.patch.object(instance, "_operation", AsyncMock()) as attempt_mock:
attempt_mock.return_value = None
cls = self._target_class()
with mock.patch(f"{cls.__module__}.{cls.__name__}._run_attempt", AsyncMock()) as attempt_mock:
instance = self._make_one(
client, table, entries, operation_timeout, operation_timeout
)
await instance.start()
assert attempt_mock.call_count == 1

Expand Down
6 changes: 3 additions & 3 deletions tests/unit/data/_async/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ def test_table_ctor_sync(self):
("sample_row_keys", (), "google.api_core.retry.retry_target_async", ()),
(
"mutate_row",
(b"row_key", []),
(b"row_key", [mock.Mock()]),
"google.api_core.retry.retry_target_async",
(),
),
Expand Down Expand Up @@ -1253,10 +1253,10 @@ async def test_customizable_retryable_errors(
("read_rows_sharded", ([ReadRowsQuery()],), "read_rows"),
("row_exists", (b"row_key",), "read_rows"),
("sample_row_keys", (), "sample_row_keys"),
("mutate_row", (b"row_key", []), "mutate_row"),
("mutate_row", (b"row_key", [mock.Mock()]), "mutate_row"),
(
"bulk_mutate_rows",
([mutations.RowMutationEntry(b"key", [mock.Mock()])],),
([mutations.RowMutationEntry(b"key", [mutations.DeleteAllFromRow()])],),
"mutate_rows",
),
("check_and_mutate_row", (b"row_key", None), "check_and_mutate_row"),
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/data/_async/test_mutations_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,10 @@ async def test_customizable_retryable_errors(
from google.cloud.bigtable.data._async.client import TableAsync

with mock.patch(
"google.api_core.retry_async.if_exception_type"
"google.api_core.retry.if_exception_type"
) as predicate_builder_mock:
with mock.patch(
"google.api_core.retry_async.retry_target"
"google.api_core.retry.retry_target_async"
) as retry_fn_mock:
table = None
with mock.patch("asyncio.create_task"):
Expand Down
65 changes: 0 additions & 65 deletions tests/unit/data/test__helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,71 +100,6 @@ def test_attempt_timeout_w_sleeps(self):
expected_value -= sleep_time


class TestConvertRetryDeadline:
"""
Test _convert_retry_deadline wrapper
"""

@pytest.mark.asyncio
@pytest.mark.parametrize("is_async", [True, False])
async def test_no_error(self, is_async):
def test_func():
return 1

async def test_async():
return test_func()

func = test_async if is_async else test_func
wrapped = _helpers._convert_retry_deadline(func, 0.1, is_async)
result = await wrapped() if is_async else wrapped()
assert result == 1

@pytest.mark.asyncio
@pytest.mark.parametrize("timeout", [0.1, 2.0, 30.0])
@pytest.mark.parametrize("is_async", [True, False])
async def test_retry_error(self, timeout, is_async):
from google.api_core.exceptions import RetryError, DeadlineExceeded

def test_func():
raise RetryError("retry error", None)

async def test_async():
return test_func()

func = test_async if is_async else test_func
wrapped = _helpers._convert_retry_deadline(func, timeout, is_async=is_async)
with pytest.raises(DeadlineExceeded) as e:
await wrapped() if is_async else wrapped()
assert e.value.__cause__ is None
assert f"operation_timeout of {timeout}s exceeded" in str(e.value)

@pytest.mark.asyncio
@pytest.mark.parametrize("is_async", [True, False])
async def test_with_retry_errors(self, is_async):
from google.api_core.exceptions import RetryError, DeadlineExceeded

timeout = 10.0

def test_func():
raise RetryError("retry error", None)

async def test_async():
return test_func()

func = test_async if is_async else test_func

associated_errors = [RuntimeError("error1"), ZeroDivisionError("other")]
wrapped = _helpers._convert_retry_deadline(
func, timeout, associated_errors, is_async
)
with pytest.raises(DeadlineExceeded) as e:
await wrapped()
cause = e.value.__cause__
assert isinstance(cause, bigtable_exceptions.RetryExceptionGroup)
assert cause.exceptions == tuple(associated_errors)
assert f"operation_timeout of {timeout}s exceeded" in str(e.value)


class TestValidateTimeouts:
def test_validate_timeouts_error_messages(self):
with pytest.raises(ValueError) as e:
Expand Down

0 comments on commit 2846e8b

Please sign in to comment.