|
3 | 3 | import pathlib |
4 | 4 | import pytz |
5 | 5 | from io import BufferedReader |
| 6 | +import yaml |
| 7 | +import cwltool.load_tool |
6 | 8 |
|
7 | 9 | import pytest |
8 | 10 | from unittest.mock import Mock |
9 | 11 |
|
10 | 12 | import docker.models.images |
| 13 | +import schema_salad.exceptions |
11 | 14 |
|
12 | 15 | import xcengine.core |
13 | 16 | import xcengine.parameters |
@@ -160,3 +163,35 @@ def test_script_creator_convert_notebook_to_script(tmp_path, clear): |
160 | 163 | expected = {output_dir / f for f in filenames} |
161 | 164 | assert set(output_dir.iterdir()) == expected |
162 | 165 | # 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 | + |
0 commit comments