|
| 1 | +import os |
| 2 | +from shutil import rmtree |
| 3 | +from tempfile import mkdtemp |
| 4 | + |
| 5 | +import nipype.interfaces.base as nib |
| 6 | +from nipype.testing import assert_equal, skipif |
| 7 | +import nipype.pipeline.engine as pe |
| 8 | + |
| 9 | + |
| 10 | +class InputSpec(nib.TraitedSpec): |
| 11 | + input1 = nib.traits.Int(desc='a random int') |
| 12 | + input2 = nib.traits.Int(desc='a random int') |
| 13 | + |
| 14 | + |
| 15 | +class OutputSpec(nib.TraitedSpec): |
| 16 | + output1 = nib.traits.List(nib.traits.Int, desc='outputs') |
| 17 | + |
| 18 | + |
| 19 | +class TestInterface(nib.BaseInterface): |
| 20 | + input_spec = InputSpec |
| 21 | + output_spec = OutputSpec |
| 22 | + |
| 23 | + def _run_interface(self, runtime): |
| 24 | + runtime.returncode = 0 |
| 25 | + return runtime |
| 26 | + |
| 27 | + def _list_outputs(self): |
| 28 | + outputs = self._outputs().get() |
| 29 | + outputs['output1'] = [1, self.inputs.input1] |
| 30 | + return outputs |
| 31 | + |
| 32 | + |
| 33 | +@skipif(False) |
| 34 | +def test_run_oargraph(): |
| 35 | + cur_dir = os.getcwd() |
| 36 | + temp_dir = mkdtemp(prefix='test_engine_') |
| 37 | + os.chdir(temp_dir) |
| 38 | + |
| 39 | + pipe = pe.Workflow(name='pipe') |
| 40 | + mod1 = pe.Node(interface=TestInterface(), name='mod1') |
| 41 | + mod2 = pe.MapNode(interface=TestInterface(), |
| 42 | + iterfield=['input1'], |
| 43 | + name='mod2') |
| 44 | + pipe.connect([(mod1, mod2, [('output1', 'input1')])]) |
| 45 | + pipe.base_dir = os.getcwd() |
| 46 | + mod1.inputs.input1 = 1 |
| 47 | + execgraph = pipe.run(plugin="OAR") |
| 48 | + names = [ |
| 49 | + '.'.join((node._hierarchy, node.name)) |
| 50 | + for node in execgraph.nodes() |
| 51 | + ] |
| 52 | + node = execgraph.nodes()[names.index('pipe.mod1')] |
| 53 | + result = node.get_output('output1') |
| 54 | + yield assert_equal, result, [1, 1] |
| 55 | + os.chdir(cur_dir) |
| 56 | + rmtree(temp_dir) |
0 commit comments