-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for a workflow using an expression for the resources
- Loading branch information
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"""Test for Requirements and Hints in cwltool.""" | ||
import json | ||
from io import StringIO | ||
|
||
from cwltool.main import main | ||
from .util import get_data | ||
|
||
|
||
def test_workflow_reqs_are_evaluated_eagerly_default_args() -> None: | ||
"""Test that a Workflow process will evaluate the requirements eagerly. | ||
Uses the default input values. | ||
This means that workflow steps, such as Expression and Command Line Tools | ||
can both use resources without re-evaluating expressions. This is useful | ||
when you have an expression that, for instance, dynamically decides | ||
how many threads/cpus to use. | ||
Issue: https://github.com/common-workflow-language/cwltool/issues/1330 | ||
""" | ||
stream = StringIO() | ||
|
||
assert ( | ||
main( | ||
[get_data("tests/wf/1330.cwl")], | ||
stdout=stream, | ||
) | ||
== 0 | ||
) | ||
|
||
out = json.loads(stream.getvalue()) | ||
assert out["out"] == "4\n" | ||
|
||
|
||
def test_workflow_reqs_are_evaluated_eagerly_provided_inputs() -> None: | ||
"""Test that a Workflow process will evaluate the requirements eagerly. | ||
Passes inputs via a job file. | ||
This means that workflow steps, such as Expression and Command Line Tools | ||
can both use resources without re-evaluating expressions. This is useful | ||
when you have an expression that, for instance, dynamically decides | ||
how many threads/cpus to use. | ||
Issue: https://github.com/common-workflow-language/cwltool/issues/1330 | ||
""" | ||
stream = StringIO() | ||
|
||
assert ( | ||
main( | ||
[get_data("tests/wf/1330.cwl"), get_data("tests/wf/1330.json")], | ||
stdout=stream, | ||
) | ||
== 0 | ||
) | ||
|
||
out = json.loads(stream.getvalue()) | ||
assert out["out"] == "3\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Original file: tests/eager-eval-reqs-hints/wf-reqs.cwl | ||
# From: https://github.com/common-workflow-language/cwl-v1.2/pull/195 | ||
cwlVersion: v1.2 | ||
class: Workflow | ||
|
||
requirements: | ||
ResourceRequirement: | ||
coresMax: $(inputs.threads_max) | ||
|
||
inputs: | ||
threads_max: | ||
type: int | ||
default: 4 | ||
|
||
steps: | ||
one: | ||
in: [] | ||
run: | ||
class: CommandLineTool | ||
inputs: | ||
other_input: | ||
type: int | ||
default: 8 | ||
baseCommand: echo | ||
arguments: [ $(runtime.cores) ] | ||
stdout: out.txt | ||
outputs: | ||
out: | ||
type: string | ||
outputBinding: | ||
glob: out.txt | ||
loadContents: true | ||
outputEval: $(self[0].contents) | ||
out: [out] | ||
|
||
outputs: | ||
out: | ||
type: string | ||
outputSource: one/out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"threads_max": 3 | ||
} |