test(assets): keep test typing 3.10-compatible (#16305)

This commit is contained in:
Simon Pinfold
2026-09-13 21:31:09 -07:00
committed by GitHub
parent 19e1058f4c
commit eecbfb4046
2 changed files with 17 additions and 7 deletions
+11 -5
View File
@@ -7,7 +7,7 @@ import uuid
from collections.abc import Iterator, Mapping
from dataclasses import dataclass
from datetime import datetime, timedelta
from typing import NotRequired, TypeAlias, TypedDict
from typing import TypeAlias, TypedDict
import pytest
import requests
@@ -22,17 +22,23 @@ from app.assets.database.queries.records import create_content, create_record
from app.database.models import Base
class AssetItem(TypedDict):
class _AssetItemOptional(TypedDict, total=False):
preview_id: str
class AssetItem(_AssetItemOptional):
id: str
name: str
preview_id: NotRequired[str]
class AssetListBody(TypedDict):
class _AssetListBodyOptional(TypedDict, total=False):
next_cursor: str
class AssetListBody(_AssetListBodyOptional):
assets: list[AssetItem]
total: int
has_more: bool
next_cursor: NotRequired[str]
class ErrorItem(TypedDict):
+6 -2
View File
@@ -6,7 +6,7 @@ import uuid
from collections.abc import Callable, Collection, Sequence
from dataclasses import dataclass
from pathlib import Path
from typing import Literal, TypedDict, assert_never
from typing import Literal, NoReturn, TypedDict
import pytest
import requests
@@ -86,6 +86,10 @@ ROUTE_SPECS: tuple[RouteSpec, ...] = (
EXPECTED_ROUTE_KEYS = {f"{spec.method} {spec.path}" for spec in ROUTE_SPECS}
def _assert_never(value: NoReturn) -> NoReturn:
raise AssertionError(f"unhandled route kind: {value!r}")
def _normalize_route_path(raw_path: str) -> str:
path = raw_path.replace("{{", "{").replace("}}", "}")
path = NESTED_PARAM_RE.sub(r"{\g<name>}", path)
@@ -233,7 +237,7 @@ def _request_for_spec(spec: RouteSpec, ctx: SmokeContext) -> requests.Response:
case "prune_missing_assets":
return ctx.http.post(f"{ctx.api_base}/api/assets/prune", timeout=120)
case _:
assert_never(spec.kind)
_assert_never(spec.kind)
def test_route_coverage_guard_rejects_extra_route() -> None: