Put test into test_features, simplify to call parse directly
				
					
				
			This commit is contained in:
		| @@ -1,11 +1,5 @@ | |||||||
| syntax = "proto3"; | syntax = "proto3"; | ||||||
|  |  | ||||||
| package repeated; |  | ||||||
|  |  | ||||||
| message Test { | message Test { | ||||||
|     repeated string names = 1; |     repeated string names = 1; | ||||||
| } | } | ||||||
|  |  | ||||||
| service ExampleService { |  | ||||||
|   rpc DoThing (Test) returns (Test); |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,34 +0,0 @@ | |||||||
| from typing import Dict |  | ||||||
|  |  | ||||||
| import grpclib.const |  | ||||||
| import grpclib.server |  | ||||||
| import pytest |  | ||||||
| from grpclib.testing import ChannelFor |  | ||||||
|  |  | ||||||
| import betterproto |  | ||||||
| from betterproto.tests.output_betterproto.repeated.repeated import ( |  | ||||||
|     ExampleServiceStub, |  | ||||||
|     Test, |  | ||||||
| ) |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class ExampleService: |  | ||||||
|     async def DoThing(self, stream: "grpclib.server.Stream[Test, Test]"): |  | ||||||
|         request = await stream.recv_message() |  | ||||||
|         await stream.send_message(request) |  | ||||||
|  |  | ||||||
|     def __mapping__(self) -> Dict[str, grpclib.const.Handler]: |  | ||||||
|         return { |  | ||||||
|             "/repeated.ExampleService/DoThing": grpclib.const.Handler( |  | ||||||
|                 self.DoThing, grpclib.const.Cardinality.UNARY_UNARY, Test, Test, |  | ||||||
|             ), |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| @pytest.mark.asyncio |  | ||||||
| async def test_sets_serialized_on_wire() -> None: |  | ||||||
|     async with ChannelFor([ExampleService()]) as channel: |  | ||||||
|         stub = ExampleServiceStub(channel) |  | ||||||
|         response = await stub.do_thing(names=["a", "b", "c"]) |  | ||||||
|         assert betterproto.serialized_on_wire(response) |  | ||||||
|         assert response.names == ["a", "b", "c"] |  | ||||||
| @@ -1,6 +1,6 @@ | |||||||
| import betterproto | import betterproto | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
| from typing import Optional | from typing import Optional, List, Dict | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_has_field(): | def test_has_field(): | ||||||
| @@ -32,6 +32,21 @@ def test_has_field(): | |||||||
|     foo.bar = Bar() |     foo.bar = Bar() | ||||||
|     assert betterproto.serialized_on_wire(foo.bar) == False |     assert betterproto.serialized_on_wire(foo.bar) == False | ||||||
|  |  | ||||||
|  |     @dataclass | ||||||
|  |     class WithCollections(betterproto.Message): | ||||||
|  |         test_list: List[str] = betterproto.string_field(1) | ||||||
|  |         test_map: Dict[str, str] = betterproto.map_field(2, betterproto.TYPE_STRING, betterproto.TYPE_STRING) | ||||||
|  |  | ||||||
|  |     # Unset with empty collections | ||||||
|  |     with_collections_empty = WithCollections().parse(bytes(WithCollections())) | ||||||
|  |     assert betterproto.serialized_on_wire(with_collections_empty) == False | ||||||
|  |  | ||||||
|  |     # Set with non-empty collections | ||||||
|  |     with_collections_list = WithCollections().parse(bytes(WithCollections(test_list=['a', 'b', 'c']))) | ||||||
|  |     assert betterproto.serialized_on_wire(with_collections_list) == True | ||||||
|  |     with_collections_map = WithCollections().parse(bytes(WithCollections(test_map={'a': 'b', 'c': 'd'}))) | ||||||
|  |     assert betterproto.serialized_on_wire(with_collections_map) == True | ||||||
|  |  | ||||||
|  |  | ||||||
| def test_class_init(): | def test_class_init(): | ||||||
|     @dataclass |     @dataclass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user