@@ -255,6 +255,59 @@ def testfunc(a: ty.Dict[str, int]):
255
255
256
256
257
257
def test_annotated_input_func_5 (use_validator ):
258
+ """ the function with annotated more complex input type (ty.List in ty.Dict)
259
+ the validator should simply check if values of dict are lists
260
+ so no error for 3.5
261
+ """
262
+
263
+ @mark .task
264
+ def testfunc (a : ty .Dict [str , ty .List [int ]]):
265
+ return sum (a ["el1" ])
266
+
267
+ funky = testfunc (a = {"el1" : [1 , 3.5 ]})
268
+ assert getattr (funky .inputs , "a" ) == {"el1" : [1 , 3.5 ]}
269
+
270
+
271
+ def test_annotated_input_func_5a_except (use_validator ):
272
+ """ the function with annotated more complex input type (ty.Dict in ty.Dict)
273
+ list is provided as a dict value (instead a dict), so error is raised
274
+ """
275
+
276
+ @mark .task
277
+ def testfunc (a : ty .Dict [str , ty .Dict [str , float ]]):
278
+ return sum (a ["el1" ])
279
+
280
+ with pytest .raises (TypeError ):
281
+ funky = testfunc (a = {"el1" : [1 , 3.5 ]})
282
+
283
+
284
+ def test_annotated_input_func_6 (use_validator ):
285
+ """ the function with annotated more complex input type (ty.Union in ty.Dict)
286
+ the validator should unpack values from the Union
287
+ """
288
+
289
+ @mark .task
290
+ def testfunc (a : ty .Dict [str , ty .Union [float , int ]]):
291
+ return sum (a ["el1" ])
292
+
293
+ funky = testfunc (a = {"el1" : 1 , "el2" : 3.5 })
294
+ assert getattr (funky .inputs , "a" ) == {"el1" : 1 , "el2" : 3.5 }
295
+
296
+
297
+ def test_annotated_input_func_6a_excep (use_validator ):
298
+ """ the function with annotated more complex input type (ty.Union in ty.Dict)
299
+ the validator should unpack values from the Union and raise an error for 3.5
300
+ """
301
+
302
+ @mark .task
303
+ def testfunc (a : ty .Dict [str , ty .Union [str , int ]]):
304
+ return sum (a ["el1" ])
305
+
306
+ with pytest .raises (TypeError ):
307
+ funky = testfunc (a = {"el1" : 1 , "el2" : 3.5 })
308
+
309
+
310
+ def test_annotated_input_func_7 (use_validator ):
258
311
""" the function with annotated input (float)
259
312
the task has a splitter, so list of float is provided
260
313
it should work, the validator tries to guess if this is a field with a splitter
@@ -268,7 +321,7 @@ def testfunc(a: float):
268
321
assert getattr (funky .inputs , "a" ) == [3.5 , 2.1 ]
269
322
270
323
271
- def test_annotated_input_func_6 (use_validator ):
324
+ def test_annotated_input_func_7a_excep (use_validator ):
272
325
""" the function with annotated input (int) and splitter
273
326
list of float provided - should raise an error (list of int would be fine)
274
327
"""
0 commit comments