Skip to content

Commit 043c800

Browse files
TechNiickScirlat DanutKludex
authored
Added type annotations to test_convertors.py (#2476)
* added type annotations to test_convertors.py * Apply suggestions from code review --------- Co-authored-by: Scirlat Danut <[email protected]> Co-authored-by: Marcelo Trylesinski <[email protected]>
1 parent 551bf86 commit 043c800

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

tests/test_convertors.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
from datetime import datetime
2+
from typing import Callable, Iterator
23

34
import pytest
45

56
from starlette import convertors
67
from starlette.convertors import Convertor, register_url_convertor
8+
from starlette.requests import Request
79
from starlette.responses import JSONResponse
810
from starlette.routing import Route, Router
11+
from starlette.testclient import TestClient
12+
13+
TestClientFactory = Callable[..., TestClient]
914

1015

1116
@pytest.fixture(scope="module", autouse=True)
12-
def refresh_convertor_types():
17+
def refresh_convertor_types() -> Iterator[None]:
1318
convert_types = convertors.CONVERTOR_TYPES.copy()
1419
yield
1520
convertors.CONVERTOR_TYPES = convert_types
@@ -29,7 +34,7 @@ def to_string(self, value: datetime) -> str:
2934
def app() -> Router:
3035
register_url_convertor("datetime", DateTimeConvertor())
3136

32-
def datetime_convertor(request):
37+
def datetime_convertor(request: Request) -> JSONResponse:
3338
param = request.path_params["param"]
3439
assert isinstance(param, datetime)
3540
return JSONResponse({"datetime": param.strftime("%Y-%m-%dT%H:%M:%S")})
@@ -45,7 +50,9 @@ def datetime_convertor(request):
4550
)
4651

4752

48-
def test_datetime_convertor(test_client_factory, app: Router):
53+
def test_datetime_convertor(
54+
test_client_factory: TestClientFactory, app: Router
55+
) -> None:
4956
client = test_client_factory(app)
5057
response = client.get("/datetime/2020-01-01T00:00:00")
5158
assert response.json() == {"datetime": "2020-01-01T00:00:00"}
@@ -57,8 +64,10 @@ def test_datetime_convertor(test_client_factory, app: Router):
5764

5865

5966
@pytest.mark.parametrize("param, status_code", [("1.0", 200), ("1-0", 404)])
60-
def test_default_float_convertor(test_client_factory, param: str, status_code: int):
61-
def float_convertor(request):
67+
def test_default_float_convertor(
68+
test_client_factory: TestClientFactory, param: str, status_code: int
69+
) -> None:
70+
def float_convertor(request: Request) -> JSONResponse:
6271
param = request.path_params["param"]
6372
assert isinstance(param, float)
6473
return JSONResponse({"float": param})

0 commit comments

Comments
 (0)