mirror of
https://github.com/correl/tornado-openapi3.git
synced 2024-11-24 03:00:14 +00:00
Set stricter mypy parameters
This commit is contained in:
parent
5a613a54b0
commit
b91feab778
4 changed files with 26 additions and 15 deletions
3
mypy.ini
Normal file
3
mypy.ini
Normal file
|
@ -0,0 +1,3 @@
|
|||
[mypy]
|
||||
disallow_untyped_defs = True
|
||||
disallow_incomplete_defs = True
|
|
@ -1,10 +1,10 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple
|
||||
import unittest
|
||||
from urllib.parse import urlencode, urlparse
|
||||
|
||||
import attr
|
||||
from hypothesis import given, settings # type: ignore
|
||||
from hypothesis import given, settings
|
||||
import hypothesis.strategies as s # type: ignore
|
||||
from openapi_core import create_spec # type: ignore
|
||||
from openapi_core.exceptions import OpenAPIError # type: ignore
|
||||
|
@ -69,16 +69,18 @@ field_value = s.text(
|
|||
)
|
||||
|
||||
|
||||
def headers(min_size=0):
|
||||
def headers(min_size: int = 0) -> s.SearchStrategy[Dict[str, str]]:
|
||||
return s.dictionaries(field_name, field_value, min_size=min_size)
|
||||
|
||||
|
||||
def query_parameters(min_size=0):
|
||||
def query_parameters(min_size: int = 0) -> s.SearchStrategy[Dict[str, str]]:
|
||||
return s.dictionaries(field_name, field_value, min_size=min_size)
|
||||
|
||||
|
||||
@s.composite
|
||||
def parameters(draw, min_headers=0, min_query_parameters=0) -> Parameters:
|
||||
def parameters(
|
||||
draw: Callable[[Any], Any], min_headers: int = 0, min_query_parameters: int = 0
|
||||
) -> Parameters:
|
||||
return Parameters(
|
||||
headers=draw(headers(min_size=min_headers)),
|
||||
query_parameters=draw(query_parameters(min_size=min_query_parameters)),
|
||||
|
@ -92,7 +94,7 @@ class TestRequestFactory(unittest.TestCase):
|
|||
s.tuples(s.just("http://example.com/foo"), query_parameters()),
|
||||
)
|
||||
)
|
||||
def test_http_request(self, opts) -> None:
|
||||
def test_http_request(self, opts: Tuple[str, Dict[str, str]]) -> None:
|
||||
url, parameters = opts
|
||||
request_url = f"{url}?{urlencode(parameters)}" if url else ""
|
||||
tornado_request = HTTPRequest(method="GET", url=request_url)
|
||||
|
@ -112,7 +114,7 @@ class TestRequestFactory(unittest.TestCase):
|
|||
s.tuples(s.just("http://example.com/foo"), query_parameters()),
|
||||
)
|
||||
)
|
||||
def test_http_server_request(self, opts) -> None:
|
||||
def test_http_server_request(self, opts: Tuple[str, Dict[str, str]]) -> None:
|
||||
url, parameters = opts
|
||||
request_url = f"{url}?{urlencode(parameters)}" if url else ""
|
||||
parsed = urlparse(request_url)
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
from dataclasses import dataclass
|
||||
from typing import Any, Dict, Optional
|
||||
from typing import Any, Callable, Dict, Optional, TypeVar
|
||||
import unittest
|
||||
|
||||
import attr
|
||||
|
||||
from hypothesis import given, settings # type: ignore
|
||||
import hypothesis.strategies as s # type: ignore
|
||||
from hypothesis import given, settings
|
||||
import hypothesis.strategies as s
|
||||
|
||||
from openapi_core import create_spec # type: ignore
|
||||
from openapi_core.validation.response.datatypes import OpenAPIResponse # type: ignore
|
||||
|
@ -18,6 +18,7 @@ from tornado_openapi3 import (
|
|||
TornadoResponseFactory,
|
||||
)
|
||||
|
||||
T = TypeVar("T")
|
||||
settings(deadline=None)
|
||||
|
||||
|
||||
|
@ -39,7 +40,7 @@ class Responses:
|
|||
|
||||
|
||||
@s.composite
|
||||
def responses(draw, min_headers=0) -> Responses:
|
||||
def responses(draw: Callable[[Any], Any], min_headers: int = 0) -> Responses:
|
||||
field_name = s.text(
|
||||
s.characters(
|
||||
min_codepoint=33,
|
||||
|
@ -55,9 +56,11 @@ def responses(draw, min_headers=0) -> Responses:
|
|||
),
|
||||
min_size=1,
|
||||
)
|
||||
code = s.sampled_from([200, 304, 400, 500])
|
||||
headers = s.dictionaries(field_name, field_value, min_size=min_headers)
|
||||
return Responses(
|
||||
code=draw(s.sampled_from([200, 304, 400, 500])),
|
||||
headers=draw(s.dictionaries(field_name, field_value, min_size=min_headers)),
|
||||
code=draw(code),
|
||||
headers=draw(headers),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -3,8 +3,9 @@ from urllib.parse import parse_qsl
|
|||
from typing import Union
|
||||
|
||||
from openapi_core.validation.request.datatypes import ( # type: ignore
|
||||
RequestParameters,
|
||||
OpenAPIRequest,
|
||||
RequestParameters,
|
||||
RequestValidationResult,
|
||||
)
|
||||
from openapi_core.validation.request import validators # type: ignore
|
||||
from tornado.httpclient import HTTPRequest # type: ignore
|
||||
|
@ -50,7 +51,9 @@ class TornadoRequestFactory:
|
|||
|
||||
|
||||
class RequestValidator(validators.RequestValidator):
|
||||
def validate(self, request: Union[HTTPRequest, HTTPServerRequest]):
|
||||
def validate(
|
||||
self, request: Union[HTTPRequest, HTTPServerRequest]
|
||||
) -> RequestValidationResult:
|
||||
return super().validate(TornadoRequestFactory.create(request))
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue