mirror of
https://github.com/long2ice/fastapi-cache.git
synced 2026-03-24 20:47:54 +00:00
Full mypy --strict type checking pass
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Optional, Tuple
|
||||
from typing import Any, Optional, Tuple, Type
|
||||
|
||||
import pytest
|
||||
from pydantic import BaseModel, ValidationError
|
||||
@@ -53,7 +53,7 @@ def test_pickle_coder(value: Any) -> None:
|
||||
(PDItem(name="foo", price=42.0, description="some pydantic item", tax=0.2), PDItem),
|
||||
],
|
||||
)
|
||||
def test_json_coder(value: Any, return_type) -> None:
|
||||
def test_json_coder(value: Any, return_type: Type[Any]) -> None:
|
||||
encoded_value = JsonCoder.encode(value)
|
||||
assert isinstance(encoded_value, bytes)
|
||||
decoded_value = JsonCoder.decode_as_type(encoded_value, type_=return_type)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from typing import Generator
|
||||
from typing import Generator, Any
|
||||
|
||||
import pendulum
|
||||
import pytest
|
||||
@@ -11,7 +11,7 @@ from fastapi_cache.backends.inmemory import InMemoryBackend
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def init_cache() -> Generator:
|
||||
def init_cache() -> Generator[Any, Any, None]:
|
||||
FastAPICache.init(InMemoryBackend())
|
||||
yield
|
||||
FastAPICache.reset()
|
||||
@@ -21,33 +21,33 @@ def test_datetime() -> None:
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/datetime")
|
||||
now = response.json().get("now")
|
||||
now_ = pendulum.now().replace(microsecond=0)
|
||||
assert pendulum.parse(now).replace(microsecond=0) == now_
|
||||
now_ = pendulum.now().replace(microsecond=0) # type: ignore[no-untyped-call]
|
||||
assert pendulum.parse(now).replace(microsecond=0) == now_ # type: ignore[attr-defined]
|
||||
response = client.get("/datetime")
|
||||
now = response.json().get("now")
|
||||
assert pendulum.parse(now).replace(microsecond=0) == now_
|
||||
assert pendulum.parse(now).replace(microsecond=0) == now_ # type: ignore[attr-defined]
|
||||
time.sleep(3)
|
||||
response = client.get("/datetime")
|
||||
now = response.json().get("now")
|
||||
now = pendulum.parse(now).replace(microsecond=0)
|
||||
now = pendulum.parse(now).replace(microsecond=0) # type: ignore[attr-defined]
|
||||
assert now != now_
|
||||
assert now == pendulum.now().replace(microsecond=0)
|
||||
assert now == pendulum.now().replace(microsecond=0) # type: ignore[no-untyped-call]
|
||||
|
||||
|
||||
def test_date() -> None:
|
||||
"""Test path function without request or response arguments."""
|
||||
with TestClient(app) as client:
|
||||
response = client.get("/date")
|
||||
assert pendulum.parse(response.json()) == pendulum.today()
|
||||
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
|
||||
|
||||
# do it again to test cache
|
||||
response = client.get("/date")
|
||||
assert pendulum.parse(response.json()) == pendulum.today()
|
||||
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
|
||||
|
||||
# now test with cache disabled, as that's a separate code path
|
||||
FastAPICache._enable = False
|
||||
response = client.get("/date")
|
||||
assert pendulum.parse(response.json()) == pendulum.today()
|
||||
assert pendulum.parse(response.json()) == pendulum.today() # type: ignore[attr-defined]
|
||||
FastAPICache._enable = True
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user