Skip to content
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
42 changes: 34 additions & 8 deletions tests/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,21 @@
_SIMPLE_PYTHON_MOLPROPS_WORKFLOW: Dict[str, Any] = yaml.safe_load(workflow_file)
assert _SIMPLE_PYTHON_MOLPROPS_WORKFLOW

_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW_FILE: str = os.path.join(
os.path.dirname(__file__),
"workflow-definitions",
"duplicate-workflow-variable-names.yaml",
)
with open(
_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW_FILE, "r", encoding="utf8"
) as workflow_file:
_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW: Dict[str, Any] = yaml.safe_load(
workflow_file
)
assert _DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW


def test_validate_minimal():
def test_validate_schema_for_minimal():
# Arrange

# Act
Expand All @@ -41,7 +54,7 @@ def test_validate_minimal():
assert error is None


def test_validate_minimal_get_step_names():
def test_minimal_get_step_names():
# Arrange

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


def test_validate_without_name():
def test_workflow_without_name():
# Arrange
workflow = _MINIMAL_WORKFLOW.copy()
_ = workflow.pop("name", None)
Expand All @@ -63,7 +76,7 @@ def test_validate_without_name():
assert error == "'name' is a required property"


def test_validate_name_with_spaces():
def test_workflow_name_with_spaces():
# Arrange
workflow = _MINIMAL_WORKFLOW.copy()
workflow["name"] = "workflow with spaces"
Expand All @@ -77,7 +90,7 @@ def test_validate_name_with_spaces():
)


def test_validate_shortcut_example_1():
def test_validate_schema_for_shortcut_example_1():
# Arrange

# Act
Expand All @@ -87,7 +100,7 @@ def test_validate_shortcut_example_1():
assert error is None


def test_validate_python_simple_molprops():
def test_validate_schema_for_python_simple_molprops():
# Arrange

# Act
Expand All @@ -97,15 +110,16 @@ def test_validate_python_simple_molprops():
assert error is None


def test_get_workflow_variables():
def test_get_workflow_variables_for_smiple_python_molprops():
# Arrange

# Act
wf_variables = decoder.get_variable_names(_SIMPLE_PYTHON_MOLPROPS_WORKFLOW)

# Assert
assert len(wf_variables) == 1
assert len(wf_variables) == 2
assert "candidateMolecules" in wf_variables
assert "clusteredMolecules" in wf_variables


def test_get_workflow_description():
Expand Down Expand Up @@ -138,3 +152,15 @@ def test_get_workflow_steps():
assert len(steps) == 2
assert steps[0]["name"] == "step1"
assert steps[1]["name"] == "step2"


def test_get_workflow_variables_for_duplicate_variables():
# Arrange

# Act
names = decoder.get_variable_names(_DUPLICATE_WORKFLOW_VARIABLE_NAMES_WORKFLOW)

# Assert
assert len(names) == 2
assert names[0] == "x"
assert names[1] == "x"
97 changes: 97 additions & 0 deletions tests/test_test_api_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,37 @@ def test_get_running_workflow_step():
assert response["name"] == "step-1"
assert not response["done"]
assert response["running_workflow"]["id"] == rwfid
assert "prior_running_workflow_step" not in response


def test_get_running_workflow_step_with_prior_step():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(workflow_definition={"name": "blah"})
wfid = response["id"]
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=wfid,
project_id=TEST_PROJECT_ID,
variables={},
)
rwfid = response["id"]
response, _ = utaa.create_running_workflow_step(
running_workflow_id=rwfid,
step="step-1",
prior_running_workflow_step_id="r-workflow-step-111",
)
rwfsid = response["id"]

# Act
response, _ = utaa.get_running_workflow_step(running_workflow_step_id=rwfsid)

# Assert
assert response["name"] == "step-1"
assert not response["done"]
assert response["running_workflow"]["id"] == rwfid
assert "prior_running_workflow_step" in response
assert response["prior_running_workflow_step"]["id"] == "r-workflow-step-111"


def test_create_instance():
Expand All @@ -291,3 +322,69 @@ def test_create_and_get_instance():

# Assert
assert response["running_workflow_step_id"] == "r-workflow-step-000"


def test_get_workflow_steps_driving_this_step_when_1st_step():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(
workflow_definition={
"name": "blah",
"steps": [{"name": "step-1"}, {"name": "step-2"}, {"name": "step-3"}],
}
)
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=response["id"],
project_id=TEST_PROJECT_ID,
variables={},
)
response, _ = utaa.create_running_workflow_step(
running_workflow_id=response["id"], step="step-1"
)
rwfs_id = response["id"]

