|
3 | 3 | """Tests for the engine module
|
4 | 4 | """
|
5 | 5 | from copy import deepcopy
|
| 6 | +from glob import glob |
6 | 7 | import os
|
7 | 8 | from shutil import rmtree
|
8 | 9 | from tempfile import mkdtemp
|
|
13 | 14 | assert_false)
|
14 | 15 | import nipype.interfaces.base as nib
|
15 | 16 | import nipype.pipeline.engine as pe
|
| 17 | +from nipype import logging |
16 | 18 |
|
17 | 19 | class InputSpec(nib.TraitedSpec):
|
18 | 20 | input1 = nib.traits.Int(desc='a random int')
|
@@ -439,3 +441,47 @@ def func2(a):
|
439 | 441 | yield assert_false, error_raised
|
440 | 442 | os.chdir(cwd)
|
441 | 443 | rmtree(wd)
|
| 444 | + |
| 445 | + |
| 446 | +def test_mapnode_json(): |
| 447 | + """Tests that mapnodes don't generate excess jsons |
| 448 | + """ |
| 449 | + cwd = os.getcwd() |
| 450 | + wd = mkdtemp() |
| 451 | + os.chdir(wd) |
| 452 | + from nipype import MapNode, Function, Workflow |
| 453 | + def func1(in1): |
| 454 | + return in1 + 1 |
| 455 | + n1 = MapNode(Function(input_names=['in1'], |
| 456 | + output_names=['out'], |
| 457 | + function=func1), |
| 458 | + iterfield=['in1'], |
| 459 | + name='n1') |
| 460 | + n1.inputs.in1 = [1] |
| 461 | + w1 = Workflow(name='test') |
| 462 | + w1.base_dir = wd |
| 463 | + w1.config = {'crashdump_dir': wd} |
| 464 | + w1.add_nodes([n1]) |
| 465 | + w1.run() |
| 466 | + n1.inputs.in1 = [2] |
| 467 | + w1.run() |
| 468 | + # should rerun |
| 469 | + n1.inputs.in1 = [1] |
| 470 | + eg = w1.run() |
| 471 | + |
| 472 | + node = eg.nodes()[0] |
| 473 | + outjson = glob(os.path.join(node.output_dir(), '_0x*.json')) |
| 474 | + yield assert_equal, len(outjson), 1 |
| 475 | + |
| 476 | + # check that multiple json's don't trigger rerun |
| 477 | + with open(os.path.join(node.output_dir(), 'test.json'), 'wt') as fp: |
| 478 | + fp.write('dummy file') |
| 479 | + w1.config['execution'].update(**{'stop_on_first_rerun': True}) |
| 480 | + error_raised = False |
| 481 | + try: |
| 482 | + w1.run() |
| 483 | + except: |
| 484 | + error_raised = True |
| 485 | + yield assert_false, error_raised |
| 486 | + os.chdir(cwd) |
| 487 | + rmtree(wd) |
0 commit comments