Skip to content

Commit

Permalink
fixed unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Jan 11, 2025
1 parent e2136d1 commit 6cca1e9
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 34 deletions.
6 changes: 2 additions & 4 deletions tests/unit/data/_async/test__mutate_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ def _target_class(self):
def _make_one(self, *args, **kwargs):
if not args:
fake_table = CrossSync.Mock()
fake_table.table_name = "table"
fake_table._request_path = {"table_name": "table"}
fake_table.app_profile_id = None
fake_table._authorized_view_name = None
kwargs["gapic_client"] = kwargs.pop("gapic_client", mock.Mock())
kwargs["table"] = kwargs.pop("table", fake_table)
kwargs["operation_timeout"] = kwargs.pop("operation_timeout", 5)
Expand Down Expand Up @@ -173,9 +172,8 @@ async def test_mutate_rows_attempt_exception(self, exc_type):
"""
client = CrossSync.Mock()
table = mock.Mock()
table.table_name = "table"
table._request_path = {"table_name": "table"}
table.app_profile_id = None
table._authorized_view_name = None
entries = [self._make_mutation(), self._make_mutation()]
operation_timeout = 0.05
expected_exception = exc_type("test")
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/data/_async/test__read_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ def test_ctor(self):
client.read_rows.return_value = None
table = mock.Mock()
table._client = client
table.table_name = "test_table"
table._request_path = {"table_name": "test_table"}
table.app_profile_id = "test_profile"
table._authorized_view_name = "authorized_view"
expected_operation_timeout = 42
expected_request_timeout = 44
time_gen_mock = mock.Mock()
Expand All @@ -79,9 +78,8 @@ def test_ctor(self):
assert instance._remaining_count == row_limit
assert instance.operation_timeout == expected_operation_timeout
assert client.read_rows.call_count == 0
assert instance.request.table_name == table.table_name
assert instance.request.table_name == "test_table"
assert instance.request.app_profile_id == table.app_profile_id
assert instance.request.authorized_view_name == table._authorized_view_name
assert instance.request.rows_limit == row_limit

@pytest.mark.parametrize(
Expand Down Expand Up @@ -269,9 +267,8 @@ async def mock_stream():

query = ReadRowsQuery(limit=start_limit)
table = mock.Mock()
table.table_name = "table_name"
table._request_path = {"table_name": "table_name"}
table.app_profile_id = "app_profile_id"
table._authorized_view_name = None
instance = self._make_one(query, table, 10, 10)
assert instance._remaining_count == start_limit
# read emit_num rows
Expand Down Expand Up @@ -309,9 +306,8 @@ async def mock_stream():

query = ReadRowsQuery(limit=start_limit)
table = mock.Mock()
table.table_name = "table_name"
table._request_path = {"table_name": "table_name"}
table.app_profile_id = "app_profile_id"
table._authorized_view_name = None
instance = self._make_one(query, table, 10, 10)
assert instance._remaining_count == start_limit
with pytest.raises(InvalidChunk) as e:
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/data/_async/test_mutations_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,8 @@ def _make_one(self, table=None, **kwargs):

if table is None:
table = mock.Mock()
table.table_name = "table"
table._request_path = {"table_name": "table"}
table.app_profile_id = None
table._authorized_view_name = None
table.default_mutate_rows_operation_timeout = 10
table.default_mutate_rows_attempt_timeout = 10
table.default_mutate_rows_retryable_errors = (
Expand All @@ -324,9 +323,9 @@ def _make_one(self, table=None, **kwargs):

@staticmethod
def _make_mutation(count=1, size=1):
mutation = mock.Mock()
mutation.size.return_value = size
mutation.mutations = [mock.Mock()] * count
mutation = RowMutationEntry("k", DeleteAllFromRow())
mutation.size = lambda: size
mutation.mutations = [DeleteAllFromRow() for _ in range(count)]
return mutation

@CrossSync.pytest
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/data/_sync_autogen/test__mutate_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ def _target_class(self):
def _make_one(self, *args, **kwargs):
if not args:
fake_table = CrossSync._Sync_Impl.Mock()
fake_table.table_name = "table"
fake_table._request_path = {"table_name": "table"}
fake_table.app_profile_id = None
fake_table._authorized_view_name = None
kwargs["gapic_client"] = kwargs.pop("gapic_client", mock.Mock())
kwargs["table"] = kwargs.pop("table", fake_table)
kwargs["operation_timeout"] = kwargs.pop("operation_timeout", 5)
Expand Down Expand Up @@ -148,9 +147,8 @@ def test_mutate_rows_attempt_exception(self, exc_type):
"""exceptions raised from attempt should be raised in MutationsExceptionGroup"""
client = CrossSync._Sync_Impl.Mock()
table = mock.Mock()
table.table_name = "table"
table._request_path = {"table_name": "table"}
table.app_profile_id = None
table._authorized_view_name = None
entries = [self._make_mutation(), self._make_mutation()]
operation_timeout = 0.05
expected_exception = exc_type("test")
Expand Down
12 changes: 4 additions & 8 deletions tests/unit/data/_sync_autogen/test__read_rows.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ def test_ctor(self):
client.read_rows.return_value = None
table = mock.Mock()
table._client = client
table.table_name = "test_table"
table._request_path = {"table_name": "test_table"}
table.app_profile_id = "test_profile"
table._authorized_view_name = "authorized_view"
expected_operation_timeout = 42
expected_request_timeout = 44
time_gen_mock = mock.Mock()
Expand All @@ -73,9 +72,8 @@ def test_ctor(self):
assert instance._remaining_count == row_limit
assert instance.operation_timeout == expected_operation_timeout
assert client.read_rows.call_count == 0
assert instance.request.table_name == table.table_name
assert instance.request.table_name == "test_table"
assert instance.request.app_profile_id == table.app_profile_id
assert instance.request.authorized_view_name == table._authorized_view_name
assert instance.request.rows_limit == row_limit

@pytest.mark.parametrize(
Expand Down Expand Up @@ -254,9 +252,8 @@ def mock_stream():

query = ReadRowsQuery(limit=start_limit)
table = mock.Mock()
table.table_name = "table_name"
table._request_path = {"table_name": "table_name"}
table.app_profile_id = "app_profile_id"
table._authorized_view_name = None
instance = self._make_one(query, table, 10, 10)
assert instance._remaining_count == start_limit
for val in instance.chunk_stream(awaitable_stream()):
Expand Down Expand Up @@ -290,9 +287,8 @@ def mock_stream():

query = ReadRowsQuery(limit=start_limit)
table = mock.Mock()
table.table_name = "table_name"
table._request_path = {"table_name": "table_name"}
table.app_profile_id = "app_profile_id"
table._authorized_view_name = None
instance = self._make_one(query, table, 10, 10)
assert instance._remaining_count == start_limit
with pytest.raises(InvalidChunk) as e:
Expand Down
9 changes: 4 additions & 5 deletions tests/unit/data/_sync_autogen/test_mutations_batcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,8 @@ def _make_one(self, table=None, **kwargs):

if table is None:
table = mock.Mock()
table.table_name = "table"
table._request_path = {"table_name": "table"}
table.app_profile_id = None
table._authorized_view_name = None
table.default_mutate_rows_operation_timeout = 10
table.default_mutate_rows_attempt_timeout = 10
table.default_mutate_rows_retryable_errors = (
Expand All @@ -273,9 +272,9 @@ def _make_one(self, table=None, **kwargs):

@staticmethod
def _make_mutation(count=1, size=1):
mutation = mock.Mock()
mutation.size.return_value = size
mutation.mutations = [mock.Mock()] * count
mutation = RowMutationEntry("k", DeleteAllFromRow())
mutation.size = lambda: size
mutation.mutations = [DeleteAllFromRow() for _ in range(count)]
return mutation

def test_ctor_defaults(self):
Expand Down

0 comments on commit 6cca1e9

Please sign in to comment.