# Act
response, _ = utaa.get_workflow_steps_driving_this_step(
running_workflow_step_id=rwfs_id
)

# Assert
assert response["caller_step_index"] == 0
assert len(response["steps"]) == 3
assert response["steps"][0]["name"] == "step-1"
assert response["steps"][1]["name"] == "step-2"
assert response["steps"][2]["name"] == "step-3"


def test_get_workflow_steps_driving_this_step_when_2nd_step():
# Arrange
utaa = UnitTestWorkflowAPIAdapter()
response = utaa.create_workflow(
workflow_definition={
"name": "blah",
"steps": [{"name": "step-1"}, {"name": "step-2"}, {"name": "step-3"}],
}
)
response = utaa.create_running_workflow(
user_id="dlister",
workflow_id=response["id"],
project_id=TEST_PROJECT_ID,
variables={},
)
response, _ = utaa.create_running_workflow_step(
running_workflow_id=response["id"], step="step-2"
)
rwfs_id = response["id"]

# Act
response, _ = utaa.get_workflow_steps_driving_this_step(
running_workflow_step_id=rwfs_id
)

# Assert
assert response["caller_step_index"] == 1
assert len(response["steps"]) == 3
assert response["steps"][0]["name"] == "step-1"
assert response["steps"][1]["name"] == "step-2"
assert response["steps"][2]["name"] == "step-3"
2 changes: 1 addition & 1 deletion tests/test_workflow_validator_for_create_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_validate_example_smiles_to_file():
assert error.error_msg is None


def test_validate_example_tow_step_nop():
def test_validate_example_two_step_nop():
# Arrange
workflow_file: str = os.path.join(
os.path.dirname(__file__), "workflow-definitions", "example-two-step-nop.yaml"
Expand Down
66 changes: 65 additions & 1 deletion tests/test_workflow_validator_for_run_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ def test_validate_example_nop_file():
assert error.error_msg is None


def test_validate_duplicate_step_names():
# Arrange
workflow_file: str = os.path.join(
os.path.dirname(__file__), "workflow-definitions", "duplicate-step-names.yaml"
)
with open(workflow_file, "r", encoding="utf8") as workflow_file:
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
assert workflow

# Act
error = WorkflowValidator.validate(
level=ValidationLevel.RUN,
workflow_definition=workflow,
)

# Assert
assert error.error_num == 2
assert error.error_msg == ["Duplicate step names found: step-1"]


def test_validate_example_smiles_to_file():
# Arrange
workflow_file: str = os.path.join(
Expand All @@ -49,7 +69,7 @@ def test_validate_example_smiles_to_file():
assert error.error_msg is None


def test_validate_example_tow_step_nop():
def test_validate_example_two_step_nop():
# Arrange
workflow_file: str = os.path.join(
os.path.dirname(__file__), "workflow-definitions", "example-two-step-nop.yaml"
Expand Down Expand Up @@ -87,3 +107,47 @@ def test_validate_shortcut_example_1():
# Assert
assert error.error_num == 0
assert error.error_msg is None


def test_validate_simple_python_molprops():
# Arrange
workflow_file: str = os.path.join(
os.path.dirname(__file__), "workflow-definitions", "simple-python-molprops.yaml"
)
with open(workflow_file, "r", encoding="utf8") as workflow_file:
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
assert workflow
variables = {"candidateMolecules": "input.sdf", "clusteredMolecules": "output.sdf"}

# Act
error = WorkflowValidator.validate(
level=ValidationLevel.RUN,
workflow_definition=workflow,
variables=variables,
)

# Assert
assert error.error_num == 0
assert error.error_msg is None


def test_validate_duplicate_workflow_variable_names():
# Arrange
workflow_file: str = os.path.join(
os.path.dirname(__file__),
"workflow-definitions",
"duplicate-workflow-variable-names.yaml",
)
with open(workflow_file, "r", encoding="utf8") as workflow_file:
workflow: dict[str, Any] = yaml.load(workflow_file, Loader=yaml.FullLoader)
assert workflow

# Act
error = WorkflowValidator.validate(
level=ValidationLevel.TAG,
workflow_definition=workflow,
)

# Assert
assert error.error_num == 3
assert error.error_msg == ["Duplicate workflow variable names found: x"]
Loading