Skip to content

Commit 892afc8

Browse files
committed
adding tests for more complex/nested input types
1 parent a3f9290 commit 892afc8

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

pydra/engine/helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ def _single_type_update(tp, name, simplify=False):
400400
else:
401401
return (tp,)
402402
elif simplify is True:
403+
warnings.warn(f"simplify validator for {name} field, checking only one depth")
403404
cont_tp, types_list = _check_special_type(tp, name=name)
404405
if cont_tp is list:
405406
return (list,)

pydra/engine/tests/test_task.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,59 @@ def testfunc(a: ty.Dict[str, int]):
255255

256256

257257
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):
258311
""" the function with annotated input (float)
259312
the task has a splitter, so list of float is provided
260313
it should work, the validator tries to guess if this is a field with a splitter
@@ -268,7 +321,7 @@ def testfunc(a: float):
268321
assert getattr(funky.inputs, "a") == [3.5, 2.1]
269322

270323

271-
def test_annotated_input_func_6(use_validator):
324+
def test_annotated_input_func_7a_excep(use_validator):
272325
""" the function with annotated input (int) and splitter
273326
list of float provided - should raise an error (list of int would be fine)
274327
"""

0 commit comments

Comments
 (0)