Full mypy --strict type checking pass

This commit is contained in:
Martijn Pieters
2023-05-09 17:08:32 +01:00
parent e92604802e
commit 941cd044c7
10 changed files with 693 additions and 40 deletions

View File

@@ -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