Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
provinzkraut committed Sep 3, 2024
1 parent d97de47 commit 77c45f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
13 changes: 3 additions & 10 deletions tests/unit/test_openapi/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,21 +617,14 @@ async def handler(dep: str) -> None:
assert param.param_in is ParamType.PATH


@pytest.mark.parametrize(
"annotation, expected_type",
[
(TypeAliasType("IntAlias", int), OpenAPIType.INTEGER), # pyright: ignore
(TypeAliasType("LiteralAlias", Literal[1]), OpenAPIType.INTEGER), # pyright: ignore
],
)
def test_type_alias_type(annotation: Any, expected_type: Any) -> None:
def test_type_alias_type() -> None:
@get("/")
def handler(query_param: Annotated[annotation, Parameter(description="foo")]) -> None:
def handler(query_param: Annotated[TypeAliasType("IntAlias", int), Parameter(description="foo")]) -> None:
pass

app = Litestar([handler])
param = app.openapi_schema.paths["/"].get.parameters[0] # type: ignore[index, union-attr]
assert param.schema.type is expected_type # type: ignore[union-attr]
assert param.schema.type is OpenAPIType.INTEGER # type: ignore[union-attr]
# ensure other attributes than the plain type are carried over correctly
assert param.description == "foo"

Expand Down
13 changes: 3 additions & 10 deletions tests/unit/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys
from dataclasses import dataclass
from typing import Any, ForwardRef, Generic, List, Literal, Optional, Tuple, TypeVar, Union
from typing import Any, ForwardRef, Generic, List, Optional, Tuple, TypeVar, Union

import annotated_types
import msgspec
Expand Down Expand Up @@ -478,15 +478,8 @@ def handler(foo: Annotated[int, Parameter(default=1)]) -> None:
assert "Deprecated default value specification" in str(record.message)


@pytest.mark.parametrize(
"annotation, expected_type",
[
(TypeAliasType("IntAlias", int), int), # pyright: ignore
(TypeAliasType("LiteralAlias", Literal["1"]), Literal["1"]), # pyright: ignore
],
)
def test_is_type_alias_type(annotation: Any, expected_type: Any) -> None:
field_definition = FieldDefinition.from_annotation(annotation)
def test_is_type_alias_type() -> None:
field_definition = FieldDefinition.from_annotation(TypeAliasType("IntAlias", int))
assert field_definition.is_type_alias_type


Expand Down

0 comments on commit 77c45f2

Please sign in to comment.