Skip to content

Commit df93a68

Browse files
committed
Add unit test for a workflow using an expression for the resources
1 parent 0cf7198 commit df93a68

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

tests/test_reqs_hints.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Test for Requirements and Hints in cwltool."""
2+
import json
3+
from io import StringIO
4+
5+
from cwltool.main import main
6+
from .util import get_data
7+
8+
9+
def test_workflow_reqs_are_evaluated_eagerly_default_args() -> None:
10+
"""Test that a Workflow process will evaluate the requirements eagerly.
11+
Uses the default input values.
12+
13+
This means that workflow steps, such as Expression and Command Line Tools
14+
can both use resources without re-evaluating expressions. This is useful
15+
when you have an expression that, for instance, dynamically decides
16+
how many threads/cpus to use.
17+
18+
Issue: https://github.com/common-workflow-language/cwltool/issues/1330
19+
"""
20+
stream = StringIO()
21+
22+
assert (
23+
main(
24+
[get_data("tests/wf/1330.cwl")],
25+
stdout=stream,
26+
)
27+
== 0
28+
)
29+
30+
out = json.loads(stream.getvalue())
31+
assert out["out"] == "4\n"
32+
33+
34+
def test_workflow_reqs_are_evaluated_eagerly_provided_inputs() -> None:
35+
"""Test that a Workflow process will evaluate the requirements eagerly.
36+
Passes inputs via a job file.
37+
38+
This means that workflow steps, such as Expression and Command Line Tools
39+
can both use resources without re-evaluating expressions. This is useful
40+
when you have an expression that, for instance, dynamically decides
41+
how many threads/cpus to use.
42+
43+
Issue: https://github.com/common-workflow-language/cwltool/issues/1330
44+
"""
45+
stream = StringIO()
46+
47+
assert (
48+
main(
49+
[get_data("tests/wf/1330.cwl"), get_data("tests/wf/1330.json")],
50+
stdout=stream,
51+
)
52+
== 0
53+
)
54+
55+
out = json.loads(stream.getvalue())
56+
assert out["out"] == "3\n"

tests/wf/1330.cwl

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Original file: tests/eager-eval-reqs-hints/wf-reqs.cwl
2+
# From: https://github.com/common-workflow-language/cwl-v1.2/pull/195
3+
cwlVersion: v1.2
4+
class: Workflow
5+
6+
requirements:
7+
ResourceRequirement:
8+
coresMax: $(inputs.threads_max)
9+
10+
inputs:
11+
threads_max:
12+
type: int
13+
default: 4
14+
15+
steps:
16+
one:
17+
in: []
18+
run:
19+
class: CommandLineTool
20+
inputs:
21+
other_input:
22+
type: int
23+
default: 8
24+
baseCommand: echo
25+
arguments: [ $(runtime.cores) ]
26+
stdout: out.txt
27+
outputs:
28+
out:
29+
type: string
30+
outputBinding:
31+
glob: out.txt
32+
loadContents: true
33+
outputEval: $(self[0].contents)
34+
out: [out]
35+
36+
outputs:
37+
out:
38+
type: string
39+
outputSource: one/out

tests/wf/1330.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"threads_max": 3
3+
}

0 commit comments

Comments
 (0)