@@ -339,6 +339,7 @@ def test_provenance(tmpdir):
339
339
340
340
341
341
def test_mapnode_crash (tmpdir ):
342
+ """Test mapnode crash when stop_on_first_crash is True"""
342
343
def myfunction (string ):
343
344
return string + 'meh'
344
345
node = pe .MapNode (niu .Function (input_names = ['WRONG' ],
@@ -350,14 +351,55 @@ def myfunction(string):
350
351
node .inputs .WRONG = ['string' + str (i ) for i in range (3 )]
351
352
node .config = deepcopy (config ._sections )
352
353
node .config ['execution' ]['stop_on_first_crash' ] = True
353
- cwd = os .getcwd ()
354
- node .base_dir = tmpdir
354
+ node .base_dir = str (tmpdir )
355
355
356
356
error_raised = False
357
357
try :
358
358
node .run ()
359
359
except TypeError as e :
360
360
error_raised = True
361
- os .chdir (cwd )
362
- rmtree (node .base_dir )
361
+ assert error_raised
362
+
363
+
364
+ def test_mapnode_crash2 (tmpdir ):
365
+ """Test mapnode crash when stop_on_first_crash is False"""
366
+ def myfunction (string ):
367
+ return string + 'meh'
368
+ node = pe .MapNode (niu .Function (input_names = ['WRONG' ],
369
+ output_names = ['newstring' ],
370
+ function = myfunction ),
371
+ iterfield = ['WRONG' ],
372
+ name = 'myfunc' )
373
+
374
+ node .inputs .WRONG = ['string' + str (i ) for i in range (3 )]
375
+ node .base_dir = str (tmpdir )
376
+
377
+ error_raised = False
378
+ try :
379
+ node .run ()
380
+ except Exception as e :
381
+ error_raised = True
382
+ assert error_raised
383
+
384
+
385
+ def test_mapnode_crash3 (tmpdir ):
386
+ """Test mapnode crash when mapnode is embedded in a workflow"""
387
+ def myfunction (string ):
388
+ return string + 'meh'
389
+ node = pe .MapNode (niu .Function (input_names = ['WRONG' ],
390
+ output_names = ['newstring' ],
391
+ function = myfunction ),
392
+ iterfield = ['WRONG' ],
393
+ name = 'myfunc' )
394
+
395
+ node .inputs .WRONG = ['string' + str (i ) for i in range (3 )]
396
+ wf = pe .Workflow ('test_mapnode_crash' )
397
+ wf .add_nodes ([node ])
398
+ wf .base_dir = str (tmpdir )
399
+
400
+ error_raised = False
401
+ try :
402
+ wf .run ()
403
+ except RuntimeError as e :
404
+ error_raised = True
363
405
assert error_raised
0 commit comments