Skip to content

Commit 2109b26

Browse files
Merge pull request #14 from InformaticsMatters/prototype-work-alan
Method tweaks to simplify access to prior workflow step variables
2 parents b1f362b + 9026fec commit 2109b26

11 files changed

+563
-28
lines changed

tests/test_decoder.py

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,21 @@
3030
_SIMPLE_PYTHON_MOLPROPS_WORKFLOW: Dict[str, Any] = yaml.safe_load(workflow_file)
3131
assert _SIMPLE_PYTHON_MOLPROPS_WORKFLOW
3232

33+
_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW_FILE: str = os.path.join(
34+
os.path.dirname(__file__),
35+
"workflow-definitions",
36+
"duplicate-workflow-variable-names.yaml",
37+
)
38+
with open(
39+
_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW_FILE, "r", encoding="utf8"
40+
) as workflow_file:
41+
_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW: Dict[str, Any] = yaml.safe_load(
42+
workflow_file
43+
)
44+
assert _DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW
45+
3346

34-
def test_validate_minimal():
47+
def test_validate_schema_for_minimal():
3548
# Arrange
3649

3750
# Act
@@ -41,7 +54,7 @@ def test_validate_minimal():
4154
assert error is None
4255

4356

44-
def test_validate_minimal_get_step_names():
57+
def test_minimal_get_step_names():
4558
# Arrange
4659

4760
# Act
@@ -51,7 +64,7 @@ def test_validate_minimal_get_step_names():
5164
assert names == ["step-1"]
5265

5366

54-
def test_validate_without_name():
67+
def test_workflow_without_name():
5568
# Arrange
5669
workflow = _MINIMAL_WORKFLOW.copy()
5770
_ = workflow.pop("name", None)
@@ -63,7 +76,7 @@ def test_validate_without_name():
6376
assert error == "'name' is a required property"
6477

6578

66-
def test_validate_name_with_spaces():
79+
def test_workflow_name_with_spaces():
6780
# Arrange
6881
workflow = _MINIMAL_WORKFLOW.copy()
6982
workflow["name"] = "workflow with spaces"
@@ -77,7 +90,7 @@ def test_validate_name_with_spaces():
7790
)
7891

7992

80-
def test_validate_shortcut_example_1():
93+
def test_validate_schema_for_shortcut_example_1():
8194
# Arrange
8295

8396
# Act
@@ -87,7 +100,7 @@ def test_validate_shortcut_example_1():
87100
assert error is None
88101

89102

90-
def test_validate_python_simple_molprops():
103+
def test_validate_schema_for_python_simple_molprops():
91104
# Arrange
92105

93106
# Act
@@ -97,15 +110,16 @@ def test_validate_python_simple_molprops():
97110
assert error is None
98111

99112

100-
def test_get_workflow_variables():
113+
def test_get_workflow_variables_for_smiple_python_molprops():
101114
# Arrange
102115

103116
# Act
104117
wf_variables = decoder.get_variable_names(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
105118

106119
# Assert
107-
assert len(wf_variables) == 1
120+
assert len(wf_variables) == 2
108121
assert "candidateMolecules" in wf_variables
122+
assert "clusteredMolecules" in wf_variables
109123

110124

111125
def test_get_workflow_description():
@@ -138,3 +152,15 @@ def test_get_workflow_steps():
138152
assert len(steps) == 2
139153
assert steps[0]["name"] == "step1"
140154
assert steps[1]["name"] == "step2"
155+
156+
157+
def test_get_workflow_variables_for_duplicate_variables():
158+
# Arrange
159+
160+
# Act
161+
names = decoder.get_variable_names(_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW)
162+
163+
# Assert
164+
assert len(names) == 2
165+
assert names[0] == "x"
166+
assert names[1] == "x"

tests/test_test_api_adapter.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,37 @@ def test_get_running_workflow_step():
267267
assert response["name"] == "step-1"
268268
assert not response["done"]
269269
assert response["running_workflow"]["id"] == rwfid
270+
assert "prior_running_workflow_step" not in response
271+
272+
273+
def test_get_running_workflow_step_with_prior_step():
274+
# Arrange
275+
utaa = UnitTestWorkflowAPIAdapter()
276+
response = utaa.create_workflow(workflow_definition={"name": "blah"})
277+
wfid = response["id"]
278+
response = utaa.create_running_workflow(
279+
user_id="dlister",
280+
workflow_id=wfid,
281+
project_id=TEST_PROJECT_ID,
282+
variables={},
283+
)
284+
rwfid = response["id"]
285+
response, _ = utaa.create_running_workflow_step(
286+
running_workflow_id=rwfid,
287+
step="step-1",
288+
prior_running_workflow_step_id="r-workflow-step-111",
289+
)
290+
rwfsid = response["id"]
291+
292+
# Act
293+
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfsid)
294+
295+
# Assert
296+
assert response["name"] == "step-1"
297+
assert not response["done"]
298+
assert response["running_workflow"]["id"] == rwfid
299+
assert "prior_running_workflow_step" in response
300+
assert response["prior_running_workflow_step"]["id"] == "r-workflow-step-111"
270301

271302

272303
def test_create_instance():
@@ -291,3 +322,69 @@ def test_create_and_get_instance():
291322

