Skip to content

Commit

Permalink
Tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
ghandic authored and plq committed Jan 11, 2023
1 parent acb6860 commit 3840c4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
2 changes: 1 addition & 1 deletion spyne/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def _typed_rpc(func):

if missing_type_annotations:
caller = inspect.getframeinfo(inspect.stack()[2][0])
raise TypeError(f"{caller.filename}:{caller.lineno} - Missing type annotation for the parameters: {missing_type_annotations}")
raise ValueError(f"{caller.filename}:{caller.lineno} - Missing type annotation for the parameters: {missing_type_annotations}")

if definition.return_annotation is not inspect._empty:
new_func = rpc(*inputs, _returns=definition.return_annotation, **kwargs)(func)
Expand Down
53 changes: 11 additions & 42 deletions spyne/test/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,13 +514,6 @@ class SomeService(Service):
@typed_rpc
def someCall(ctx, x: someCallResponse) -> Array(String):
return ['abc', 'def']

Application(
[SomeService],
'tns',
in_protocol=Soap11(),
out_protocol=Soap11(cleanup_namespaces=True)
)

def test_typed_rpc_works_with_kwargs(self):
class someCallResponse(ComplexModel):
Expand All @@ -532,12 +525,6 @@ class SomeService(Service):
def someCall(ctx, x: someCallResponse) -> Array(String):
return ['abc', 'def']

Application(
[SomeService],
'tns',
in_protocol=Soap11(),
out_protocol=Soap11(cleanup_namespaces=True)
)

def test_typed_rpc_works_with_no_response_works(self):
class someCallResponse(ComplexModel):
Expand All @@ -548,31 +535,18 @@ class SomeService(Service):
@typed_rpc(_is_async=True)
def someCall(ctx, x: someCallResponse):
return ['abc', 'def']

Application(
[SomeService],
'tns',
in_protocol=Soap11(),
out_protocol=Soap11(cleanup_namespaces=True)
)

def test_typed_rpc_works_with__returns_kwarg_raises(self):
class someCallResponse(ComplexModel):
__namespace__ = 'tns'
s = String

class SomeService(Service):
@typed_rpc(someCallResponse, _returns=Array(String))
def someCall(ctx, x: someCallResponse) -> Array(String):
return ['abc', 'def']

expected_message = "_returns must be omitted when type annotations are used. Please annotate the return type"
try:
Application(
[SomeService],
'tns',
in_protocol=Soap11(),
out_protocol=Soap11(cleanup_namespaces=True)
)
class SomeService(Service):
@typed_rpc(_returns=Array(String))
def someCall(ctx, x: someCallResponse) -> Array(String):
return ['abc', 'def']
except ValueError as e:
assert str(e) == expected_message
else:
Expand All @@ -583,18 +557,13 @@ class someCallResponse(ComplexModel):
__namespace__ = 'tns'
s = String

class SomeService(Service):
@typed_rpc(someCallResponse)
def someCall(ctx, x: someCallResponse, y) -> Array(String):
return ['abc', 'def']
expected_sub_message = "Missing type annotation for the parameters: ['b']"

expected_sub_message = "Missing type annotation for the parameters: ['y']"
try:
Application(
[SomeService],
'tns',
in_protocol=Soap11(),
out_protocol=Soap11(cleanup_namespaces=True)
)
class SomeService(Service):
@typed_rpc(_is_async=True)
def someCall(ctx, x: someCallResponse, y) -> Array(String):
return ['abc', 'def']
except ValueError as e:
assert expected_sub_message in str(e)
else:
Expand Down

0 comments on commit 3840c4e

Please sign in to comment.