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

WorkChains: Raise if predicate if_/while_ does not return boolean #5924

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
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies:
- importlib-resources~=5.0
- numpy~=1.19
- paramiko>=2.7.2,~=2.7
- plumpy~=0.21.3
- plumpy~=0.21.4
- pgsu~=0.2.1
- psutil~=5.6
- psycopg2-binary~=2.8
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ dependencies = [
"importlib-resources~=5.0;python_version<'3.9'",
"numpy~=1.19",
"paramiko~=2.7,>=2.7.2",
"plumpy~=0.21.3",
"plumpy~=0.21.4",
"pgsu~=0.2.1",
"psutil~=5.6",
"psycopg2-binary~=2.8",
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-py-3.10.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pickleshare==0.7.5
Pillow==9.3.0
plotly==5.4.0
pluggy==1.0.0
plumpy==0.21.3
plumpy==0.21.4
prometheus-client==0.12.0
prompt-toolkit==3.0.37
psutil==5.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-py-3.11.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Pillow==9.3.0
platformdirs==2.5.4
plotly==5.11.0
pluggy==1.0.0
plumpy==0.21.3
plumpy==0.21.4
prometheus-client==0.15.0
prompt-toolkit==3.0.37
psutil==5.9.4
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-py-3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pickleshare==0.7.5
Pillow==9.3.0
plotly==5.4.0
pluggy==1.0.0
plumpy==0.21.3
plumpy==0.21.4
prometheus-client==0.12.0
prompt-toolkit==3.0.37
psutil==5.8.0
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements-py-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ pickleshare==0.7.5
Pillow==9.3.0
plotly==5.4.0
pluggy==1.0.0
plumpy==0.21.3
plumpy==0.21.4
prometheus-client==0.12.0
prompt-toolkit==3.0.37
psutil==5.8.0
Expand Down
34 changes: 34 additions & 0 deletions tests/engine/test_work_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,40 @@ def read_context(self):
def test_str(self):
assert isinstance(str(Wf.spec()), str)

def test_invalid_if_predicate(self):
"""Test that workchain raises if the predicate of an ``if_`` condition does not return a boolean."""

class TestWorkChain(WorkChain):

@classmethod
def define(cls, spec):
super().define(spec)
spec.outline(if_(cls.predicate))

def predicate(self):
"""Invalid predicate whose return value is not a boolean."""
return 'true'

with pytest.raises(TypeError, match=r'The conditional predicate `predicate` did not return a boolean'):
launch.run(TestWorkChain)

def test_invalid_while_predicate(self):
"""Test that workchain raises if the predicate of an ``while_`` condition does not return a boolean."""

class TestWorkChain(WorkChain):

@classmethod
def define(cls, spec):
super().define(spec)
spec.outline(while_(cls.predicate))

def predicate(self):
"""Invalid predicate whose return value is not a boolean."""
return 'true'

with pytest.raises(TypeError, match=r'The conditional predicate `predicate` did not return a boolean'):
launch.run(TestWorkChain)

def test_malformed_outline(self):
"""
Test some malformed outlines
Expand Down