try:
from typing import Annotated
except ImportError:
# python <3.9
from typing_extensions import Annotated
from typing import Optional
from typing import Union
import pytest
from ..models._base.custom_types.metadata.base import CustomTypeMetadata
from ..models._base.fields.annotations import get_field_metadata
from ..models._base.fields.annotations import get_field_type
class _CustomMetadata(CustomTypeMetadata):
pass
[docs]
@pytest.mark.parametrize(
"annotation, target_type, expected",
[
(int, int, int),
(int, CustomTypeMetadata, None),
(_CustomMetadata, CustomTypeMetadata, _CustomMetadata),
(Annotated[int, _CustomMetadata], int, int),
(Optional[int], int, int),
(
Optional[_CustomMetadata],
CustomTypeMetadata,
_CustomMetadata,
),
(
Union[int, _CustomMetadata],
CustomTypeMetadata,
_CustomMetadata,
),
],
)
def test_get_field_type(annotation, target_type, expected):
assert get_field_type(annotation, target_type) is expected