@@ -156,12 +156,8 @@ def test_expansion():
156
156
pipe5 .add_nodes ([pipe4 ])
157
157
pipe6 = pe .Workflow (name = "pipe6" )
158
158
pipe6 .connect ([(pipe5 , pipe3 , [('pipe4.mod5.output1' , 'pipe2.mod3.input1' )])])
159
- error_raised = False
160
- try :
161
- pipe6 ._flatgraph = pipe6 ._create_flat_graph ()
162
- except :
163
- error_raised = True
164
- assert not error_raised
159
+
160
+ pipe6 ._flatgraph = pipe6 ._create_flat_graph ()
165
161
166
162
167
163
def test_iterable_expansion ():
@@ -479,14 +475,9 @@ def func1(in1):
479
475
nested = False ,
480
476
name = 'n1' )
481
477
n2 .inputs .in1 = [[1 , [2 ]], 3 , [4 , 5 ]]
482
- error_raised = False
483
- try :
484
- n2 .run ()
485
- except Exception as e :
486
- from nipype .pipeline .engine .base import logger
487
- logger .info ('Exception: %s' % str (e ))
488
- error_raised = True
489
- assert error_raised
478
+
479
+ with pytest .raises (Exception ): n2 .run ()
480
+
490
481
491
482
492
483
def test_node_hash (tmpdir ):
@@ -518,35 +509,26 @@ def func2(a):
518
509
w1 .config ['execution' ] = {'stop_on_first_crash' : 'true' ,
519
510
'local_hash_check' : 'false' ,
520
511
'crashdump_dir' : wd }
521
- error_raised = False
522
512
# create dummy distributed plugin class
523
513
from nipype .pipeline .plugins .base import DistributedPluginBase
524
514
525
515
class RaiseError (DistributedPluginBase ):
526
516
def _submit_job (self , node , updatehash = False ):
527
517
raise Exception ('Submit called' )
528
- try :
518
+
519
+ with pytest .raises (Exception ) as excinfo :
529
520
w1 .run (plugin = RaiseError ())
530
- except Exception as e :
531
- from nipype .pipeline .engine .base import logger
532
- logger .info ('Exception: %s' % str (e ))
533
- error_raised = True
534
- assert error_raised
521
+ assert 'Submit called' == str (excinfo .value )
522
+
535
523
# rerun to ensure we have outputs
536
524
w1 .run (plugin = 'Linear' )
537
525
# set local check
538
526
w1 .config ['execution' ] = {'stop_on_first_crash' : 'true' ,
539
527
'local_hash_check' : 'true' ,
540
528
'crashdump_dir' : wd }
541
- error_raised = False
542
- try :
543
- w1 .run (plugin = RaiseError ())
544
- except Exception as e :
545
- from nipype .pipeline .engine .base import logger
546
- logger .info ('Exception: %s' % str (e ))
547
- error_raised = True
548
- assert not error_raised
549
529
530
+ w1 .run (plugin = RaiseError ())
531
+
550
532
551
533
def test_old_config (tmpdir ):
552
534
wd = str (tmpdir )
@@ -574,14 +556,8 @@ def func2(a):
574
556
575
557
w1 .config ['execution' ]['crashdump_dir' ] = wd
576
558
# generate outputs
577
- error_raised = False
578
- try :
579
- w1 .run (plugin = 'Linear' )
580
- except Exception as e :
581
- from nipype .pipeline .engine .base import logger
582
- logger .info ('Exception: %s' % str (e ))
583
- error_raised = True
584
- assert not error_raised
559
+
560
+ w1 .run (plugin = 'Linear' )
585
561
586
562
587
563
def test_mapnode_json (tmpdir ):
@@ -618,13 +594,9 @@ def func1(in1):
618
594
with open (os .path .join (node .output_dir (), 'test.json' ), 'wt' ) as fp :
619
595
fp .write ('dummy file' )
620
596
w1 .config ['execution' ].update (** {'stop_on_first_rerun' : True })
621
- error_raised = False
622
- try :
623
- w1 .run ()
624
- except :
625
- error_raised = True
626
- assert not error_raised
627
597
598
+ w1 .run ()
599
+
628
600
629
601
def test_parameterize_dirs_false (tmpdir ):
630
602
from ....interfaces .utility import IdentityInterface
@@ -643,14 +615,8 @@ def test_parameterize_dirs_false(tmpdir):
643
615
wf .config ['execution' ]['parameterize_dirs' ] = False
644
616
wf .connect ([(n1 , n2 , [('output1' , 'in1' )])])
645
617
646
- error_raised = False
647
- try :
648
- wf .run ()
649
- except TypeError as typerr :
650
- from nipype .pipeline .engine .base import logger
651
- logger .info ('Exception: %s' % str (typerr ))
652
- error_raised = True
653
- assert not error_raised
618
+
619
+ wf .run ()
654
620
655
621
656
622
def test_serial_input (tmpdir ):
@@ -694,16 +660,8 @@ def func1(in1):
694
660
assert n1 .num_subnodes () == 1
695
661
696
662
# test running the workflow on serial conditions
697
- error_raised = False
698
- try :
699
- w1 .run (plugin = 'MultiProc' )
700
- except Exception as e :
701
- from nipype .pipeline .engine .base import logger
702
- logger .info ('Exception: %s' % str (e ))
703
- error_raised = True
704
-
705
- assert not error_raised
706
-
663
+ w1 .run (plugin = 'MultiProc' )
664
+
707
665
708
666
def test_write_graph_runs (tmpdir ):
709
667
os .chdir (str (tmpdir ))
0 commit comments