Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4df2120
duplicating file to base
ohmayr Aug 23, 2024
26f52a5
restore original file
ohmayr Aug 23, 2024
204920a
duplicate file to async
ohmayr Aug 23, 2024
2014ef6
restore original file
ohmayr Aug 23, 2024
fdeb437
Merge branch 'dups' into add-support-for-async-rest-streaming
ohmayr Aug 23, 2024
8014f47
duplicate test file for async
ohmayr Aug 23, 2024
e84f03a
restore test file
ohmayr Aug 23, 2024
91f5c13
Merge branch 'dups' into add-support-for-async-rest-streaming
ohmayr Aug 23, 2024
0c2ee5c
feat: add support for asynchronous rest streaming
ohmayr Aug 23, 2024
75ae7d7
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 23, 2024
db7cfb3
fix naming issue
ohmayr Aug 23, 2024
9da0113
Merge branch 'add-support-for-async-rest-streaming' of github.com:goo…
ohmayr Aug 23, 2024
87eeca3
fix import module name
ohmayr Aug 23, 2024
d6abddd
pull auth feature branch
ohmayr Aug 23, 2024
a6a648d
revert setup file
ohmayr Aug 23, 2024
8d30b2d
address PR comments
ohmayr Aug 24, 2024
0b51b09
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] Aug 24, 2024
7d8f1e1
run black
ohmayr Aug 24, 2024
d793069
address PR comments
ohmayr Aug 27, 2024
5f48f72
Merge branch 'add-support-for-async-rest-streaming' of github.com:goo…
ohmayr Aug 27, 2024
70d1cdb
update nox coverage
ohmayr Aug 27, 2024
ee3a5ac
address PR comments
ohmayr Aug 27, 2024
5a6e488
fix nox session name in workflow
ohmayr Aug 27, 2024
f2180da
use https for remote repo
ohmayr Aug 27, 2024
bc811e5
add context manager methods
ohmayr Aug 27, 2024
fc74ae0
address PR comments
ohmayr Sep 11, 2024
1603818
Merge branch 'main' into add-support-for-async-rest-streaming
ohmayr Sep 11, 2024
cee06ab
update auth error versions
ohmayr Sep 18, 2024
380dedf
Merge branch 'main' into add-support-for-async-rest-streaming
ohmayr Sep 18, 2024
750d4cb
update import error
ohmayr Sep 18, 2024
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
Prev Previous commit
Next Next commit
add context manager methods
  • Loading branch information
ohmayr committed Aug 27, 2024
commit bc811e5c88d2f7fc9e086b61f1896b249d3ca869
5 changes: 4 additions & 1 deletion google/api_core/rest_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

try:
import google.auth.aio.transport
except ImportError:
except ImportError: # pragma: NO COVER
# TODO (ohmayr): Update this version once auth work is released.
raise ValueError(
"google-auth>=2.3x.x is required to use asynchronous rest streaming."
Expand Down Expand Up @@ -56,6 +56,9 @@ def __init__(
response_message_cls=response_message_cls
)

async def __aenter__(self):
return self

async def cancel(self):
"""Cancel existing streaming operation."""
await self._response.close()
Expand Down
14 changes: 13 additions & 1 deletion tests/asyncio/test_rest_streaming_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@


async def mock_async_gen(data, chunk_size=1):
for i in range(0, len(data)):
for i in range(0, len(data)): # pragma: NO COVER
chunk = data[i : i + chunk_size]
yield chunk.encode("utf-8")

Expand Down Expand Up @@ -316,6 +316,18 @@ async def test_cancel(response_type):
mock_method.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.parametrize("response_type", [EchoResponse, httpbody_pb2.HttpBody])
async def test_iterator_as_context_manager(response_type):
with mock.patch.object(
ResponseMock, "close", new_callable=mock.AsyncMock
) as mock_method:
resp = ResponseMock(responses=[], response_cls=response_type)
async with rest_streaming_async.AsyncResponseIterator(resp, response_type):
pass
mock_method.assert_called_once()


@pytest.mark.asyncio
@pytest.mark.parametrize(
"response_type,return_value",
Expand Down