1111import pytest
1212from models_library .projects_nodes import InputTypes , OutputTypes
1313from models_library .projects_nodes_io import SimCoreFileLink
14- from pydantic import BaseModel , ValidationError , schema_json_of
14+ from pydantic import BaseModel , Field , ValidationError , schema_json_of
1515from pydantic .types import Json
1616from pydantic .version import version_short
1717
@@ -90,8 +90,8 @@ class ArgumentAnnotation(BaseModel):
9090def test_union_types_coercion ():
9191 # SEE https://pydantic-docs.helpmanual.io/usage/types/#unions
9292 class Func (BaseModel ):
93- input : InputTypes
94- output : OutputTypes
93+ input : InputTypes = Field ( union_mode = "left_to_right" )
94+ output : OutputTypes = Field ( union_mode = "left_to_right" )
9595
9696 assert get_origin (InputTypes ) is Union
9797 assert get_origin (OutputTypes ) is Union
@@ -125,15 +125,15 @@ class Func(BaseModel):
125125 model = Func .model_validate ({"input" : "0" , "output" : 1 })
126126 print (model .model_dump_json (indent = 1 ))
127127
128- assert model .input == "0"
128+ assert model .input == 0
129129 assert model .output == 1
130130
131131 # numbers and bool ------------------------
132132 model = Func .model_validate ({"input" : "0.5" , "output" : "false" })
133133 print (model .model_dump_json (indent = 1 ))
134134
135- assert model .input == " 0.5"
136- assert model .output == "false"
135+ assert model .input == 0.5
136+ assert model .output is False
137137
138138 # (undefined) json string vs string ------------------------
139139 model = Func .model_validate (
@@ -144,7 +144,7 @@ class Func(BaseModel):
144144 )
145145 print (model .model_dump_json (indent = 1 ))
146146
147- assert model .input == ' {"w": 42, "z": false}'
147+ assert model .input == {"w" : 42 , "z" : False }
148148 assert model .output == "some/path/or/string"
149149
150150 # (undefined) json string vs SimCoreFileLink.dict() ------------
@@ -162,7 +162,7 @@ class Func(BaseModel):
162162 }
163163 )
164164 print (model .model_dump_json (indent = 1 ))
165- assert model .input == ' {"w": 42, "z": false}'
165+ assert model .input == {"w" : 42 , "z" : False }
166166 assert model .output == example
167167 assert isinstance (model .output , SimCoreFileLink )
168168
0 commit comments