Skip to content

Commit 434fec9

Browse files
author
Alan Christie
committed
test: Initial test material for shortcut example 1
1 parent 8e03ebd commit 434fec9

File tree

5 files changed

+173
-8
lines changed

5 files changed

+173
-8
lines changed

tests/job-definitions/job-definitions.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,52 @@ jobs:
5858
smiles:
5959
title: SMILES
6060
type: string
61+
62+
shortcut-example-1-process-a:
63+
command: >-
64+
shortcut-example-1-process-a.py --outputFile {{ outputFile }}
65+
variables:
66+
outputs:
67+
type: object
68+
properties:
69+
title: Output file
70+
mime-types:
71+
- chemical/x-mdl-sdfile
72+
- squonk/x-smiles
73+
creates: '{{ outputFile }}'
74+
type: file
75+
options:
76+
type: object
77+
required:
78+
- outputFile
79+
properties:
80+
outputFile:
81+
title: Output file
82+
type: string
83+
default: clustered.sdf
84+
pattern: "^[A-Za-z0-9_/\\.\\-]+\\.(smi|sdf)$"
85+
86+
shortcut-example-1-process-b:
87+
command: >-
88+
shortcut-example-1-process-b.py --inputFile {{ inputFile }}--outputFile {{ outputFile }}
89+
variables:
90+
outputs:
91+
type: object
92+
properties:
93+
title: Output file
94+
mime-types:
95+
- chemical/x-mdl-sdfile
96+
- squonk/x-smiles
97+
creates: '{{ outputFile }}'
98+
type: file
99+
options:
100+
type: object
101+
required:
102+
- outputFile
103+
- inputFile
104+
properties:
105+
outputFile:
106+
title: Output file
107+
type: string
108+
default: clustered.sdf
109+
pattern: "^[A-Za-z0-9_/\\.\\-]+\\.(smi|sdf)$"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
3+
_SDF_CONTENT: str = """
4+
O=C(CSCc1ccc(Cl)s1)N1CCC(O)CC1
5+
RDKit 3D
6+
7+
18 19 0 0 0 0 0 0 0 0999 V2000
8+
8.7102 -1.3539 24.2760 O 0 0 0 0 0 0 0 0 0 0 0 0
9+
9.4334 -2.1203 23.6716 C 0 0 0 0 0 0 0 0 0 0 0 0
10+
10.3260 -1.7920 22.4941 C 0 0 0 0 0 0 0 0 0 0 0 0
11+
9.5607 -0.5667 21.3699 S 0 0 0 0 0 0 0 0 0 0 0 0
12+
7.9641 -1.3976 21.0216 C 0 0 0 0 0 0 0 0 0 0 0 0
13+
7.1007 -0.5241 20.1671 C 0 0 0 0 0 0 0 0 0 0 0 0
14+
5.7930 -0.1276 20.3932 C 0 0 0 0 0 0 0 0 0 0 0 0
15+
5.2841 0.6934 19.3422 C 0 0 0 0 0 0 0 0 0 0 0 0
16+
6.2234 0.8796 18.3624 C 0 0 0 0 0 0 0 0 0 0 0 0
17+
6.0491 1.8209 16.9402 Cl 0 0 0 0 0 0 0 0 0 0 0 0
18+
7.6812 0.0795 18.6678 S 0 0 0 0 0 0 0 0 0 0 0 0
19+
9.5928 -3.4405 24.2306 N 0 0 0 0 0 0 0 0 0 0 0 0
20+
10.8197 -3.4856 25.0609 C 0 0 0 0 0 0 0 0 0 0 0 0
21+
11.0016 -4.9279 25.4571 C 0 0 0 0 0 0 0 0 0 0 0 0
22+
9.9315 -5.2800 26.4615 C 0 0 0 0 0 0 0 0 0 0 0 0
23+
10.3887 -4.7677 27.7090 O 0 0 0 0 0 0 0 0 0 0 0 0
24+
8.5793 -4.6419 26.1747 C 0 0 0 0 0 0 0 0 0 0 0 0
25+
8.3826 -4.0949 24.7695 C 0 0 0 0 0 0 0 0 0 0 0 0
26+
1 2 2 0
27+
2 3 1 0
28+
2 12 1 0
29+
3 4 1 0
30+
4 5 1 0
31+
5 6 1 0
32+
6 7 2 0
33+
7 8 1 0
34+
8 9 2 0
35+
9 10 1 0
36+
9 11 1 0
37+
11 6 1 0
38+
12 13 1 0
39+
13 14 1 0
40+
14 15 1 0
41+
15 16 1 0
42+
15 17 1 0
43+
17 18 1 0
44+
18 12 1 0
45+
M END
46+
47+
$$$$
48+
"""
49+
50+
parser = argparse.ArgumentParser(
51+
prog="shortcut-example-1-process-a",
52+
description="The Job for the first step in our Shortcut example 1",
53+
)
54+
parser.add_argument("-o", "--outputFile", required=True)
55+
args = parser.parse_args()
56+
57+
with open(args.outputFile, "wt", encoding="utf8") as output_file:
58+
output_file.write(_SDF_CONTENT)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import argparse
2+
3+
parser = argparse.ArgumentParser(
4+
prog="shortcut-example-1-process-a",
5+
description="The Job for the first step in our Shortcut example 1",
6+
)
7+
parser.add_argument("-i", "--inputFile", required=True)
8+
parser.add_argument("-o", "--outputFile", required=True)
9+
args = parser.parse_args()
10+
11+
print(args)
12+
13+
with open(args.inputFile, "rt", encoding="utf8") as input_file:
14+
content = input_file.read()
15+
with open(args.outputFile, "wt", encoding="utf8") as output_file:
16+
output_file.write(content)

