Skip to content

Commit 4ca0812

Browse files
committed
TEST: new tests for Function interface updates
1 parent b000645 commit 4ca0812

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

nipype/interfaces/tests/test_utility.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import shutil
55
from tempfile import mkdtemp
66

7-
from nipype.testing import assert_equal, assert_true
7+
import numpy as np
8+
from nipype.testing import assert_equal, assert_true, assert_raises
89
from nipype.interfaces import utility
910
import nipype.pipeline.engine as pe
1011

@@ -66,3 +67,49 @@ def increment_array(in_array):
6667
# Clean up
6768
os.chdir(origdir)
6869
shutil.rmtree(tempdir)
70+
71+
72+
def make_random_array(size):
73+
74+
return np.random.randn(size, size)
75+
76+
77+
def should_fail():
78+
79+
tempdir = os.path.realpath(mkdtemp())
80+
origdir = os.getcwd()
81+
os.chdir(tempdir)
82+
83+
node = pe.Node(utility.Function(input_names=["size"],
84+
output_names=["random_array"],
85+
function=make_random_array),
86+
name="should_fail")
87+
try:
88+
node.inputs.size = 10
89+
node.run()
90+
finally:
91+
os.chdir(origdir)
92+
shutil.rmtree(tempdir)
93+
94+
95+
assert_raises(NameError, should_fail)
96+
97+
98+
def test_function_with_imports():
99+
100+
tempdir = os.path.realpath(mkdtemp())
101+
origdir = os.getcwd()
102+
os.chdir(tempdir)
103+
104+
node = pe.Node(utility.Function(input_names=["size"],
105+
output_names=["random_array"],
106+
function=make_random_array,
107+
imports=["import numpy as np"]),
108+
name="should_not_fail")
109+
print node.inputs.function_str
110+
try:
111+
node.inputs.size = 10
112+
node.run()
113+
finally:
114+
os.chdir(origdir)
115+
shutil.rmtree(tempdir)

0 commit comments

Comments
 (0)