Skip to content

Commit d630887

Browse files
FredLoneysatra
FredLoney
authored andcommitted
Test the alternate itersource iterables format.
1 parent 5f4a764 commit d630887

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

nipype/pipeline/tests/test_engine.py

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ def test_synchronize_expansion():
211211
import nipype.pipeline.engine as pe
212212
wf1 = pe.Workflow(name='test')
213213
node1 = pe.Node(TestInterface(),name='node1')
214-
node2 = pe.Node(TestInterface(),name='node2')
215214
node1.iterables = [('input1',[1,2]),('input2',[3,4,5])]
216215
node1.synchronize = True
216+
node2 = pe.Node(TestInterface(),name='node2')
217217
wf1.connect(node1,'output1', node2, 'input2')
218218
wf3 = pe.Workflow(name='group')
219219
for i in [0,1,2]:
@@ -226,18 +226,33 @@ def test_synchronize_expansion():
226226
# => 18 nodes in the group
227227
yield assert_equal, len(pe.generate_expanded_graph(wf3._flatgraph).nodes()), 18
228228

229-
def test_itersource_expansion():
229+
def test_synchronize_tuples_expansion():
230230
import nipype.pipeline.engine as pe
231231
wf1 = pe.Workflow(name='test')
232232
node1 = pe.Node(TestInterface(),name='node1')
233233
node2 = pe.Node(TestInterface(),name='node2')
234-
node3 = pe.Node(TestInterface(),name='node3')
234+
node1.iterables = [('input1','input2'), [(1,3), (2,4), (None,5)]]
235+
node1.synchronize = True
236+
wf1.connect(node1,'output1', node2, 'input2')
237+
wf3 = pe.Workflow(name='group')
238+
for i in [0,1,2]:
239+
wf3.add_nodes([wf1.clone(name='test%d'%i)])
240+
wf3._flatgraph = wf3._create_flat_graph()
241+
# Identical to test_synchronize_expansion
242+
yield assert_equal, len(pe.generate_expanded_graph(wf3._flatgraph).nodes()), 18
243+
244+
def test_itersource_expansion():
245+
import nipype.pipeline.engine as pe
246+
wf1 = pe.Workflow(name='test')
247+
node1 = pe.Node(TestInterface(),name='node1')
235248
node1.iterables = ('input1',[1,2])
236-
node3.itersource = 'node1'
237-
node3.iterables = [('input1',{1:[3,4], 2:[5,6,7]}), ('input2',{1:[6,7]})]
238-
node4 = pe.Node(TestInterface(),name='node4')
249+
node2 = pe.Node(TestInterface(),name='node2')
239250
wf1.connect(node1,'output1', node2, 'input1')
251+
node3 = pe.Node(TestInterface(),name='node3')
252+
node3.itersource = ('node1', 'input1')
253+
node3.iterables = [('input1', {1:[3,4], 2:[5,6,7]})]
240254
wf1.connect(node2,'output1', node3, 'input1')
255+
node4 = pe.Node(TestInterface(),name='node4')
241256
wf1.connect(node3,'output1', node4, 'input1')
242257
wf3 = pe.Workflow(name='group')
243258
for i in [0,1,2]:
@@ -246,13 +261,13 @@ def test_itersource_expansion():
246261

247262
# each expanded graph clone has:
248263
# 2 node1 expansion nodes,
249-
# 2 node2 successors,
250-
# 2 * 2 node3 replicates for the node1 input1 value 1 replicate,
251-
# 3 node3 replicates for the node1 input1 value 2 replicate and
264+
# 1 node2 per node1 replicate,
265+
# 2 node3 replicates for the node1 input1 value 1,
266+
# 3 node3 replicates for the node1 input1 value 2 and
252267
# 1 node4 successor per node3 replicate
253-
# => 2 + 2 + (4 + 3) + 7 = 24 nodes per expanded graph clone
254-
# => 3 * 18 = 54 nodes in the group
255-
yield assert_equal, len(pe.generate_expanded_graph(wf3._flatgraph).nodes()), 54
268+
# => 2 + 2 + (2 + 3) + 5 = 14 nodes per expanded graph clone
269+
# => 3 * 14 = 42 nodes in the group
270+
yield assert_equal, len(pe.generate_expanded_graph(wf3._flatgraph).nodes()), 42
256271

257272
def test_disconnect():
258273
import nipype.pipeline.engine as pe

0 commit comments

Comments
 (0)