Skip to content

pack.py: add 'cwlVersion' in pack dict, if only single item exists in $graph #497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 8, 2017
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
5 changes: 5 additions & 0 deletions cwltool/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,9 @@ def rewrite_id(r, mainuri):

import_embed(packed, set())

if len(packed["$graph"]) == 1:
# duplicate 'cwlVersion' inside $graph when there is a single item
# because we're printing contents inside '$graph' rather than whole dict
packed["$graph"][0]["cwlVersion"] = packed["cwlVersion"]

return packed
27 changes: 27 additions & 0 deletions tests/test_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from functools import partial

import cwltool.pack
from cwltool.main import print_pack as print_pack
import cwltool.workflow
from cwltool.load_tool import fetch_document, validate_document
from cwltool.main import makeRelative
Expand Down Expand Up @@ -33,3 +34,29 @@ def test_pack(self):
del expect_packed["$schemas"]

self.assertEqual(expect_packed, packed)

def test_pack_missing_cwlVersion(self):
"""Test to ensure the generated pack output is not missing
the `cwlVersion` in case of single tool workflow and single step workflow"""
# Since diff is longer than 3174 characters
self.maxDiff = None

# Testing single tool workflow
document_loader, workflowobj, uri = fetch_document(
get_data("tests/wf/hello_single_tool.cwl"))
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
# generate pack output dict
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))

self.assertEqual('v1.0', packed["cwlVersion"])

# Testing single step workflow
document_loader, workflowobj, uri = fetch_document(
get_data("tests/wf/hello-workflow.cwl"))
document_loader, avsc_names, processobj, metadata, uri = validate_document(
document_loader, workflowobj, uri)
# generate pack output dict
packed = json.loads(print_pack(document_loader, processobj, uri, metadata))

self.assertEqual('v1.0', packed["cwlVersion"])
38 changes: 38 additions & 0 deletions tests/wf/hello-workflow.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env cwl-runner

cwlVersion: v1.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mr-c does this qualify as both? a single tool, simple workflow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point is to traverse both branches of

if len(packed["$graph"]) > 1:

class: Workflow

label: "Hello World"
doc: "Outputs a message using echo"

inputs:
usermessage: string

outputs:
response:
outputSource: step0/response
type: File

steps:
step0:
run:
class: CommandLineTool
inputs:
message:
type: string
doc: "The message to print"
default: "Hello World"
inputBinding:
position: 1
baseCommand: echo
arguments:
- "-n"
- "-e"
stdout: response.txt
outputs:
response:
type: stdout
in:
message: usermessage
out: [response]
9 changes: 9 additions & 0 deletions tests/wf/hello_single_tool.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cwlVersion: v1.0
class: CommandLineTool
baseCommand: echo
inputs:
message:
type: string
inputBinding:
position: 1
outputs: []