Skip to content

Commit de1a509

Browse files
author
Alan Christie
committed
feat: Decoder now returns workflow variable names
1 parent 0376974 commit de1a509

File tree

3 files changed

+77
-4
lines changed

3 files changed

+77
-4
lines changed

tests/test_decoder.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
_SHORTCUT_EXAMPLE_1_WORKFLOW: Dict[str, Any] = yaml.safe_load(workflow_file)
2424
assert _SHORTCUT_EXAMPLE_1_WORKFLOW
2525

26+
_SIMPLE_PYTHON_MOLPROPS_WORKFLOW_FILE: str = os.path.join(
27+
os.path.dirname(__file__), "workflow-definitions", "simple-python-molprops.yaml"
28+
)
29+
with open(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW_FILE, "r", encoding="utf8") as workflow_file:
30+
_SIMPLE_PYTHON_MOLPROPS_WORKFLOW: Dict[str, Any] = yaml.safe_load(workflow_file)
31+
assert _SIMPLE_PYTHON_MOLPROPS_WORKFLOW
32+
2633

2734
def test_validate_minimal():
2835
# Arrange
@@ -78,3 +85,56 @@ def test_validate_shortcut_example_1():
7885

7986
# Assert
8087
assert error is None
88+
89+
90+
def test_validate_python_simple_molprops():
91+
# Arrange
92+
93+
# Act
94+
error = decoder.validate_schema(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
95+
96+
# Assert
97+
assert error is None
98+
99+
100+
def test_get_workflow_variables():
101+
# Arrange
102+
103+
# Act
104+
wf_variables = decoder.get_variable_names(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
105+
106+
# Assert
107+
assert len(wf_variables) == 1
108+
assert "candidateMolecules" in wf_variables
109+
110+
111+
def test_get_workflow_description():
112+
# Arrange
113+
114+
# Act
115+
description = decoder.get_description(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
116+
117+
# Assert
118+
assert description == "A simple python experimental workflow"
119+
120+
121+
def test_get_workflow_name():
122+
# Arrange
123+
124+
# Act
125+
name = decoder.get_name(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
126+
127+
# Assert
128+
assert name == "python-workflow"
129+
130+
131+
def test_get_workflow_steps():
132+
# Arrange
133+
134+
# Act
135+
steps = decoder.get_steps(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)
136+
137+
# Assert
138+
assert len(steps) == 2
139+
assert steps[0]["name"] == "step1"
140+
assert steps[1]["name"] == "step2"

tests/workflow-definitions/simple-python-molprops.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
kind: DataManagerWorkflow
33
kind-version: "2024.1"
44
name: python-workflow
5-
description: An simple python experimental workflow
5+
description: A simple python experimental workflow
66
variables:
77
inputs:
88
- name: candidateMolecules
9-
- type: squonk/x-smiles
9+
type: squonk/x-smiles
1010
outputs:
1111
- name: clusteredMolecules
1212
from:

workflow/decoder.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,24 @@ def get_steps(definition: dict[str, Any]) -> list[dict[str, Any]]:
5252
return response
5353

5454

55-
def get_workflow_name(definition: dict[str, Any]) -> str:
55+
def get_name(definition: dict[str, Any]) -> str:
5656
"""Given a Workflow definition this function returns its name."""
5757
return str(definition.get("name", ""))
5858

5959

60-
def get_workflow_description(definition: dict[str, Any]) -> str | None:
60+
def get_description(definition: dict[str, Any]) -> str | None:
6161
"""Given a Workflow definition this function returns its description (if it has one)."""
6262
return definition.get("description")
63+
64+
65+
def get_variable_names(definition: dict[str, Any]) -> list[str]:
66+
"""Given a Workflow definition this function returns all the names of the
67+
variables defined at the workflow level."""
68+
wf_variable_names: set[str] = set()
69+
variables: dict[str, Any] | None = definition.get("variables")
70+
if variables:
71+
for input_variable in variables.get("inputs", []):
72+
name: str = input_variable["name"]
73+
assert name not in wf_variable_names
74+
wf_variable_names.add(name)
75+
return list(wf_variable_names)

0 commit comments

Comments
 (0)