Skip to content

Commit c37f6cf

Browse files
author
Peter Amstutz
committed
Test for getting cwlVersion from root document in load_tool.
1 parent ba22034 commit c37f6cf

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

cwltool/load_tool.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def resolve_and_validate_document(loadingContext,
221221
cwlVersion = workflowobj.get("cwlVersion")
222222
if not cwlVersion and fileuri != uri:
223223
# The tool we're loading is a fragment of a bigger file. Get
224-
# the document root element and look for cwlVersion there
224+
# the document root element and look for cwlVersion there.
225225
metadata = fetch_document(fileuri, loadingContext)[1]
226226
cwlVersion = metadata.get("cwlVersion")
227227
if not cwlVersion:
@@ -304,6 +304,8 @@ def resolve_and_validate_document(loadingContext,
304304

305305
# None means default behavior (do update)
306306
if loadingContext.do_update in (True, None):
307+
if "cwlVersion" not in metadata:
308+
metadata["cwlVersion"] = cwlVersion
307309
processobj = cast(CommentedMap, cmap(update.update(
308310
processobj, document_loader, fileuri, loadingContext.enable_dev, metadata)))
309311
if isinstance(processobj, MutableMapping):

tests/test_load_tool.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from cwltool.load_tool import load_tool
22
from cwltool.context import LoadingContext, RuntimeContext
33
from cwltool.errors import WorkflowException
4+
from cwltool.update import INTERNAL_VERSION
45
import pytest
56
from .util import (get_data, get_main_output,
67
get_windows_safe_factory,
@@ -60,3 +61,21 @@ def test_checklink_outputSource():
6061
loadingContext = LoadingContext({"do_validate": False})
6162
tool = load_tool(get_data("tests/wf/1st-workflow.cwl"), loadingContext)
6263
assert norm(tool.tool["outputs"][0]["outputSource"]) == outsrc
64+
65+
def test_load_graph_fragment():
66+
"""Test that outputSource is resolved correctly independent of value
67+
of do_validate.
68+
69+
"""
70+
71+
loadingContext = LoadingContext()
72+
uri = Path(get_data("tests/wf/scatter-wf4.cwl")).as_uri()+"#main"
73+
tool = load_tool(uri, loadingContext)
74+
75+
rs, metadata = tool.doc_loader.resolve_ref(uri)
76+
# Reload from a dict (in 'rs'), not a URI. The dict is a fragment
77+
# of original document and doesn't have cwlVersion set, so test
78+
# that it correctly looks up the root document to get the
79+
# cwlVersion.
80+
tool = load_tool(tool.tool, loadingContext)
81+
assert tool.metadata["cwlVersion"] == INTERNAL_VERSION

0 commit comments

Comments
 (0)