Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Enable Workflow constructor to receive SpecInfo objects for input_spec parameter #573

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pydra/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ def __init__(
if input_spec:
if isinstance(input_spec, BaseSpec):
self.input_spec = input_spec
elif isinstance(input_spec, SpecInfo):
if not any([x == BaseSpec for x in input_spec.bases]):
raise ValueError(
"Provided SpecInfo must have BaseSpec as it's base."
)
self.input_spec = input_spec
else:
self.input_spec = SpecInfo(
name="Inputs",
Expand Down
31 changes: 31 additions & 0 deletions pydra/engine/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,44 @@
from ..submitter import Submitter
from ..core import Workflow
from ... import mark
from ..specs import SpecInfo, BaseSpec, ShellSpec


def test_wf_no_input_spec():
with pytest.raises(ValueError, match="Empty input_spec"):
Workflow(name="workflow")


def test_wf_specinfo_input_spec():
input_spec = SpecInfo(
name="Input",
fields=[
("a", str, "", {"mandatory": True}),
("b", dict, {"foo": 1, "bar": False}, {"mandatory": False}),
],
bases=(BaseSpec,),
)
wf = Workflow(
name="workflow",
input_spec=input_spec,
)
for x in ["a", "b"]:
assert hasattr(wf.inputs, x)
assert wf.inputs.a == ""
assert wf.inputs.b == {"foo": 1, "bar": False}
bad_input_spec = SpecInfo(
name="Input",
fields=[
("a", str, {"mandatory": True}),
],
bases=(ShellSpec,),
)
with pytest.raises(
ValueError, match="Provided SpecInfo must have BaseSpec as it's base."
):
Workflow(name="workflow", input_spec=bad_input_spec)


def test_wf_name_conflict1():
"""raise error when workflow name conflicts with a class attribute or method"""
with pytest.raises(ValueError) as excinfo1:
Expand Down