Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
21e66a3
add AsyncAbstractObjectStream
chandra-siri Sep 17, 2025
39503f4
keep _AsyncAbstractObjectStream private
chandra-siri Sep 17, 2025
a161fd0
Add _AsyncReadObjectStream and it's stubs
chandra-siri Sep 17, 2025
dd862a2
complete __init__ for read_obj_str
chandra-siri Sep 17, 2025
aaabfd7
remove unuseful comments
chandra-siri Sep 17, 2025
3c0fd66
Merge branch 'main' of github.com:googleapis/python-storage into bidi…
chandra-siri Sep 18, 2025
0810afc
fix doc strings, add licence and type hints
chandra-siri Sep 18, 2025
d43d889
Merge branch 'bidi_reads_1_abs_obj_stream' of github.com:googleapis/p…
chandra-siri Sep 18, 2025
a14bc68
pass abstract methods
chandra-siri Sep 18, 2025
fbacbb4
Merge branch 'bidi_reads_1_abs_obj_stream' of github.com:googleapis/p…
chandra-siri Sep 18, 2025
fd37489
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 18, 2025
635ad07
add handle param
chandra-siri Sep 18, 2025
ba453d4
include handle in tests
chandra-siri Sep 18, 2025
800c6df
remove unit tests for abstract class
chandra-siri Sep 18, 2025
8b40812
Merge branch 'bidi_reads_1_abs_obj_stream' of github.com:googleapis/p…
chandra-siri Sep 18, 2025
18529ad
edit doc string for _AsyncReadObjectStream
chandra-siri Sep 18, 2025
df2532e
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 18, 2025
b4da1ac
refactor unit tests for async_read_object_stream
chandra-siri Sep 18, 2025
6dec6c6
bucket_name and object_name cannot be NONE
chandra-siri Sep 18, 2025
90a65f6
Merge branch 'bidi_reads_1_abs_obj_stream' of github.com:googleapis/p…
chandra-siri Sep 18, 2025
a154905
bucket_name and object_name cannot be None
chandra-siri Sep 18, 2025
d69cd63
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 18, 2025
2054989
minor edit - add bidi-stream in doc string
chandra-siri Sep 19, 2025
2b9ae2e
Merge branch 'bidi_reads_1_abs_obj_stream' of github.com:googleapis/p…
chandra-siri Sep 19, 2025
c06896c
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 19, 2025
0991383
Merge branch 'main' of github.com:googleapis/python-storage into bidi…
chandra-siri Sep 19, 2025
f589b89
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 19, 2025
0e60694
add checks for invalid inputs
chandra-siri Sep 19, 2025
961def8
Merge branch 'bidi_reads_2_read_obj_stream' of github.com:googleapis/…
chandra-siri Sep 19, 2025
e9d0f9e
Merge branch 'main' of github.com:googleapis/python-storage into bidi…
chandra-siri Sep 22, 2025
dcb6a55
remove duplicated import
chandra-siri Sep 23, 2025
90d8597
remove unused import
chandra-siri Sep 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from google.cloud.storage._experimental.asyncio.async_abstract_object_stream import (
_AsyncAbstractObjectStream,
)
from google.cloud.storage._experimental.asyncio.bidi_async import AsyncBidiRpc


class _AsyncReadObjectStream(_AsyncAbstractObjectStream):
Expand All @@ -36,7 +37,7 @@ class _AsyncReadObjectStream(_AsyncAbstractObjectStream):
This class provides a unix socket-like interface to a GCS ``Object``, with
methods like ``open``, ``close``, ``send``, and ``recv``.

:type client: :class:`~google.cloud.storage.asyncio.AsyncGrpcClient.grpc_client`
:type client: :class:`~google.cloud.storage._experimental.asyncio.async_grpc_client.AsyncGrpcClient.grpc_client`
:param client: async grpc client to use for making API requests.

