Skip to content

Commit e107989

Browse files
bogdang989Peter Amstutz
authored andcommitted
Don't convert 0 to null on optional output (#1122)
* Don't convert 0 to null on output * Add test for optional numeric output returning 0. * Keep conversion to null for optional outputs where glob returns []. * Add windows_needs_docker to test_optional_numeric_output_0
1 parent fec7a10 commit e107989

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

cwltool/command_line_tool.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,12 @@ def collect_output(self,
797797
adjustFileObjs(r, revmap)
798798

799799
if not r and optional:
800-
return None
800+
# Don't convert zero or empty string to None
801+
if r in [0, '']:
802+
return r
803+
# For [] or None, return None
804+
else:
805+
return None
801806

802807
if (not empty_and_optional and isinstance(schema["type"], MutableMapping)
803808
and schema["type"]["type"] == "record"):

tests/test_examples.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,3 +920,14 @@ def test_v1_0_position_expression():
920920
['--debug', get_data(test_file), get_data(test_job)])
921921
assert "is not int" in stderr, stderr
922922
assert error_code == 1
923+
924+
925+
@windows_needs_docker
926+
def test_optional_numeric_output_0():
927+
test_file = "tests/wf/optional-numerical-output-0.cwl"
928+
error_code, stdout, stderr = get_main_output(
929+
[get_data(test_file)])
930+
931+
assert "completed success" in stderr
932+
assert error_code == 0
933+
assert json.loads(stdout)['out'] == 0
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cwlVersion: v1.0
2+
class: CommandLineTool
3+
baseCommand:
4+
- echo
5+
- "0"
6+
stdout: a.txt
7+
requirements:
8+
- class: InlineJavascriptRequirement
9+
inputs: []
10+
outputs:
11+
out:
12+
type: float?
13+
outputBinding:
14+
glob: "a.txt"
15+
loadContents: true
16+
outputEval: "${\n return parseFloat(self[0].contents);\n}"

0 commit comments

Comments
 (0)