From 032c5077da185893b3bd830e8a75834afe01a5ea Mon Sep 17 00:00:00 2001 From: dotX12 Date: Sun, 23 Jul 2023 02:01:11 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20A=20test=20`test=5Fmodel=5Foptional?= =?UTF-8?q?=5Funion=5Fv2`=20has=20been=20added=20to=20coverage=20the=20is?= =?UTF-8?q?=5Fsequence=5Ffield=20function,=20which=20is=20involved=20in=20?= =?UTF-8?q?parsing=20data=20from=20FormData.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_compat.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/test_compat.py b/tests/test_compat.py index 47160ee76..b35d108c4 100644 --- a/tests/test_compat.py +++ b/tests/test_compat.py @@ -1,4 +1,4 @@ -from typing import List, Union +from typing import FrozenSet, List, Optional, Set, Union from fastapi import FastAPI, UploadFile from fastapi._compat import ( @@ -6,6 +6,7 @@ from fastapi._compat import ( Undefined, _get_model_config, is_bytes_sequence_annotation, + is_sequence_field, is_uploadfile_sequence_annotation, ) from fastapi.testclient import TestClient @@ -91,3 +92,24 @@ def test_is_uploadfile_sequence_annotation(): # and other types, but I'm not even sure it's a good idea to support it as a first # class "feature" assert is_uploadfile_sequence_annotation(Union[List[str], List[UploadFile]]) + + +@needs_pydanticv2 +def test_model_optional_union_v2(): + # For coverage + types = [ + Optional[List[str]], + Union[List[int], List[float]], + Optional[Set[int]], + Union[Set[int], Set[float]], + Optional[FrozenSet[int]], + Union[List[int], None], + ] + for annotation in types: + field_info = FieldInfo(annotation=annotation) + field = ModelField(name="foo", field_info=field_info) + assert is_sequence_field(field) is True + + field_info_str = FieldInfo(annotation=str) + field_str = ModelField(name="foo", field_info=field_info_str) + assert is_sequence_field(field_str) is False