From 75f31fcd6f725fd3f604c11b3c9e4449f30d4be7 Mon Sep 17 00:00:00 2001 From: Jake Fennick Date: Wed, 12 Jun 2024 13:57:10 -1000 Subject: [PATCH 1/4] recursively insert output format --- cwltool/command_line_tool.py | 15 +++++++++++++-- tests/output_2D_file_format.cwl | 29 +++++++++++++++++++++++++++++ tests/test_2D.py | 17 +++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 tests/output_2D_file_format.cwl create mode 100644 tests/test_2D.py diff --git a/cwltool/command_line_tool.py b/cwltool/command_line_tool.py index b11bb4bc3..4afd84228 100644 --- a/cwltool/command_line_tool.py +++ b/cwltool/command_line_tool.py @@ -1495,8 +1495,19 @@ def collect_output( ) primary["format"] = format_eval else: - for primary in aslist(result): - primary["format"] = format_field + + def recursively_insert(j_dict: Any, key: Any, val: Any) -> Any: + """Recursively inserts a value into any dictionaries""" + if isinstance(j_dict, List): + return [recursively_insert(x, key, val) for x in j_dict] + if isinstance(j_dict, Dict): + if j_dict.get("class") == "File": + j_dict[key] = val + else: + return {x: recursively_insert(y, key, val) for x, y in j_dict.items()} + return j_dict + + result = recursively_insert(result, "format", format_field) # Ensure files point to local references outside of the run environment adjustFileObjs(result, revmap) diff --git a/tests/output_2D_file_format.cwl b/tests/output_2D_file_format.cwl new file mode 100644 index 000000000..621111061 --- /dev/null +++ b/tests/output_2D_file_format.cwl @@ -0,0 +1,29 @@ +#!/usr/bin/env cwl-runner +cwlVersion: v1.0 + +class: CommandLineTool + +baseCommand: 'true' + +requirements: + InlineJavascriptRequirement: {} + +inputs: {} + +outputs: + output_array: + type: {"type": "array", "items": {"type": "array", "items": "File"}} + outputBinding: + outputEval: | + ${ + var out2d = []; + for (var i = 0; i < 2; i++) { + var out1d = []; + for (var j = 0; j < 2; j++) { + out1d.push({"class": "File", "location": "../../filename.txt"}); + } + out2d.push(out1d); + } + return out2d; + } + format: some_format diff --git a/tests/test_2D.py b/tests/test_2D.py new file mode 100644 index 000000000..305840bb9 --- /dev/null +++ b/tests/test_2D.py @@ -0,0 +1,17 @@ +import subprocess +import sys + +from .util import get_data + + +def test_output_2D_file_format() -> None: + """Test format tag for 2D output arrays.""" + + params = [ + sys.executable, + "-m", + "cwltool", + get_data("tests/output_2D_file_format.cwl"), + ] + + assert subprocess.check_call(params) == 0 From 248873f5ae88ef841bcfc0a9e5e2b5d9c6f0040d Mon Sep 17 00:00:00 2001 From: Vasu Jaganath Date: Thu, 27 Jun 2024 11:39:05 -0400 Subject: [PATCH 2/4] modify test2D to automate file creation --- cwltool/command_line_tool.py | 6 ++++-- tests/test_2D.py | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/cwltool/command_line_tool.py b/cwltool/command_line_tool.py index 4afd84228..c4798c0b7 100644 --- a/cwltool/command_line_tool.py +++ b/cwltool/command_line_tool.py @@ -1497,14 +1497,16 @@ def collect_output( else: def recursively_insert(j_dict: Any, key: Any, val: Any) -> Any: - """Recursively inserts a value into any dictionaries""" + """Recursively insert a value into any dictionary.""" if isinstance(j_dict, List): return [recursively_insert(x, key, val) for x in j_dict] if isinstance(j_dict, Dict): if j_dict.get("class") == "File": j_dict[key] = val else: - return {x: recursively_insert(y, key, val) for x, y in j_dict.items()} + return { + x: recursively_insert(y, key, val) for x, y in j_dict.items() + } return j_dict result = recursively_insert(result, "format", format_field) diff --git a/tests/test_2D.py b/tests/test_2D.py index 305840bb9..fafddef5a 100644 --- a/tests/test_2D.py +++ b/tests/test_2D.py @@ -1,16 +1,20 @@ import subprocess import sys +from pathlib import Path from .util import get_data def test_output_2D_file_format() -> None: - """Test format tag for 2D output arrays.""" + """A simple test for format tag fix for 2D output arrays.""" + Path("filename.txt").touch() params = [ sys.executable, "-m", "cwltool", + "--cachedir", # just so that the relative path of file works out + "foo", get_data("tests/output_2D_file_format.cwl"), ] From 07c162fee4830a8ee549137638d4f688a57ee345 Mon Sep 17 00:00:00 2001 From: Vasu Jaganath Date: Tue, 9 Jul 2024 16:16:12 -0400 Subject: [PATCH 3/4] try to fix tmp_dir permission failure with test fixture --- cwltool/command_line_tool.py | 4 ++-- tests/test_2D.py | 30 ++++++++++++++---------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/cwltool/command_line_tool.py b/cwltool/command_line_tool.py index c4798c0b7..d249c0200 100644 --- a/cwltool/command_line_tool.py +++ b/cwltool/command_line_tool.py @@ -1498,9 +1498,9 @@ def collect_output( def recursively_insert(j_dict: Any, key: Any, val: Any) -> Any: """Recursively insert a value into any dictionary.""" - if isinstance(j_dict, List): + if isinstance(j_dict, MutableSequence): return [recursively_insert(x, key, val) for x in j_dict] - if isinstance(j_dict, Dict): + if isinstance(j_dict, MutableMapping): if j_dict.get("class") == "File": j_dict[key] = val else: diff --git a/tests/test_2D.py b/tests/test_2D.py index fafddef5a..952515f25 100644 --- a/tests/test_2D.py +++ b/tests/test_2D.py @@ -1,21 +1,19 @@ -import subprocess -import sys from pathlib import Path +import pytest +from .util import get_data, get_main_output -from .util import get_data - - -def test_output_2D_file_format() -> None: +@pytest.fixture(scope="session") +def test_output_2d_file_format(tmp_path_factory: pytest.TempPathFactory) -> None: """A simple test for format tag fix for 2D output arrays.""" - Path("filename.txt").touch() - params = [ - sys.executable, - "-m", - "cwltool", - "--cachedir", # just so that the relative path of file works out - "foo", - get_data("tests/output_2D_file_format.cwl"), - ] + tmp_path: Path = tmp_path_factory.mktemp("tmp") + # still need to create 'filename.txt' as it is needed in output_2D_file_format.cwl + _ = tmp_path / "filename.txt" + commands = [ + "--cachedir", + str(tmp_path / "foo"), # just so that the relative path of file works out + get_data("tests/output_2D_file_format.cwl")] + + error_code, _, stderr = get_main_output(commands) - assert subprocess.check_call(params) == 0 + assert error_code == 0, stderr From c73137b99ae79ba9236c3fe616fc16d1070b0561 Mon Sep 17 00:00:00 2001 From: "Michael R. Crusoe" Date: Wed, 10 Jul 2024 20:26:18 +0200 Subject: [PATCH 4/4] simplify --- tests/test_2D.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/test_2D.py b/tests/test_2D.py index 952515f25..87d16ccf0 100644 --- a/tests/test_2D.py +++ b/tests/test_2D.py @@ -1,18 +1,20 @@ from pathlib import Path -import pytest + from .util import get_data, get_main_output -@pytest.fixture(scope="session") -def test_output_2d_file_format(tmp_path_factory: pytest.TempPathFactory) -> None: + +def test_output_2d_file_format(tmp_path: Path) -> None: """A simple test for format tag fix for 2D output arrays.""" - tmp_path: Path = tmp_path_factory.mktemp("tmp") # still need to create 'filename.txt' as it is needed in output_2D_file_format.cwl - _ = tmp_path / "filename.txt" + (tmp_path / "filename.txt").touch() commands = [ "--cachedir", str(tmp_path / "foo"), # just so that the relative path of file works out - get_data("tests/output_2D_file_format.cwl")] + "--outdir", + str(tmp_path / "out"), + get_data("tests/output_2D_file_format.cwl"), + ] error_code, _, stderr = get_main_output(commands)