Skip to content

Commit 0b4f096

Browse files
committed
test union field
1 parent ac3583c commit 0b4f096

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tests/contrib/test_pydantic.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class PydanticModel(BaseModel):
2424
List[str], Field(), WithJsonSchema({"extra": "data"})
2525
]
2626
str_short_sequence: ShortSequence[List[str]]
27+
union_field: Union[int, str]
2728

2829
def _check_instance(self):
2930
assert isinstance(self.ip_field, IPv4Address)
@@ -33,6 +34,8 @@ def _check_instance(self):
3334
assert isinstance(self.str_short_sequence, list)
3435
assert self.annotated_list_of_str == ["my-string-1", "my-string-2"]
3536
assert self.str_short_sequence == ["my-string-1", "my-string-2"]
37+
assert isinstance(self.union_field, str)
38+
assert self.union_field == "my-string"
3639

3740

3841
class PydanticDatetimeModel(BaseModel):
@@ -155,6 +158,7 @@ def make_homogeneous_list_of_pydantic_objects() -> List[PydanticModel]:
155158
string_field_assigned_field="my-string",
156159
annotated_list_of_str=["my-string-1", "my-string-2"],
157160
str_short_sequence=["my-string-1", "my-string-2"],
161+
union_field="my-string",
158162
),
159163
]
160164

@@ -166,6 +170,7 @@ def make_heterogenous_list_of_pydantic_objects() -> List[PydanticModels]:
166170
string_field_assigned_field="my-string",
167171
annotated_list_of_str=["my-string-1", "my-string-2"],
168172
str_short_sequence=["my-string-1", "my-string-2"],
173+
union_field="my-string",
169174
),
170175
PydanticDatetimeModel(
171176
datetime_field=datetime(2000, 1, 2, 3, 4, 5),

0 commit comments

Comments
 (0)