Skip to content

Commit 142130a

Browse files
Merge pull request #19 from InformaticsMatters/workflow-options
Basic workflow options
2 parents 0886e2d + 132872b commit 142130a

15 files changed

+298
-6
lines changed

tests/test_decoder.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@
5656
)
5757
assert _STEP_SPECIFICATION_VARIABLE_NAMES_WORKFLOW
5858

59+
_WORKFLOW_OPTIONS_WORKFLOW_FILE: str = os.path.join(
60+
os.path.dirname(__file__),
61+
"workflow-definitions",
62+
"workflow-options.yaml",
63+
)
64+
with open(_WORKFLOW_OPTIONS_WORKFLOW_FILE, "r", encoding="utf8") as workflow_file:
65+
_WORKFLOW_OPTIONS: Dict[str, Any] = yaml.safe_load(workflow_file)
66+
assert _WORKFLOW_OPTIONS
67+
5968

6069
def test_validate_schema_for_minimal():
6170
# Arrange
@@ -133,6 +142,16 @@ def test_validate_schema_for_step_specification_variable_names():
133142
assert error is None
134143

135144

145+
def test_validate_schema_for_workflow_options():
146+
# Arrange
147+
148+
# Act
149+
error = decoder.validate_schema(_WORKFLOW_OPTIONS)
150+
151+
# Assert
152+
assert error is None
153+
154+
136155
def test_get_workflow_variables_for_smiple_python_molprops():
137156
# Arrange
138157

tests/test_workflow_validator_for_run_level.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,88 @@ def test_validate_simple_python_molprops():
131131
assert error.error_msg is None
132132

133133

