From ec1e1c8f1a2c96f51818e5265aef978aa7966b8a Mon Sep 17 00:00:00 2001 From: LanderOtto <48457093+LanderOtto@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:41:12 +0100 Subject: [PATCH] add test for scatter in loop (#1965) --- tests/loop/scatter-inside-loop.cwl | 53 ++++++++++++++++++++++++++++++ tests/test_loop.py | 13 ++++++++ 2 files changed, 66 insertions(+) create mode 100644 tests/loop/scatter-inside-loop.cwl diff --git a/tests/loop/scatter-inside-loop.cwl b/tests/loop/scatter-inside-loop.cwl new file mode 100644 index 000000000..7a4c394be --- /dev/null +++ b/tests/loop/scatter-inside-loop.cwl @@ -0,0 +1,53 @@ +#!/usr/bin/env cwl-runner +cwlVersion: v1.2 +class: Workflow +$namespaces: + cwltool: "http://commonwl.org/cwltool#" +requirements: + InlineJavascriptRequirement: {} + ScatterFeatureRequirement: {} + SubworkflowFeatureRequirement: {} +inputs: + i1: int[] + i2: int +outputs: + o1: + type: int[] + outputSource: scatter/o1 +steps: + scatter: + run: + class: Workflow + inputs: + i1: int[] + i2: int + outputs: + o1: + type: int[] + outputSource: subworkflow/o1 + steps: + subworkflow: + run: + class: ExpressionTool + inputs: + i1: int + i2: int + outputs: + o1: int + expression: > + ${return {'o1': inputs.i1 + inputs.i2};} + in: + i1: i1 + i2: i2 + out: [o1] + scatter: i1 + in: + i1: i1 + i2: i2 + out: [o1] + requirements: + cwltool:Loop: + loopWhen: $(inputs.i1[0] < 10) + loop: + i1: o1 + outputMethod: last \ No newline at end of file diff --git a/tests/test_loop.py b/tests/test_loop.py index 4d82e7e91..5bc9a99ea 100644 --- a/tests/test_loop.py +++ b/tests/test_loop.py @@ -221,6 +221,19 @@ def test_loop_inside_scatter() -> None: assert json.loads(stream.getvalue()) == expected +def test_scatter_inside_loop() -> None: + """Test a loop workflow with inside a scatter step.""" + stream = StringIO() + params = [ + "--enable-ext", + get_data("tests/loop/scatter-inside-loop.cwl"), + get_data("tests/loop/loop-inside-scatter-job.yml"), + ] + main(params, stdout=stream) + expected = {"o1": [10, 11, 12, 13, 14]} + assert json.loads(stream.getvalue()) == expected + + def test_nested_loops() -> None: """Test a workflow with two nested loops.""" stream = StringIO()