Skip to content

Commit ae98391

Browse files
committed
Test sync stream unary and stream stream
1 parent 4a30028 commit ae98391

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

tests/test_sync_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from collections.abc import AsyncIterator
44

55
import grpc
6-
import grpclib
76
import pytest
87
from grpclib.server import Server
98

@@ -24,10 +23,14 @@ async def get_unary_stream(self, message: "Request") -> "AsyncIterator[Response]
2423
yield Response(message=f"Hello {message.value} {i}")
2524

2625
async def get_stream_unary(self, messages: "AsyncIterator[Request]") -> "Response":
27-
raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
26+
s = 0
27+
async for m in messages:
28+
s += m.value
29+
return Response(message=f"Hello {s}")
2830

2931
async def get_stream_stream(self, messages: "AsyncIterator[Request]") -> "AsyncIterator[Response]":
30-
raise grpclib.GRPCError(grpclib.const.Status.UNIMPLEMENTED)
32+
async for message in messages:
33+
yield Response(message=f"Hello {message.value}")
3134

3235

3336
@pytest.mark.asyncio
@@ -57,6 +60,12 @@ async def run_server():
5760
response = client.get_unary_stream(Request(value=42))
5861
assert [r.message for r in response] == [f"Hello 42 {i}" for i in range(5)]
5962

63+
response = client.get_stream_unary([Request(value=i) for i in range(5)])
64+
assert response.message == "Hello 10"
65+
66+
response = client.get_stream_stream([Request(value=i) for i in range(5)])
67+
assert [r.message for r in response] == [f"Hello {i}" for i in range(5)]
68+
6069
# Create an async client
6170
# client = SimpleServiceStub(Channel(host="127.0.0.1", port=1234))
6271
# response = await client.get_unary_unary(Request(value=42))

0 commit comments

Comments
 (0)