2
2
3
3
TODO: Add tests for dispatch_requests (non-pure version)
4
4
"""
5
- from typing import Any
5
+ from typing import Any , Dict
6
6
from unittest .mock import Mock , patch , sentinel
7
7
import json
8
8
import pytest
34
34
)
35
35
from jsonrpcserver .exceptions import JsonRpcError
36
36
from jsonrpcserver .main import default_jsonrpc_validator
37
- from jsonrpcserver .methods import method
37
+ from jsonrpcserver .methods import Method
38
38
from jsonrpcserver .request import Request
39
39
from jsonrpcserver .response import ErrorResponse , SuccessResponse
40
40
from jsonrpcserver .result import (
47
47
from jsonrpcserver .sentinels import NOCONTEXT , NODATA , NOID
48
48
from jsonrpcserver .utils import identity
49
49
50
- # pylint: disable=missing-function-docstring,missing-class-docstring,too-few-public-methods,unnecessary-lambda-assignment,invalid-name,disallowed-name
51
-
52
50
53
51
def ping () -> Result :
54
52
return Ok ("pong" )
@@ -381,7 +379,10 @@ def test_dispatch_to_response_pure_parse_error() -> None:
381
379
ErrorResponse (
382
380
ERROR_PARSE_ERROR ,
383
381
"Parse error" ,
384
- "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)" ,
382
+ (
383
+ "Expecting property name enclosed in double quotes: "
384
+ "line 1 column 2 (char 1)"
385
+ ),
385
386
None ,
386
387
)
387
388
)
@@ -566,14 +567,19 @@ def test_dispatch_to_response_pure_notification_parse_error() -> None:
566
567
ErrorResponse (
567
568
ERROR_PARSE_ERROR ,
568
569
"Parse error" ,
569
- "Expecting property name enclosed in double quotes: line 1 column 2 (char 1)" ,
570
+ (
571
+ "Expecting property name enclosed in double quotes: "
572
+ "line 1 column 2 (char 1)"
573
+ ),
570
574
None ,
571
575
)
572
576
)
573
577
574
578
575
579
def test_dispatch_to_response_pure_notification_invalid_request () -> None :
576
- """Invalid JSON-RPC, must return an error. (impossible to determine if notification)"""
580
+ """Invalid JSON-RPC, must return an error. (impossible to determine if
581
+ notification)
582
+ """
577
583
assert dispatch_to_response_pure (
578
584
validate_args ,
579
585
json .loads ,
@@ -625,7 +631,7 @@ def foo(colour: str, size: str) -> Result: # pylint: disable=unused-argument
625
631
)
626
632
627
633
628
- def test_dispatch_to_response_pure_invalid_params_notification_explicitly_returned () -> None :
634
+ def test_dispatch_to_response_pure_invalid_params_notification_returned () -> None :
629
635
def foo (colour : str ) -> Result :
630
636
if colour not in ("orange" , "red" , "yellow" ):
631
637
return InvalidParams ()
@@ -912,7 +918,7 @@ def test_examples_mixed_requests_and_notifications() -> None:
912
918
The spec example includes this which invalidates the entire request:
913
919
{"foo": "boo"},
914
920
"""
915
- methods = {
921
+ methods : Dict [ str , Method ] = {
916
922
"sum" : lambda * args : Ok (sum (args )),
917
923
"notify_hello" : lambda * args : Ok (19 ),
918
924
"subtract" : lambda * args : Ok (args [0 ] - sum (args [1 :])),
@@ -929,7 +935,12 @@ def test_examples_mixed_requests_and_notifications() -> None:
929
935
{"jsonrpc": "2.0", "method": "sum", "params": [1,2,4], "id": "1"},
930
936
{"jsonrpc": "2.0", "method": "notify_hello", "params": [7]},
931
937
{"jsonrpc": "2.0", "method": "subtract", "params": [42,23], "id": "2"},
932
- {"jsonrpc": "2.0", "method": "foo.get", "params": {"name": "myself"}, "id": "5"},
938
+ {
939
+ "jsonrpc": "2.0",
940
+ "method": "foo.get",
941
+ "params": {"name": "myself"},
942
+ "id": "5"
943
+ },
933
944
{"jsonrpc": "2.0", "method": "get_data", "id": "9"}
934
945
]""" ,
935
946
)
0 commit comments