292323
# Assert
293324
assert response["running_workflow_step_id"] == "r-workflow-step-000"
325+
326+
327+
def test_get_workflow_steps_driving_this_step_when_1st_step():
328+
# Arrange
329+
utaa = UnitTestWorkflowAPIAdapter()
330+
response = utaa.create_workflow(
331+
workflow_definition={
332+
"name": "blah",
333+
"steps": [{"name": "step-1"}, {"name": "step-2"}, {"name": "step-3"}],
334+
}
335+
)
336+
response = utaa.create_running_workflow(
337+
user_id="dlister",
338+
workflow_id=response["id"],
339+
project_id=TEST_PROJECT_ID,
340+
variables={},
341+
)
342+
response, _ = utaa.create_running_workflow_step(
343+
running_workflow_id=response["id"], step="step-1"
344+
)
345+
rwfs_id = response["id"]
346+
347+
# Act
348+
response, _ = utaa.get_workflow_steps_driving_this_step(
349+
running_workflow_step_id=rwfs_id
350+
)
351+
352+
# Assert
353+
assert response["caller_step_index"] == 0
354+
assert len(response["steps"]) == 3
355+
assert response["steps"][0]["name"] == "step-1"
356+
assert response["steps"][1]["name"] == "step-2"
357+
assert response["steps"][2]["name"] == "step-3"
358+
359+
360+
def test_get_workflow_steps_driving_this_step_when_2nd_step():
361+
# Arrange
362+
utaa = UnitTestWorkflowAPIAdapter()
363+
response = utaa.create_workflow(
364+
workflow_definition={
365+
"name": "blah",
366+
"steps": [{"name": "step-1"}, {"name": "step-2"}, {"name": "step-3"}],
367+
}
368+
)
369+
response = utaa.create_running_workflow(
370+
user_id="dlister",
371+
workflow_id=response["id"],
372+
project_id=TEST_PROJECT_ID,
373+
variables={},
374+
)
375+
response, _ = utaa.create_running_workflow_step(
376+
running_workflow_id=response["id"], step="step-2"
377+
)
378+
rwfs_id = response["id"]
379+
380+
# Act
381+
response, _ = utaa.get_workflow_steps_driving_this_step(
382+
running_workflow_step_id=rwfs_id
383+
)
384+
385+
# Assert
386+
assert response["caller_step_index"] == 1
387+
assert len(response["steps"]) == 3
388+
assert response["steps"][0]["name"] == "step-1"
389+
assert response["steps"][1]["name"] == "step-2"
390+
assert response["steps"][2]["name"] == "step-3"

tests/test_workflow_validator_for_create_level.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_validate_example_smiles_to_file():
6464
assert error.error_msg is None
6565

6666

67-
def test_validate_example_tow_step_nop():
67+
def test_validate_example_two_step_nop():
6868
# Arrange
6969
workflow_file: str = os.path.join(
7070
os.path.dirname(__file__), "workflow-definitions", "example-two-step-nop.yaml"

tests/test_workflow_validator_for_run_level.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ def test_validate_example_nop_file():
2929
assert error.error_msg is None
3030

3131

32+
def test_validate_duplicate_step_names():
33+
# Arrange
34+
workflow_file: str = os.path.join(
35+
os.path.dirname(__file__), "workflow-definitions", "duplicate-step-names.yaml"
36+
)
37+
with open(workflow_file, "r", encoding="utf8") as workflow_file:
38+
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
39+
assert workflow
40+
41+
# Act
42+
error = WorkflowValidator.validate(
43+
level=ValidationLevel.RUN,
44+
workflow_definition=workflow,
45+
)
46+
47+
# Assert
48+
assert error.error_num == 2
49+
assert error.error_msg == ["Duplicate step names found: step-1"]
50+
51+
3252
def test_validate_example_smiles_to_file():
3353
# Arrange
3454
workflow_file: str = os.path.join(
@@ -49,7 +69,7 @@ def test_validate_example_smiles_to_file():
4969
assert error.error_msg is None
5070

5171

52-
def test_validate_example_tow_step_nop():
72+
def test_validate_example_two_step_nop():
5373
# Arrange
5474
workflow_file: str = os.path.join(
5575
os.path.dirname(__file__), "workflow-definitions", "example-two-step-nop.yaml"
@@ -87,3 +107,47 @@ def test_validate_shortcut_example_1():
87107
# Assert
88108
assert error.error_num == 0
89109
assert error.error_msg is None
110+
111+
112+
def test_validate_simple_python_molprops():
113+
# Arrange
114+
workflow_file: str = os.path.join(
115+
os.path.dirname(__file__), "workflow-definitions", "simple-python-molprops.yaml"
116+
)
117+
with open(workflow_file, "r", encoding="utf8") as workflow_file:
118+
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
119+
assert workflow
120+
variables = {"candidateMolecules": "input.sdf", "clusteredMolecules": "output.sdf"}
121+
122+
# Act
123+
error = WorkflowValidator.validate(
124+
level=ValidationLevel.RUN,
125+
workflow_definition=workflow,
126+
variables=variables,
127+
)
128+
129+
# Assert
130+
assert error.error_num == 0
131+
assert error.error_msg is None
132+
133+
134+
def test_validate_duplicate_workflow_variable_names():
135+
# Arrange
136+
workflow_file: str = os.path.join(
137+
os.path.dirname(__file__),
138+
"workflow-definitions",
139+
"duplicate-workflow-variable-names.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+
145+
# Act
146+
error = WorkflowValidator.validate(
147+
level=ValidationLevel.TAG,
148+
workflow_definition=workflow,
149+
)
150+
151+
# Assert
152+
assert error.error_num == 3
153+
assert error.error_msg == ["Duplicate workflow variable names found: x"]

0 commit comments

Comments
 (0)