Skip to content

Commit 013bdad

Browse files
committed
fix:test & fix bug using aux functions in connect
1 parent 70f4f7f commit 013bdad

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

nipype/interfaces/tests/test_utility.py

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ def increment_array(in_array):
6363
f2 = pe.MapNode(utility.Function(input_names=['in_array'], output_names=['out_array'], function=increment_array), name='increment_array', iterfield=['in_array'])
6464

6565
wf.connect(f1, 'random_array', f2, 'in_array')
66-
6766
wf.run()
6867

6968
# Clean up
@@ -167,3 +166,57 @@ def test_csvReader():
167166
yield assert_equal, out.outputs.column_1, ['hello', 'world', 'goodbye']
168167
yield assert_equal, out.outputs.column_2, ['300.1', '5', '0.3']
169168
os.unlink(name)
169+
170+
171+
def test_aux_connect_function():
172+
""" This tests excution nodes with multiple inputs and auxiliary
173+
function inside the Workflow connect function.
174+
"""
175+
tempdir = os.path.realpath(mkdtemp())
176+
origdir = os.getcwd()
177+
os.chdir(tempdir)
178+
179+
wf = pe.Workflow(name="test_workflow")
180+
181+
def _gen_tuple(size):
182+
return [1, ] * size
183+
184+
def _sum_and_sub_mul(a, b, c):
185+
return (a+b)*c, (a-b)*c
186+
187+
def _inc(x):
188+
return x + 1
189+
190+
params = pe.Node(utility.IdentityInterface(fields=['size', 'num']), name='params')
191+
params.inputs.num = 42
192+
params.inputs.size = 1
193+
194+
gen_tuple = pe.Node(utility.Function(input_names=['size'],
195+
output_names=['tuple'],
196+
function=_gen_tuple),
197+
name='gen_tuple')
198+
199+
ssm = pe.Node(utility.Function(input_names=['a', 'b', 'c'],
200+
output_names=['sum', 'sub'],
201+
function=_sum_and_sub_mul),
202+
name='sum_and_sub_mul')
203+
204+
split = pe.Node(utility.Split(splits=[1, 1],
205+
squeeze=True),
206+
name='split')
207+
208+
209+
wf.connect([
210+
(params, gen_tuple, [(("size", _inc), "size")]),
211+
(params, ssm, [(("num", _inc), "c")]),
212+
(gen_tuple, split, [("tuple", "inlist")]),
213+
(split, ssm, [(("out1", _inc), "a"),
214+
("out2", "b"),
215+
]),
216+
])
217+
218+
wf.run()
219+
220+
# Clean up
221+
os.chdir(origdir)
222+
shutil.rmtree(tempdir)

nipype/pipeline/engine/workflows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def _configure_exec_nodes(self, graph):
690690
node.input_source = {}
691691
for edge in graph.in_edges_iter(node):
692692
data = graph.get_edge_data(*edge)
693-
for sourceinfo, field in sorted(data['connect']):
693+
for sourceinfo, field in data['connect']:
694694
node.input_source[field] = \
695695
(op.join(edge[0].output_dir(),
696696
'result_%s.pklz' % edge[0].name),

0 commit comments

Comments
 (0)