From d89fd84ef1b9e45eb2dc5d4116805626b0298e05 Mon Sep 17 00:00:00 2001 From: "Bruno P. Kinoshita" Date: Fri, 19 Aug 2022 10:28:46 +1200 Subject: [PATCH] Add unit test for a workflow using an expression for the resources --- tests/test_reqs_hints.py | 56 ++++++++++++++++++++++++++++++++++++++++ tests/wf/1330.cwl | 39 ++++++++++++++++++++++++++++ tests/wf/1330.json | 3 +++ 3 files changed, 98 insertions(+) create mode 100644 tests/test_reqs_hints.py create mode 100644 tests/wf/1330.cwl create mode 100644 tests/wf/1330.json diff --git a/tests/test_reqs_hints.py b/tests/test_reqs_hints.py new file mode 100644 index 0000000000..54ae12d382 --- /dev/null +++ b/tests/test_reqs_hints.py @@ -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" diff --git a/tests/wf/1330.cwl b/tests/wf/1330.cwl new file mode 100644 index 0000000000..557ad78096 --- /dev/null +++ b/tests/wf/1330.cwl @@ -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 diff --git a/tests/wf/1330.json b/tests/wf/1330.json new file mode 100644 index 0000000000..ae7b995fdf --- /dev/null +++ b/tests/wf/1330.json @@ -0,0 +1,3 @@ +{ + "threads_max": 3 +} \ No newline at end of file