本文整理汇总了Python中nipype.testing.assert_equal函数的典型用法代码示例。如果您正苦于以下问题:Python assert_equal函数的具体用法?Python assert_equal怎么用?Python assert_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了assert_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mlab_init
def test_mlab_init():
yield assert_equal(mlab.MatlabCommand._cmd, 'matlab')
yield assert_equal(mlab.MatlabCommand.input_spec, mlab.MatlabInputSpec)
yield assert_equal(mlab.MatlabCommand().cmd, matlab_cmd)
mc = mlab.MatlabCommand(matlab_cmd='foo_m')
yield assert_equal(mc.cmd, 'foo_m')
示例2: test_unique_join_node
def test_unique_join_node():
"""Test join with the ``unique`` flag set to True."""
global _sum_operands
_sum_operands = []
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
# Make the workflow.
wf = pe.Workflow(name='test')
# the iterated input node
inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec')
inputspec.iterables = [('n', [3, 1, 2, 1, 3])]
# a pre-join node in the iterated path
pre_join1 = pe.Node(IncrementInterface(), name='pre_join1')
wf.connect(inputspec, 'n', pre_join1, 'input1')
# the set join node
join = pe.JoinNode(SumInterface(), joinsource='inputspec',
joinfield='input1', unique=True, name='join')
wf.connect(pre_join1, 'output1', join, 'input1')
wf.run()
assert_equal(_sum_operands[0], [4, 2, 3],
"The unique join output value is incorrect: %s." % _sum_operands[0])
os.chdir(cwd)
rmtree(wd)
示例3: test_set_join_node
def test_set_join_node():
"""Test collecting join inputs to a set."""
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
# Make the workflow.
wf = pe.Workflow(name='test')
# the iterated input node
inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec')
inputspec.iterables = [('n', [1, 2, 1, 3, 2])]
# a pre-join node in the iterated path
pre_join1 = pe.Node(IncrementInterface(), name='pre_join1')
wf.connect(inputspec, 'n', pre_join1, 'input1')
# the set join node
join = pe.JoinNode(SetInterface(), joinsource='inputspec',
joinfield='input1', name='join')
wf.connect(pre_join1, 'output1', join, 'input1')
wf.run()
# the join length is the number of unique inputs
assert_equal(_set_len, 3,
"The join Set output value is incorrect: %s." % _set_len)
os.chdir(cwd)
rmtree(wd)
示例4: _run_interface
def _run_interface(self, runtime):
data1 = nb.load(self.inputs.volume1).get_data()
data2 = nb.load(self.inputs.volume2).get_data()
assert_equal(data1, data2)
return runtime
示例5: test1
def test1():
pipe = pe.Workflow(name='pipe')
mod1 = pe.Node(interface=TestInterface(),name='mod1')
pipe.add_nodes([mod1])
pipe._create_flat_graph()
pipe._execgraph = pe._generate_expanded_graph(deepcopy(pipe._flatgraph))
yield assert_equal(len(pipe._execgraph.nodes()), 1)
yield assert_equal(len(pipe._execgraph.edges()), 0)
示例6: test2
def test2():
pipe = pe.Workflow(name='pipe')
mod1 = pe.Node(interface=TestInterface(),name='mod1')
mod1.iterables = dict(input1=lambda:[1,2],input2=lambda:[1,2])
pipe.add_nodes([mod1])
pipe._create_flat_graph()
pipe._execgraph = pe._generate_expanded_graph(deepcopy(pipe._flatgraph))
yield assert_equal(len(pipe._execgraph.nodes()), 4)
yield assert_equal(len(pipe._execgraph.edges()), 0)
示例7: test_multiple_join_nodes
def test_multiple_join_nodes():
"""Test two join nodes, one downstream of the other."""
global _products
_products = []
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
# Make the workflow.
wf = pe.Workflow(name='test')
# the iterated input node
inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec')
inputspec.iterables = [('n', [1, 2, 3])]
# a pre-join node in the iterated path
pre_join1 = pe.Node(IncrementInterface(), name='pre_join1')
wf.connect(inputspec, 'n', pre_join1, 'input1')
# the first join node
join1 = pe.JoinNode(IdentityInterface(fields=['vector']),
joinsource='inputspec', joinfield='vector',
name='join1')
wf.connect(pre_join1, 'output1', join1, 'vector')
# an uniterated post-join node
post_join1 = pe.Node(SumInterface(), name='post_join1')
wf.connect(join1, 'vector', post_join1, 'input1')
# the downstream join node connected to both an upstream join
# path output and a separate input in the iterated path
join2 = pe.JoinNode(IdentityInterface(fields=['vector', 'scalar']),
joinsource='inputspec', joinfield='vector',
name='join2')
wf.connect(pre_join1, 'output1', join2, 'vector')
wf.connect(post_join1, 'output1', join2, 'scalar')
# a second post-join node
post_join2 = pe.Node(SumInterface(), name='post_join2')
wf.connect(join2, 'vector', post_join2, 'input1')
# a third post-join node
post_join3 = pe.Node(ProductInterface(), name='post_join3')
wf.connect(post_join2, 'output1', post_join3, 'input1')
wf.connect(join2, 'scalar', post_join3, 'input2')
result = wf.run()
# The expanded graph contains one pre_join1 replicate per inputspec
# replicate and one of each remaining node = 3 + 5 = 8 nodes.
# The replicated inputspec nodes are factored out of the expansion.
assert_equal(len(result.nodes()), 8,
"The number of expanded nodes is incorrect.")
# The outputs are:
# pre_join1: [2, 3, 4]
# post_join1: 9
# join2: [2, 3, 4] and 9
# post_join2: 9
# post_join3: 9 * 9 = 81
assert_equal(_products, [81], "The post-join product is incorrect")
os.chdir(cwd)
rmtree(wd)
示例8: test_itersource_join_source_node
def test_itersource_join_source_node():
"""Test join on an input node which has an ``itersource``."""
cwd = os.getcwd()
wd = mkdtemp()
os.chdir(wd)
# Make the workflow.
wf = pe.Workflow(name='test')
# the iterated input node
inputspec = pe.Node(IdentityInterface(fields=['n']), name='inputspec')
inputspec.iterables = [('n', [1, 2])]
# an intermediate node in the first iteration path
pre_join1 = pe.Node(IncrementInterface(), name='pre_join1')
wf.connect(inputspec, 'n', pre_join1, 'input1')
# an iterable pre-join node with an itersource
pre_join2 = pe.Node(ProductInterface(), name='pre_join2')
pre_join2.itersource = ('inputspec', 'n')
pre_join2.iterables = ('input1', {1: [3, 4], 2: [5, 6]})
wf.connect(pre_join1, 'output1', pre_join2, 'input2')
# an intermediate node in the second iteration path
pre_join3 = pe.Node(IncrementInterface(), name='pre_join3')
wf.connect(pre_join2, 'output1', pre_join3, 'input1')
# the join node
join = pe.JoinNode(IdentityInterface(fields=['vector']),
joinsource='pre_join2', joinfield='vector', name='join')
wf.connect(pre_join3, 'output1', join, 'vector')
# a join successor node
post_join1 = pe.Node(SumInterface(), name='post_join1')
wf.connect(join, 'vector', post_join1, 'input1')
result = wf.run()
# the expanded graph contains
# 1 pre_join1 replicate for each inputspec iteration,
# 2 pre_join2 replicates for each inputspec iteration,
# 1 pre_join3 for each pre_join2 iteration,
# 1 join replicate for each inputspec iteration and
# 1 post_join1 replicate for each join replicate =
# 2 + (2 * 2) + 4 + 2 + 2 = 14 expansion graph nodes.
# Nipype factors away the iterable input
# IdentityInterface but keeps the join IdentityInterface.
assert_equal(len(result.nodes()), 14,
"The number of expanded nodes is incorrect.")
# The first join inputs are:
# 1 + (3 * 2) and 1 + (4 * 2)
# The second join inputs are:
# 1 + (5 * 3) and 1 + (6 * 3)
# the post-join nodes execution order is indeterminate;
# therefore, compare the lists item-wise.
assert_true([16, 19] in _sum_operands,
"The join Sum input is incorrect: %s." % _sum_operands)
assert_true([7, 9] in _sum_operands,
"The join Sum input is incorrect: %s." % _sum_operands)
os.chdir(cwd)
rmtree(wd)
示例9: test_split_filename
def test_split_filename():
res = split_filename('foo.nii')
yield assert_equal(res, ('', 'foo', '.nii'))
res = split_filename('foo.nii.gz')
yield assert_equal(res, ('', 'foo', '.nii.gz'))
res = split_filename('/usr/local/foo.nii.gz')
yield assert_equal(res, ('/usr/local', 'foo', '.nii.gz'))
res = split_filename('../usr/local/foo.nii')
yield assert_equal(res, ('../usr/local', 'foo', '.nii'))
res = split_filename('/usr/local/foo.a.b.c.d')
yield assert_equal(res, ('/usr/local', 'foo', '.a.b.c.d'))
示例10: test_callback_multiproc_normal
def test_callback_multiproc_normal():
so = Status()
wf = pe.Workflow(name='test', base_dir='/tmp')
f_node = pe.Node(niu.Function(function=func, input_names=[], output_names=[]), name='f_node')
wf.add_nodes([f_node])
wf.run(plugin='MultiProc', plugin_args={'status_callback': so.callback})
assert_equal(len(so.statuses), 2)
for (n, s) in so.statuses:
yield assert_equal, n.name, 'f_node'
yield assert_equal, so.statuses[0][1], 'start'
yield assert_equal, so.statuses[1][1], 'end'
示例11: test5
def test5():
pipe = pe.Workflow(name='pipe')
mod1 = pe.Node(interface=TestInterface(),name='mod1')
mod2 = pe.Node(interface=TestInterface(),name='mod2')
mod1.iterables = dict(input1=lambda:[1,2])
mod2.iterables = dict(input1=lambda:[1,2])
pipe.connect([(mod1,mod2,[('output1','input2')])])
pipe._create_flat_graph()
pipe._execgraph = pe._generate_expanded_graph(deepcopy(pipe._flatgraph))
yield assert_equal(len(pipe._execgraph.nodes()), 6)
yield assert_equal(len(pipe._execgraph.edges()), 4)
示例12: test_generate_dependency_list
def test_generate_dependency_list():
pipe = pe.Workflow(name='pipe')
mod1 = pe.Node(interface=TestInterface(),name='mod1')
mod2 = pe.Node(interface=TestInterface(),name='mod2')
pipe.connect([(mod1,mod2,[('output1','input1')])])
pipe._create_flat_graph()
pipe._execgraph = pe._generate_expanded_graph(deepcopy(pipe._flatgraph))
pipe._generate_dependency_list()
yield assert_false(pipe._execgraph == None)
yield assert_equal(len(pipe.procs), 2)
yield assert_false(pipe.proc_done[1])
yield assert_false(pipe.proc_pending[1])
yield assert_equal(pipe.depidx[0,1], 1)
示例13: test_cmdline
def test_cmdline():
basedir = mkdtemp()
mi = mlab.MatlabCommand(script='whos',
script_file='testscript')
yield assert_equal(mi.cmdline, \
matlab_cmd + ' -nodesktop -nosplash -singleCompThread -r "fprintf(1,\'Executing code at %s:\\n\',datestr(now));ver,try,whos,catch ME,ME,ME.stack,fprintf(\'%s\\n\',ME.message);fprintf(2,\'<MatlabScriptException>\');fprintf(2,\'%s\\n\',ME.message);fprintf(2,\'File:%s\\nName:%s\\nLine:%d\\n\',ME.stack.file,ME.stack.name,ME.stack.line);fprintf(2,\'</MatlabScriptException>\');end;;exit"')
yield assert_equal(mi.inputs.script, 'whos')
yield assert_equal(mi.inputs.script_file, 'testscript')
path_exists = os.path.exists(os.path.join(basedir,'testscript.m'))
yield assert_false(path_exists)
rmtree(basedir)
示例14: test_callback_exception
def test_callback_exception():
so = Status()
wf = pe.Workflow(name='test', base_dir='/tmp')
f_node = pe.Node(niu.Function(function=bad_func, input_names=[], output_names=[]), name='f_node')
wf.add_nodes([f_node])
try:
wf.run(plugin_args={'status_callback': so.callback})
except:
pass
assert_equal(len(so.statuses), 2)
for (n, s) in so.statuses:
yield assert_equal, n.name, 'f_node'
yield assert_equal, so.statuses[0][1], 'start'
yield assert_equal, so.statuses[1][1], 'exception'
示例15: test_run_interface
def test_run_interface():
mc = mlab.MatlabCommand(matlab_cmd='foo_m')
yield assert_raises(ValueError, mc.run) # script is mandatory
mc.inputs.script = 'a=1;'
yield assert_raises(IOError, mc.run) # foo_m is not an executable
cwd = os.getcwd()
basedir = mkdtemp()
os.chdir(basedir)
res = mlab.MatlabCommand(script='foo', paths=[basedir], mfile=True).run() # bypasses ubuntu dash issue
yield assert_equal(res.runtime.returncode, 1)
res = mlab.MatlabCommand(script='a=1;', paths=[basedir], mfile=True).run() # bypasses ubuntu dash issue
yield assert_equal(res.runtime.returncode, 0)
os.chdir(cwd)
rmtree(basedir)