Skip to content
22 changes: 21 additions & 1 deletion tests/nexus/test_handler_interface_implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,39 @@ async def op(
error_message = None


class MissingWorkflowRunDecorator(_InterfaceImplementationTestCase):
"""Missing @workflow_run_operation decorator raises appropriate error."""

@nexusrpc.service
class Interface:
my_workflow_op: nexusrpc.Operation[str, int]

class Impl:
# Method exists but MISSING @workflow_run_operation decorator
async def my_workflow_op(
self, _ctx: WorkflowRunOperationContext, _input: str
) -> nexus.WorkflowHandle[int]:
raise NotImplementedError

error_message = "does not implement an operation with method name 'my_workflow_op'"


@pytest.mark.parametrize(
"test_case",
[
ValidImpl,
ValidWorkflowRunImpl,
MissingWorkflowRunDecorator,
],
)
def test_service_decorator_enforces_interface_conformance(
test_case: type[_InterfaceImplementationTestCase],
):
if test_case.error_message:
with pytest.raises(Exception) as ei:
nexusrpc.handler.service_handler(test_case.Interface)(test_case.Impl)
nexusrpc.handler.service_handler(service=test_case.Interface)(
test_case.Impl
)
err = ei.value
assert test_case.error_message in str(err)
else:
Expand Down
3 changes: 0 additions & 3 deletions tests/nexus/test_workflow_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1301,9 +1301,6 @@ async def run(
return await nexus_client.execute_operation(service_cls.op, None) # type: ignore


# TODO(nexus-prerelease): check missing decorator behavior


async def test_service_interface_and_implementation_names(
client: Client, env: WorkflowEnvironment
):
Expand Down