Skip to content

Commit 4a51195

Browse files
committed
debugging test_workflow
1 parent b03307d commit 4a51195

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

pydra/engine/core.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,11 @@ def construct(
664664
constructor = input_values.pop("constructor")
665665
# Call the user defined constructor to set the outputs
666666
output_lazy_fields = constructor(**input_values)
667+
if output_lazy_fields is None:
668+
raise ValueError(
669+
f"Constructor function for {definition} returned None, must a lazy field "
670+
"or a tuple of lazy fields"
671+
)
667672
# Check to see whether any mandatory inputs are not set
668673
for node in workflow.nodes:
669674
node._definition._check_rules()

pydra/engine/tests/test_workflow.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import pydra.engine.core
4141
from pydra.engine.core import Workflow
4242
from pydra.engine.helpers import plot_workflow
43-
from pydra.utils import exc_info_matches
4443

4544

4645
def test_wf_no_output(plugin: str, tmp_path: Path):
@@ -50,11 +49,8 @@ def test_wf_no_output(plugin: str, tmp_path: Path):
5049
def Worky(x):
5150
workflow.add(Add2(x=x))
5251

53-
worky = Worky(x=2)
54-
55-
with pytest.raises(ValueError) as excinfo:
56-
worky(worker=plugin, cache_dir=tmp_path)
57-
assert "Worky output cannot be None" in str(excinfo.value)
52+
with pytest.raises(ValueError, match="returned None"):
53+
Workflow.construct(Worky(x=2))
5854

5955

6056
def test_wf_1(plugin: str, tmp_path: Path):
@@ -1312,21 +1308,21 @@ def test_wf_ndstLR_1a(plugin: str, tmp_path: Path):
13121308
def Worky(x, y):
13131309
add2 = workflow.add(Add2().split("x", x=x), name="add2")
13141310
mult = workflow.add(
1315-
Multiply().split(["_add2", "y"], x=add2.out, y=y), name="mult"
1311+
Multiply(x=add2.out).split(["_add2", "y"], y=y), name="mult"
13161312
)
13171313
return mult.out
13181314

13191315
worky = Worky(x=[1, 2], y=[11, 12])
13201316

1321-
outputs = worky(worker=plugin, cache_dir=tmp_path)
1322-
13231317
# checking if the splitter is created properly
13241318
wf = Workflow.construct(worky)
13251319
assert wf["mult"].state.splitter == ["_add2", "mult.y"]
13261320
assert wf["mult"].state.splitter_rpn == ["add2.x", "mult.y", "*"]
13271321

13281322
# expected: [({"add2.x": 1, "mult.y": 11}, 33), ({"add2.x": 1, "mult.y": 12}, 36),
13291323
# ({"add2.x": 2, "mult.y": 11}, 44), ({"add2.x": 2, "mult.y": 12}, 48)]
1324+
1325+
outputs = worky(worker=plugin, cache_dir=tmp_path)
13301326
assert outputs.out == [33, 36, 44, 48]
13311327

13321328

@@ -1339,7 +1335,9 @@ def test_wf_ndstLR_2(plugin: str, tmp_path: Path):
13391335
@workflow.define
13401336
def Worky(x, y, z):
13411337
add2 = workflow.add(Add2().split("x", x=x), name="add2")
1342-
addvar = workflow.add(FunAddVar3(a=add2.out).split(["b", "c"], b=y, c=z))
1338+
addvar = workflow.add(
1339+
FunAddVar3(a=add2.out).split(["b", "c"], b=y, c=z), name="addvar"
1340+
)
13431341
return addvar.out
13441342

13451343
worky = Worky(x=[1, 2, 3], y=[10, 20], z=[100, 200])
@@ -1388,7 +1386,7 @@ def test_wf_ndstLR_2a(plugin: str, tmp_path: Path):
13881386
def Worky(x, y, z):
13891387
add2 = workflow.add(Add2().split("x", x=x), name="add2")
13901388
addvar = workflow.add(
1391-
FunAddVar3(a=add2.out).split(["_add2", ["b", "c"]], b=y, c=z)
1389+
FunAddVar3(a=add2.out).split(["_add2", ["b", "c"]], b=y, c=z), name="addvar"
13921390
)
13931391

13941392
return addvar.out
@@ -2142,9 +2140,8 @@ def Worky(x, y):
21422140
@pytest.mark.flaky(reruns=3)
21432141
def test_wf_nostate_cachedir_relativepath(tmp_path, plugin):
21442142
"""worky with provided cache_dir as relative path"""
2145-
tmp_path.chdir()
2146-
cache_dir = "test_wf_cache_2"
2147-
tmp_path.mkdir(cache_dir)
2143+
cache_dir = tmp_path / "test_wf_cache_2"
2144+
cache_dir.mkdir()
21482145

21492146
@workflow.define
21502147
def Worky(x, y):
@@ -3570,11 +3567,11 @@ def Worky1(a, b):
35703567
def test_wf_resultfile_1(plugin: str, tmp_path: Path):
35713568
"""workflow with a file in the result, file should be copied to the worky dir"""
35723569

3573-
@workflow.define
3570+
@workflow.define(outputs=["wf_out"])
35743571
def Worky(x):
35753572
writefile = workflow.add(FunWriteFile(filename=x))
35763573

3577-
return writefile.out # wf_out
3574+
return writefile.out #
35783575

35793576
worky = Worky(x="file_1.txt")
35803577
outputs = worky(worker=plugin, cache_dir=tmp_path)

0 commit comments

Comments
 (0)