Skip to content

Commit 1f61aa2

Browse files
committed
simplyfying tests, removing some try/except blocks
1 parent 7b5201d commit 1f61aa2

File tree

1 file changed

+19
-61
lines changed

1 file changed

+19
-61
lines changed

nipype/pipeline/engine/tests/test_engine.py

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,8 @@ def test_expansion():
156156
pipe5.add_nodes([pipe4])
157157
pipe6 = pe.Workflow(name="pipe6")
158158
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()
165161

166162

167163
def test_iterable_expansion():
@@ -479,14 +475,9 @@ def func1(in1):
479475
nested=False,
480476
name='n1')
481477
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+
490481

491482

492483
def test_node_hash(tmpdir):
@@ -518,35 +509,26 @@ def func2(a):
518509
w1.config['execution'] = {'stop_on_first_crash': 'true',
519510
'local_hash_check': 'false',
520511
'crashdump_dir': wd}
521-
error_raised = False
522512
# create dummy distributed plugin class
523513
from nipype.pipeline.plugins.base import DistributedPluginBase
524514

525515
class RaiseError(DistributedPluginBase):
526516
def _submit_job(self, node, updatehash=False):
527517
raise Exception('Submit called')
528-
try:
518+
519+
with pytest.raises(Exception) as excinfo:
529520
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+
535523
# rerun to ensure we have outputs
536524
w1.run(plugin='Linear')
537525
# set local check
538526
w1.config['execution'] = {'stop_on_first_crash': 'true',
539527
'local_hash_check': 'true',
540528
'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
549529

530+
w1.run(plugin=RaiseError())
531+
550532

551533
def test_old_config(tmpdir):
552534
wd = str(tmpdir)
@@ -574,14 +556,8 @@ def func2(a):
574556

575557
w1.config['execution']['crashdump_dir'] = wd
576558
# 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')
585561

586562

587563
def test_mapnode_json(tmpdir):
@@ -618,13 +594,9 @@ def func1(in1):
618594
with open(os.path.join(node.output_dir(), 'test.json'), 'wt') as fp:
619595
fp.write('dummy file')
620596
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
627597

598+
w1.run()
599+
628600

629601
def test_parameterize_dirs_false(tmpdir):
630602
from ....interfaces.utility import IdentityInterface
@@ -643,14 +615,8 @@ def test_parameterize_dirs_false(tmpdir):
643615
wf.config['execution']['parameterize_dirs'] = False
644616
wf.connect([(n1, n2, [('output1', 'in1')])])
645617

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()
654620

655621

656622
def test_serial_input(tmpdir):
@@ -694,16 +660,8 @@ def func1(in1):
694660
assert n1.num_subnodes() == 1
695661

696662
# 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+
707665

708666
def test_write_graph_runs(tmpdir):
709667
os.chdir(str(tmpdir))

0 commit comments

Comments
 (0)