Skip to content

Commit 4834529

Browse files
authored
Merge pull request #575 from common-workflow-language/fix/#574
Run "#main" resolved object by default
2 parents 6670a19 + b02a63f commit 4834529

File tree

4 files changed

+63
-11
lines changed

4 files changed

+63
-11
lines changed

cwltool/load_tool.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,13 @@ def make_tool(document_loader, # type: Loader
281281
"""Make a Python CWL object."""
282282
resolveduri = document_loader.resolve_ref(uri)[0]
283283

284+
processobj = None
284285
if isinstance(resolveduri, list):
285-
if len(resolveduri) == 1:
286-
processobj = resolveduri[0]
287-
else:
286+
for obj in resolveduri:
287+
if obj['id'].endswith('#main'):
288+
processobj = obj
289+
break
290+
if not processobj:
288291
raise WorkflowException(
289292
u"Tool file contains graph of multiple objects, must specify "
290293
"one of #%s" % ", #".join(

tests/test_pack.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
from __future__ import absolute_import
2+
23
import json
3-
import os
44
import unittest
5+
6+
import os
57
from functools import partial
68

9+
import pytest
10+
from six import StringIO
11+
712
import cwltool.pack
8-
from cwltool.main import print_pack as print_pack
913
import cwltool.workflow
1014
from cwltool.load_tool import fetch_document, validate_document
11-
from cwltool.main import makeRelative
15+
from cwltool.main import makeRelative, main, print_pack
1216
from cwltool.pathmapper import adjustDirObjs, adjustFileObjs
13-
17+
from cwltool.utils import onWindows
1418
from .util import get_data
1519

1620

1721
class TestPack(unittest.TestCase):
22+
maxDiff = None
23+
1824
def test_pack(self):
19-
self.maxDiff = None
2025

2126
document_loader, workflowobj, uri = fetch_document(
2227
get_data("tests/wf/revsort.cwl"))
@@ -38,8 +43,6 @@ def test_pack(self):
3843
def test_pack_missing_cwlVersion(self):
3944
"""Test to ensure the generated pack output is not missing
4045
the `cwlVersion` in case of single tool workflow and single step workflow"""
41-
# Since diff is longer than 3174 characters
42-
self.maxDiff = None
4346

4447
# Testing single tool workflow
4548
document_loader, workflowobj, uri = fetch_document(
@@ -76,7 +79,6 @@ def test_pack_idempotence_workflow(self):
7679
self._pack_idempotently("tests/wf/count-lines1-wf.cwl")
7780

7881
def _pack_idempotently(self, document):
79-
self.maxDiff = None
8082
document_loader, workflowobj, uri = fetch_document(
8183
get_data(document))
8284
document_loader, avsc_names, processobj, metadata, uri = validate_document(
@@ -89,3 +91,28 @@ def _pack_idempotently(self, document):
8991
document_loader, workflowobj, uri)
9092
double_packed = json.loads(print_pack(document_loader, processobj, uri2, metadata))
9193
self.assertEqual(packed, double_packed)
94+
95+
@pytest.mark.skipif(onWindows(),
96+
reason="Instance of cwltool is used, on Windows it invokes a default docker container"
97+
"which is not supported on AppVeyor")
98+
def test_packed_workflow_execution(self):
99+
test_wf = "tests/wf/count-lines1-wf.cwl"
100+
test_wf_job = "tests/wf/wc-job.json"
101+
document_loader, workflowobj, uri = fetch_document(
102+
get_data(test_wf))
103+
document_loader, avsc_names, processobj, metadata, uri = validate_document(
104+
document_loader, workflowobj, uri)
105+
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))
106+
temp_packed_path = "/tmp/packedwf"
107+
with open(temp_packed_path, 'w') as f:
108+
json.dump(packed, f)
109+
normal_output = StringIO()
110+
packed_output = StringIO()
111+
self.assertEquals(main(['--debug', get_data(temp_packed_path),
112+
get_data(test_wf_job)],
113+
stdout=packed_output), 0)
114+
self.assertEquals(main([get_data(test_wf),
115+
get_data(test_wf_job)],
116+
stdout=normal_output), 0)
117+
self.assertEquals(json.loads(packed_output.getvalue()), json.loads(normal_output.getvalue()))
118+

tests/wf/wc-job.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"file1": {
3+
"class": "File",
4+
"location": "whale.txt"
5+
}
6+
}

tests/wf/whale.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Call me Ishmael. Some years ago--never mind how long precisely--having
2+
little or no money in my purse, and nothing particular to interest me on
3+
shore, I thought I would sail about a little and see the watery part of
4+
the world. It is a way I have of driving off the spleen and regulating
5+
the circulation. Whenever I find myself growing grim about the mouth;
6+
whenever it is a damp, drizzly November in my soul; whenever I find
7+
myself involuntarily pausing before coffin warehouses, and bringing up
8+
the rear of every funeral I meet; and especially whenever my hypos get
9+
such an upper hand of me, that it requires a strong moral principle to
10+
prevent me from deliberately stepping into the street, and methodically
11+
knocking people's hats off--then, I account it high time to get to sea
12+
as soon as I can. This is my substitute for pistol and ball. With a
13+
philosophical flourish Cato throws himself upon his sword; I quietly
14+
take to the ship. There is nothing surprising in this. If they but knew
15+
it, almost all men in their degree, some time or other, cherish very
16+
nearly the same feelings towards the ocean with me.

0 commit comments

Comments
 (0)