134+
def test_validate_simple_python_molprops_with_options_when_missing_required():
135+
# Arrange
136+
workflow_file: str = os.path.join(
137+
os.path.dirname(__file__),
138+
"workflow-definitions",
139+
"simple-python-molprops-with-options.yaml",
140+
)
141+
with open(workflow_file, "r", encoding="utf8") as workflow_file:
142+
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
143+
assert workflow
144+
variables = {
145+
"candidateMolecules": "input.sdf",
146+
"clusteredMolecules": "output.sdf",
147+
}
148+
149+
# Act
150+
error = WorkflowValidator.validate(
151+
level=ValidationLevel.RUN,
152+
workflow_definition=workflow,
153+
variables=variables,
154+
)
155+
156+
# Assert
157+
assert error.error_num == 7
158+
assert error.error_msg == [
159+
"Missing workflow variable values for: rdkitPropertyValue"
160+
]
161+
162+
163+
def test_validate_simple_python_molprops_with_options():
164+
# Arrange
165+
workflow_file: str = os.path.join(
166+
os.path.dirname(__file__),
167+
"workflow-definitions",
168+
"simple-python-molprops-with-options.yaml",
169+
)
170+
with open(workflow_file, "r", encoding="utf8") as workflow_file:
171+
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
172+
assert workflow
173+
variables = {
174+
"candidateMolecules": "input.sdf",
175+
"clusteredMolecules": "output.sdf",
176+
"rdkitPropertyName": "col1",
177+
"rdkitPropertyValue": 123,
178+
}
179+
180+
# Act
181+
error = WorkflowValidator.validate(
182+
level=ValidationLevel.RUN,
183+
workflow_definition=workflow,
184+
variables=variables,
185+
)
186+
187+
# Assert
188+
assert error.error_num == 0
189+
assert error.error_msg is None
190+
191+
192+
def test_validate_simple_python_molprops_with_missing_input():
193+
# Arrange
194+
workflow_file: str = os.path.join(
195+
os.path.dirname(__file__), "workflow-definitions", "simple-python-molprops.yaml"
196+
)
197+
with open(workflow_file, "r", encoding="utf8") as workflow_file:
198+
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
199+
assert workflow
200+
variables = {"clusteredMolecules": "output.sdf"}
201+
202+
# Act
203+
error = WorkflowValidator.validate(
204+
level=ValidationLevel.RUN,
205+
workflow_definition=workflow,
206+
variables=variables,
207+
)
208+
209+
# Assert
210+
assert error.error_num == 7
211+
assert error.error_msg == [
212+
"Missing workflow variable values for: candidateMolecules"
213+
]
214+
215+
134216
def test_validate_duplicate_workflow_variable_names():
135217
# Arrange
136218
workflow_file: str = os.path.join(

tests/workflow-definitions/duplicate-step-names.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
kind: DataManagerWorkflow
33
kind-version: "2024.1"
44
name: duplicate-step-names
5+
56
steps:
7+
68
- name: step-1
79
specification:
810
collection: a
911
job: b
1012
version: '1.0.0'
13+
1114
- name: step-1
1215
specification:
1316
collection: a

tests/workflow-definitions/duplicate-workflow-variable-names.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ variables:
1515
as: clustered-molecules.smi
1616

1717
steps:
18+
1819
- name: step1
1920
description: Add column 1
2021
specification:

tests/workflow-definitions/example-nop-fail.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ kind-version: "2024.1"
44
name: nop-fail
55
description: >-
66
A workflow with one step that fails
7+
78
steps:
9+
810
- name: step-1
911
specification:
1012
collection: workflow-engine-unit-test-jobs

tests/workflow-definitions/example-smiles-to-file.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ name: smiles-to-file
55
description: >-
66
A workflow with one step that uses variables.
77
The step takes an input string and the Job creates a file from it.
8+
89
steps:
10+
911
- name: step-1
1012
specification:
1113
collection: workflow-engine-unit-test-jobs

tests/workflow-definitions/example-two-step-nop.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ name: two-step-nop
55
description: >-
66
A workflow with two steps.
77
The steps do nothing, take no arguments, and simply return success.
8+
89
steps:
10+
911
- name: step-1
1012
specification:
1113
collection: workflow-engine-unit-test-jobs
1214
job: nop
1315
version: "1.0.0"
16+
1417
- name: step-2
1518
specification:
1619
collection: workflow-engine-unit-test-jobs

tests/workflow-definitions/minimal.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
kind: DataManagerWorkflow
33
kind-version: "2024.1"
44
name: workflow-minimal
5+
56
steps:
7+
68
- name: step-1
79
specification:
810
collection: a

tests/workflow-definitions/shortcut-example-1.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ kind: DataManagerWorkflow
33
kind-version: "2024.1"
44
name: shortcut-example-1
55
description: The shortcut example 1 workflow
6+
67
steps:
8+
79
- name: example-1-step-1
810
description: The first step
911
specification:
@@ -13,6 +15,7 @@ steps:
1315
outputs:
1416
- output: 'outputFile'
1517
as: 'a.sdf'
18+
1619
- name: example-1-step-2
1720
description: The first step
1821
specification:
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
kind: DataManagerWorkflow
3+
kind-version: "2024.1"
4+
name: python-workflow
5+
description: A simple python experimental workflow
6+
variables:
7+
inputs:
8+
- name: candidateMolecules
9+
type: squonk/x-smiles
10+
outputs:
11+
- name: clusteredMolecules
12+
from:
13+
step: step2
14+
output: outputFile
15+
as: clustered-molecules.smi
16+
options:
17+
- name: rdkitPropertyName
18+
default: name
19+
as:
20+
- option: name
21+
step: step1
22+
- name: rdkitPropertyValue
23+
as:
24+
- option: value
25+
step: step1
26+
27+
steps:
28+
29+
- name: step1
30+
description: Add column 1
31+
specification:
32+
collection: workflow-engine-unit-test-jobs
33+
job: rdkit-molprops
34+
version: "1.0.0"
35+
inputs:
36+
- input: inputFile
37+
from:
38+
workflow-input: candidateMolecules
39+
outputs:
40+
- output: outputFile
41+
as: step1.out.smi
42+
43+
- name: step2
44+
description: Add column 2
45+
specification:
46+
collection: workflow-engine-unit-test-jobs
47+
job: cluster-butina
48+
version: "1.0.0"
49+
variables:
50+
name: "col2"
51+
value: "999"
52+
inputs:
53+
- input: inputFile
54+
from:
55+
step: step1
56+
output: outputFile
57+
outputs:
58+
- output: outputFile
59+
as: step2.out.smi

0 commit comments

Comments
 (0)