Skip to content

Commit 2621312

Browse files
authored
Support array of integers and floats as command argument parameters (#2037)
1 parent 6d8c2a4 commit 2621312

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

cwltool/argparser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,11 @@ def add_argument(
903903
action = DirectoryAppendAction
904904
else:
905905
action = AppendAction
906+
items = inptype["items"]
907+
if items == "int" or items == "long":
908+
atype = int
909+
elif items == "double" or items == "float":
910+
atype = float
906911
elif isinstance(inptype, MutableMapping) and inptype["type"] == "enum":
907912
atype = str
908913
elif isinstance(inptype, MutableMapping) and inptype["type"] == "record":

tests/test_toolargparse.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,62 @@
101101
outputs: []
102102
"""
103103

104+
script_int = """
105+
#!/usr/bin/env cwl-runner
106+
107+
cwlVersion: v1.0
108+
class: ExpressionTool
109+
110+
inputs:
111+
foo: int[]
112+
113+
expression: '{"bar": $(inputs.foo)}'
114+
115+
outputs: []
116+
"""
117+
118+
script_long = """
119+
#!/usr/bin/env cwl-runner
120+
121+
cwlVersion: v1.0
122+
class: ExpressionTool
123+
124+
inputs:
125+
foo: long[]
126+
127+
expression: '{"bar": $(inputs.foo)}'
128+
129+
outputs: []
130+
"""
131+
132+
script_float = """
133+
#!/usr/bin/env cwl-runner
134+
135+
cwlVersion: v1.0
136+
class: ExpressionTool
137+
138+
inputs:
139+
foo: float[]
140+
141+
expression: '{"bar": $(inputs.foo)}'
142+
143+
outputs: []
144+
"""
145+
146+
script_double = """
147+
#!/usr/bin/env cwl-runner
148+
149+
cwlVersion: v1.0
150+
class: ExpressionTool
151+
152+
inputs:
153+
foo: double[]
154+
155+
expression: '{"bar": $(inputs.foo)}'
156+
157+
outputs: []
158+
"""
159+
104160
scripts_argparse_params = [
105161
("help", script_a, lambda x: ["--debug", x, "--input", get_data("tests/echo.cwl")]),
106162
("boolean", script_b, lambda x: [x, "--help"]),
@@ -120,6 +176,31 @@
120176
script_e,
121177
lambda x: [x, "--foo", "http://example.com"],
122178
),
179+
(
180+
"foo with int",
181+
script_int,
182+
lambda x: [x, "--foo", "1", "--foo", "2"],
183+
),
184+
(
185+
"foo with long for large value",
186+
script_long,
187+
lambda x: [x, "--foo", str(2**31 + 10)],
188+
),
189+
(
190+
"foo with long for small value",
191+
script_long,
192+
lambda x: [x, "--foo", str(-1 * (2**31) - 10)],
193+
),
194+
(
195+
"foo with float",
196+
script_float,
197+
lambda x: [x, "--foo", "1.2", "--foo", "3.4"],
198+
),
199+
(
200+
"foo with double",
201+
script_double,
202+
lambda x: [x, "--foo", "1.2", "--foo", "3.4"],
203+
),
123204
]
124205

125206

0 commit comments

Comments
 (0)