Skip to content

Commit a765bd3

Browse files
committed
Add CWL unit test; name Workflow using notebook
xcengine-created CWL workflows now have an ID taken from the name of the input notebook. Addresses #29.
1 parent 23fb650 commit a765bd3

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

test/test_core.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import pathlib
44
import pytz
55
from io import BufferedReader
6+
import yaml
7+
import cwltool.load_tool
68

79
import pytest
810
from unittest.mock import Mock
911

1012
import docker.models.images
13+
import schema_salad.exceptions
1114

1215
import xcengine.core
1316
import xcengine.parameters
@@ -160,3 +163,35 @@ def test_script_creator_convert_notebook_to_script(tmp_path, clear):
160163
expected = {output_dir / f for f in filenames}
161164
assert set(output_dir.iterdir()) == expected
162165
# TODO test execution as well?
166+
167+
168+
def test_script_creator_cwl(tmp_path):
169+
nb_path = pathlib.Path(__file__).parent / "data" / "noparamtest.ipynb"
170+
script_creator = ScriptCreator(
171+
nb_path
172+
)
173+
image_tag = "foo"
174+
cwl_path = tmp_path / "test.cwl"
175+
cwl = script_creator.create_cwl(image_tag)
176+
with open(cwl_path, "w") as fh:
177+
yaml.dump(cwl, fh)
178+
loading_context, workflowobj, uri = cwltool.load_tool.fetch_document(
179+
str(cwl_path)
180+
)
181+
try:
182+
cwltool.load_tool.resolve_and_validate_document(
183+
loading_context, workflowobj, uri
184+
)
185+
except schema_salad.exceptions.ValidationException:
186+
pytest.fail("CWL validation failed")
187+
graph = cwl["$graph"]
188+
cli_tools = [n for n in graph if n["class"] == "CommandLineTool"]
189+
assert len(cli_tools) == 1
190+
cli_tool = cli_tools[0]
191+
assert cli_tool["requirements"]["DockerRequirement"]["dockerPull"] == image_tag
192+
assert cli_tool["hints"]["DockerRequirement"]["dockerPull"] == image_tag
193+
workflows = [n for n in graph if n["class"] == "Workflow"]
194+
assert len(workflows) == 1
195+
workflow = workflows[0]
196+
assert workflow["id"] == nb_path.stem
197+

xcengine/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@
3636
class ScriptCreator:
3737
"""Turn a Jupyter notebook into a set of scripts"""
3838

39+
nb_path: pathlib.Path
3940
notebook: nbformat.NotebookNode
4041
nb_params: NotebookParameters = NotebookParameters({})
4142

4243
def __init__(self, nb_path: pathlib.Path):
44+
self.nb_path = nb_path
4345
with open(nb_path) as fh:
4446
self.notebook = nbformat.read(fh, as_version=4)
4547
self.process_params_cell()
@@ -121,7 +123,7 @@ def create_cwl(self, image_tag: str) -> dict[str, Any]:
121123
"$graph": [
122124
{
123125
"class": "Workflow",
124-
"id": "xcengine_ap",
126+
"id": self.nb_path.stem,
125127
"label": "xcengine notebook",
126128
"doc": "xcengine notebook",
127129
"requirements": [],

0 commit comments

Comments
 (0)