:type bucket_name: str
Expand Down Expand Up @@ -77,6 +78,21 @@ def __init__(
self.client: AsyncGrpcClient.grpc_client = client
self.read_handle: Optional[bytes] = read_handle

self._full_bucket_name = f"projects/_/buckets/{self.bucket_name}"

self.rpc = self.client._client._transport._wrapped_methods[
self.client._client._transport.bidi_read_object
]
first_bidi_read_req = _storage_v2.BidiReadObjectRequest(
read_object_spec=_storage_v2.BidiReadObjectSpec(
bucket=self._full_bucket_name, object=object_name
),
)
self.metadata = (("x-goog-request-params", f"bucket={self._full_bucket_name}"),)
self.socket_like_rpc = AsyncBidiRpc(
self.rpc, initial_request=first_bidi_read_req, metadata=self.metadata
)

async def open(self) -> None:
pass

Expand Down
78 changes: 28 additions & 50 deletions tests/unit/asyncio/test_async_read_object_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,73 +14,51 @@

import pytest
from unittest import mock
from google.cloud import _storage_v2

from google.cloud.storage._experimental.asyncio.async_abstract_object_stream import (
_AsyncAbstractObjectStream,
)
from google.cloud.storage._experimental.asyncio.async_read_object_stream import (
_AsyncReadObjectStream,
)


def test_inheritance():
"""Test that _AsyncReadObjectStream inherits from _AsyncAbstractObjectStream."""
assert issubclass(_AsyncReadObjectStream, _AsyncAbstractObjectStream)


def test_init():
"""Test the constructor of _AsyncReadObjectStream."""
mock_client = mock.Mock(name="client")
@mock.patch(
"google.cloud.storage._experimental.asyncio.async_read_object_stream.AsyncBidiRpc"
)
@mock.patch(
"google.cloud.storage._experimental.asyncio.async_grpc_client.AsyncGrpcClient.grpc_client"
)
def test_init_with_bucket_object_generation(mock_client, mock_async_bidi_rpc):
# initialize with bucket, object_name and generation number. & client.
bucket_name = "test-bucket"
object_name = "test-object"
generation = 12345
read_handle = "some-handle"
generation_number = 12345
mock_client._client._transport.bidi_read_object = "bidi_read_object_rpc"
mock_client._client._transport._wrapped_methods = {
"bidi_read_object_rpc": mock.sentinel.A
}

# Test with all parameters
stream = _AsyncReadObjectStream(
mock_client,
read_obj_stream = _AsyncReadObjectStream(
client=mock_client,
bucket_name=bucket_name,
object_name=object_name,
generation_number=generation,
read_handle=read_handle,
generation_number=generation_number,
)

assert stream.client is mock_client
assert stream.bucket_name == bucket_name
assert stream.object_name == object_name
assert stream.generation_number == generation
assert stream.read_handle == read_handle

# Test with default parameters
stream_defaults = _AsyncReadObjectStream(
mock_client, bucket_name=bucket_name, object_name=object_name
full_bucket_name = f"projects/_/buckets/{bucket_name}"
first_bidi_read_req = _storage_v2.BidiReadObjectRequest(
read_object_spec=_storage_v2.BidiReadObjectSpec(
bucket=full_bucket_name, object=object_name
),
)
mock_async_bidi_rpc.assert_called_once_with(
mock.sentinel.A,
initial_request=first_bidi_read_req,
metadata=(("x-goog-request-params", f"bucket={full_bucket_name}"),),
)
assert stream_defaults.client is mock_client
assert stream_defaults.bucket_name is bucket_name
assert stream_defaults.object_name is object_name
assert stream_defaults.generation_number is None
assert stream_defaults.read_handle is None
assert read_obj_stream.socket_like_rpc is mock_async_bidi_rpc.return_value


def test_init_with_invalid_parameters():
"""Test the constructor of _AsyncReadObjectStream with invalid params."""

with pytest.raises(ValueError):
_AsyncReadObjectStream(None, bucket_name=None, object_name=None)


@pytest.mark.asyncio
async def test_async_methods_are_awaitable():
"""Test that the async methods exist and are awaitable."""
mock_client = mock.Mock(name="client")
stream = _AsyncReadObjectStream(mock_client, "bucket", "object")

# These methods are currently empty, but we can test they are awaitable
# and don't raise exceptions.
try:
await stream.open()
await stream.close()
await stream.send(mock.Mock())
await stream.recv()
except Exception as e:
pytest.fail(f"Async methods should be awaitable without errors. Raised: {e}")