Finish implementation and testing of client

Including stream_unary and stream_stream call methods.

Also
- improve organisation of relevant tests
- fix some generated type annotations
- Add AsyncChannel utility cos it's useful
This commit is contained in:
Nat Noordanus
2020-06-07 17:51:26 +02:00
parent 09f821921f
commit 4b6f55dce5
12 changed files with 503 additions and 339 deletions

View File

@@ -77,9 +77,9 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
{%- endif -%}
{%- else -%}
{# Client streaming: need a request iterator instead #}
, request_iterator: Iterator["{{ method.input }}"]
, request_iterator: Union[AsyncIterable["{{ method.input }}"], Iterable["{{ method.input }}"]]
{%- endif -%}
) -> {% if method.server_streaming %}AsyncGenerator[{{ method.output }}, None]{% else %}{{ method.output }}{% endif %}:
) -> {% if method.server_streaming %}AsyncIterator[{{ method.output }}]{% else %}{{ method.output }}{% endif %}:
{% if method.comment %}
{{ method.comment }}
@@ -97,7 +97,7 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
{% endif %}
{% if method.server_streaming %}
{% if method.client_streaming %}
{% if method.client_streaming %}
async for response in self._stream_stream(
"{{ method.route }}",
request_iterator,
@@ -105,7 +105,7 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
{{ method.output }},
):
yield response
{% else %}{# i.e. not client streaming #}
{% else %}{# i.e. not client streaming #}
async for response in self._unary_stream(
"{{ method.route }}",
request,
@@ -113,22 +113,22 @@ class {{ service.py_name }}Stub(betterproto.ServiceStub):
):
yield response
{% endif %}{# if client streaming #}
{% endif %}{# if client streaming #}
{% else %}{# i.e. not server streaming #}
{% if method.client_streaming %}
{% if method.client_streaming %}
return await self._stream_unary(
"{{ method.route }}",
request_iterator,
{{ method.input }},
{{ method.output }}
)
{% else %}{# i.e. not client streaming #}
{% else %}{# i.e. not client streaming #}
return await self._unary_unary(
"{{ method.route }}",
request,
{{ method.output }}
)
{% endif %}{# client streaming #}
{% endif %}{# client streaming #}
{% endif %}
{% endfor %}