File tree Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Expand file tree Collapse file tree 2 files changed +35
-8
lines changed Original file line number Diff line number Diff line change @@ -199,19 +199,21 @@ def _run_task(self):
199
199
del inputs ["_func" ]
200
200
self .output_ = None
201
201
output = cp .loads (self .inputs ._func )(** inputs )
202
- if output is not None :
203
- output_names = [el [0 ] for el in self .output_spec .fields ]
204
- self .output_ = {}
205
- if len (output_names ) > 1 :
206
- if len (output_names ) == len (output ):
202
+ output_names = [el [0 ] for el in self .output_spec .fields ]
203
+ if output is None :
204
+ self .output_ = dict ((nm , None ) for nm in output_names )
205
+ else :
206
+ if len (output_names ) == 1 :
207
+ # if only one element in the fields, everything should be returned together
208
+ self .output_ = {output_names [0 ]: output }
209
+ else :
210
+ if isinstance (output , tuple ) and len (output_names ) == len (output ):
207
211
self .output_ = dict (zip (output_names , output ))
208
212
else :
209
213
raise Exception (
210
214
f"expected { len (self .output_spec .fields )} elements, "
211
- f"but { len ( output ) } were returned"
215
+ f"but { output } were returned"
212
216
)
213
- else : # if only one element in the fields, everything should be returned together
214
- self .output_ [output_names [0 ]] = output
215
217
216
218
217
219
class ShellCommandTask (TaskBase ):
Original file line number Diff line number Diff line change @@ -309,6 +309,31 @@ def raise_exception(c, d):
309
309
assert pytest .raises (Exception , bad_funk )
310
310
311
311
312
+ def test_result_none_1 ():
313
+ """ checking if None is properly returned as the result"""
314
+
315
+ @mark .task
316
+ def fun_none (x ):
317
+ return None
318
+
319
+ task = fun_none (name = "none" , x = 3 )
320
+ res = task ()
321
+ assert res .output .out is None
322
+
323
+
324
+ def test_result_none_2 ():
325
+ """ checking if None is properly set for all outputs """
326
+
327
+ @mark .task
328
+ def fun_none (x ) -> (ty .Any , ty .Any ):
329
+ return None
330
+
331
+ task = fun_none (name = "none" , x = 3 )
332
+ res = task ()
333
+ assert res .output .out1 is None
334
+ assert res .output .out2 is None
335
+
336
+
312
337
def test_audit_prov (tmpdir ):
313
338
@mark .task
314
339
def testfunc (a : int , b : float = 0.1 ) -> ty .NamedTuple ("Output" , [("out" , float )]):
You can’t perform that action at this time.
0 commit comments