tests/test_workflow_engine_examples.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import time
33
from datetime import datetime, timezone
4+
from typing import Any
45

56
import pytest
67
import yaml
@@ -40,7 +41,9 @@ def basic_engine():
4041
print("Stopped")
4142

4243

43-
def start_workflow(md, da, workflow_file_name, variables) -> str:
44+
def start_workflow(
45+
md, da, workflow_file_name: str, variables: dict[str, Any] | None = None
46+
) -> str:
4447
"""A convenience function to handle all the 'START' logic for a workflow.
4548
It is given the message dispatcher, data adapter, and the base-name of the
4649
workflow definition - i.e. the filename without the '.yaml' extension
@@ -177,9 +180,37 @@ def test_workflow_engine_example_smiles_to_file(basic_engine):
177180
# Additional, detailed checks...
178181
# Check we only have one RunningWorkflowStep, and it succeeded
179182
response = da.get_running_workflow_steps(running_workflow_id=r_wfid)
180-
print(f"^^^^^^ response={response}")
181183
assert response["count"] == 1
182184
assert response["running_workflow_steps"][0]["done"]
183185
assert response["running_workflow_steps"][0]["success"]
184186
# This test should generate a file in the simulated project directory
185187
assert project_file_exists(output_file)
188+
189+
190+
@pytest.mark.skip(reason="The engine does not currently create the required variables")
191+
def test_workflow_engine_shortcut_example_1(basic_engine):
192+
# Arrange
193+
da, md = basic_engine
194+
# Make sure files that should be generated by the test
195+
# do not exist before we run the test.
196+
output_file_a = "a.sdf"
197+
assert not project_file_exists(output_file_a)
198+
output_file_b = "b.sdf"
199+
assert not project_file_exists(output_file_b)
200+
201+
# Act
202+
r_wfid = start_workflow(md, da, "shortcut-example-1", {})
203+
204+
# Assert
205+
wait_for_workflow(da, r_wfid)
206+
# Additional, detailed checks...
207+
# Check we only have one RunningWorkflowStep, and it succeeded
208+
response = da.get_running_workflow_steps(running_workflow_id=r_wfid)
209+
assert response["count"] == 2
210+
assert response["running_workflow_steps"][0]["done"]
211+
assert response["running_workflow_steps"][0]["success"]
212+
assert response["running_workflow_steps"][1]["done"]
213+
assert response["running_workflow_steps"][1]["success"]
214+
# This test should generate a file in the simulated project directory
215+
assert project_file_exists(output_file_a)
216+
assert project_file_exists(output_file_b)

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,28 @@
11
---
22
kind: DataManagerWorkflow
33
kind-version: "2024.1"
4-
name: experimental-workflow
5-
description: An experimental workflow
4+
name: shortcut-example-1
5+
description: The shortcut example 1 workflow
66
steps:
7-
- name: step-1
7+
- name: example-1-step-1
88
description: The first step
9-
specification: '{"collection":"im-test","job":"process-a","version":"1.0.0", "variables":{"x": 7}}'
9+
specification: >-
10+
{
11+
"collection": "workflow-engine-unit-test-jobs",
12+
"job": "shortcut-example-1-process-a",
13+
"version": "1.0.0"
14+
}
1015
outputs:
1116
- output: 'outputFile'
1217
as: 'a.sdf'
13-
- name: step-2
14-
specification: '{"collection":"im-test","job":"process-b","version":"1.0.0", "variables":{"y": 22}}'
18+
- name: example-1-step-2
19+
description: The first step
20+
specification: >-
21+
{
22+
"collection": "workflow-engine-unit-test-jobs",
23+
"job": "shortcut-example-1-process-b",
24+
"version": "1.0.0"
25+
}
1526
inputs:
1627
- input: 'inputFile'
1728
from:

0 commit comments

Comments
 (0)