diff --git a/betterproto/tests/inputs/service/service.proto b/betterproto/tests/inputs/service/service.proto index aaf4254..7c931ed 100644 --- a/betterproto/tests/inputs/service/service.proto +++ b/betterproto/tests/inputs/service/service.proto @@ -10,6 +10,6 @@ message DoThingResponse { int32 successfulIterations = 1; } -service ExampleService { +service Test { rpc DoThing (DoThingRequest) returns (DoThingResponse); } diff --git a/betterproto/tests/test_service_stub.py b/betterproto/tests/inputs/service/test_service.py similarity index 95% rename from betterproto/tests/test_service_stub.py rename to betterproto/tests/inputs/service/test_service.py index b614e82..ebd9308 100644 --- a/betterproto/tests/test_service_stub.py +++ b/betterproto/tests/inputs/service/test_service.py @@ -7,7 +7,7 @@ from typing import Dict from betterproto.tests.output_betterproto.service.service import ( DoThingResponse, DoThingRequest, - ExampleServiceStub, + TestStub as ExampleServiceStub, ) @@ -29,12 +29,12 @@ class ExampleService: def __mapping__(self) -> Dict[str, grpclib.const.Handler]: return { - "/service.ExampleService/DoThing": grpclib.const.Handler( + "/service.Test/DoThing": grpclib.const.Handler( self.DoThing, grpclib.const.Cardinality.UNARY_UNARY, DoThingRequest, DoThingResponse, - ) + ), } @@ -99,7 +99,7 @@ async def test_service_call_lower_level_with_overrides(): ) as channel: stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata) response = await stub._unary_unary( - "/service.ExampleService/DoThing", + "/service.Test/DoThing", DoThingRequest(ITERATIONS), DoThingResponse, deadline=kwarg_deadline, @@ -123,7 +123,7 @@ async def test_service_call_lower_level_with_overrides(): ) as channel: stub = ExampleServiceStub(channel, deadline=deadline, metadata=metadata) response = await stub._unary_unary( - "/service.ExampleService/DoThing", + "/service.Test/DoThing", DoThingRequest(ITERATIONS), DoThingResponse, timeout=kwarg_timeout, diff --git a/betterproto/tests/mocks.py b/betterproto/tests/mocks.py index 326b892..f42dff0 100644 --- a/betterproto/tests/mocks.py +++ b/betterproto/tests/mocks.py @@ -5,7 +5,7 @@ from grpclib.client import Channel class MockChannel(Channel): # noinspection PyMissingConstructor - def __init__(self, responses: List) -> None: + def __init__(self, responses: List = []) -> None: self.responses = responses self.requests = [] diff --git a/betterproto/tests/test_inputs.py b/betterproto/tests/test_inputs.py index abac067..1d31348 100644 --- a/betterproto/tests/test_inputs.py +++ b/betterproto/tests/test_inputs.py @@ -9,6 +9,7 @@ import pytest import betterproto from betterproto.tests.inputs import xfail +from betterproto.tests.mocks import MockChannel from betterproto.tests.util import get_directories, get_test_case_json_data, inputs_path # Force pure-python implementation instead of C++, otherwise imports @@ -113,6 +114,12 @@ def test_message_json(repeat, test_data: TestData) -> None: assert json.loads(json_data) == json.loads(message_json) +@pytest.mark.parametrize("test_data", test_cases.services, indirect=True) +def test_service_can_be_instantiated(test_data: TestData) -> None: + plugin_module, _, json_data = test_data + plugin_module.TestStub(MockChannel()) + + @pytest.mark.parametrize("test_data", test_cases.messages_with_json, indirect=True) def test_binary_compatibility(repeat, test_data: TestData) -> None: plugin_module, reference_module, json_data = test_data