Skip to content

Commit 0a55595

Browse files
committed
A test case for output removal
1 parent 626b3f4 commit 0a55595

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

nipype/pipeline/tests/test_utils.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,99 @@ def test_function(arg1):
8686
'file2.txt'))
8787
rmtree(out_dir)
8888

89+
90+
def test_outputs_removal_wf():
91+
92+
def test_function(arg1):
93+
import os
94+
file1 = os.path.join(os.getcwd(), 'file1.txt')
95+
file2 = os.path.join(os.getcwd(), 'file2.txt')
96+
fp = open(file1, 'wt')
97+
fp.write('%d' % arg1)
98+
fp.close()
99+
fp = open(file2, 'wt')
100+
fp.write('%d' % arg1)
101+
fp.close()
102+
return file1, file2
103+
104+
def test_function2(in_file, arg):
105+
import os
106+
in_arg = open(in_file).read()
107+
file1 = os.path.join(os.getcwd(), 'file1.txt')
108+
file2 = os.path.join(os.getcwd(), 'file2.txt')
109+
fp = open(file1, 'wt')
110+
fp.write('%d' % arg + in_arg)
111+
fp.close()
112+
fp = open(file2, 'wt')
113+
fp.write('%d' % arg + in_arg)
114+
fp.close()
115+
return file1, file2, 1
116+
117+
def test_function3(arg):
118+
import os
119+
return arg
120+
121+
out_dir = mkdtemp()
122+
123+
for plugin in ('Linear', 'MultiProc'):
124+
n1 = pe.Node(niu.Function(input_names=['arg1'],
125+
output_names=['out_file1', 'out_file2'],
126+
function=test_function),
127+
name='n1')
128+
n1.inputs.arg1 = 1
129+
130+
n2 = pe.Node(niu.Function(input_names=['in_file', 'arg'],
131+
output_names=['out_file1', 'out_file2', 'n'],
132+
function=test_function2),
133+
name='n2')
134+
n2.inputs.arg = 2
135+
136+
n3 = pe.Node(niu.Function(input_names=['arg'],
137+
output_names=['n'],
138+
function=test_function3),
139+
name='n3')
140+
141+
wf = pe.Workflow(name="node_rem_test" + plugin, base_dir=out_dir)
142+
wf.connect(n1, "out_file1", n2, "in_file")
143+
144+
for remove_unnecessary_outputs in [True, False]:
145+
wf.config = {'execution': {'remove_unnecessary_outputs': remove_unnecessary_outputs}}
146+
wf.config = merge_dict(deepcopy(config._sections), wf.config)
147+
wf.run(plugin=plugin)
148+
149+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
150+
wf.name,
151+
n1.name,
152+
'file2.txt')) != remove_unnecessary_outputs
153+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
154+
wf.name,
155+
n1.name,
156+
'file1.txt'))
157+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
158+
wf.name,
159+
n2.name,
160+
'file1.txt'))
161+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
162+
wf.name,
163+
n2.name,
164+
'file2.txt'))
165+
wf.connect(n2, "n", n3, "arg")
166+
for remove_unnecessary_outputs in [True, False]:
167+
wf.config = {'execution': {'remove_unnecessary_outputs': remove_unnecessary_outputs}}
168+
wf.config = merge_dict(deepcopy(config._sections), wf.config)
169+
wf.run(plugin=plugin)
170+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
171+
wf.name,
172+
n2.name,
173+
'file1.txt')) != remove_unnecessary_outputs
174+
yield assert_true, os.path.exists(os.path.join(wf.base_dir,
175+
wf.name,
176+
n2.name,
177+
'file2.txt')) != remove_unnecessary_outputs
178+
179+
rmtree(out_dir)
180+
181+
89182
class InputSpec(nib.TraitedSpec):
90183
in_file = nib.File(exists=True, copyfile=True)
91184

0 commit comments

Comments
 (0)