3
Yds                 @   s`   d dl Z d dlZd dlmZ d dljjZdZdd Z	dd Z
dd	 Zd
d Zdd Zdd ZdS )    N)utilityzdef concat_sort(in_arrays):
    import numpy as np
    all_vals = np.concatenate([arr.flatten() for arr in in_arrays])
    return np.sort(all_vals)
c             C   s   | j   dd }tjtjdgdg|dddgd}ddd	g|j_tjd
d}dd }tjtj|dddgd}|j|d|d tj	tjt
ddd}|j|d|d |j  d S )Nc             S   s   dd l }|jj| | S )Nr   )ZnumpyrandomZrand)sizenp r   _/var/www/html/virt/lib/python3.6/site-packages/nipype/interfaces/utility/tests/test_wrappers.pygen_random_array   s    z'test_function.<locals>.gen_random_arrayr   random_array)input_namesoutput_namesfunction)nameZ	iterfield         test_workflow)r   c             S   s   | d S )N   r   )in_arrayr   r   r   increment_array'   s    z&test_function.<locals>.increment_array)r   r   r   concat_sortoutZ	in_arrays)chdirpeZMapNoder   Functioninputsr   WorkflowconnectNoder   run)tmpdirr   f1wfr   f2Zf3r   r   r   test_function   s(    


r#   c             C   s   t jj| | S )N)r   r   Zrandn)r   r   r   r   make_random_array8   s    r$   c             C   s:   | j   tjtjdgdgtddd}d|j_|j  d S )Nr   r	   )r
   r   r   should_fail)r   
   )	r   r   r   r   r   r$   r   r   r   )tmpnoder   r   r   r%   <   s    r%   c          	   C   s&   t jtjj t|  W d Q R X d S )N)pytestZraisesr   ZnodesZNodeExecutionErrorr%   )r   r   r   r   test_should_failK   s    r*   c             C   sJ   | j   tjtjdgdgtdgddd}t|jj d|j_	|j
  d S )Nr   r	   zimport numpy as np)r
   r   r   ZimportsZshould_not_fail)r   r&   )r   r   r   r   r   r$   printr   Zfunction_strr   r   )r   r(   r   r   r   test_function_with_importsP   s    r,   c       	   	   C   s  | j   tjdd}dd }dd }dd }tjtjd	d
gddd}d|j_d|j_tjtj	d	gdg|ddd}tjtj	dddgddg|ddd}tjtj
ddgdddd}|j||d	|fd	fgf||d
|fdfgf||dgf||d|fdfd gfg |j  dS )!ztThis tests excution nodes with multiple inputs and auxiliary
    function inside the Workflow connect function.
    r   )r   c             S   s
   dg|  S )Nr   r   )r   r   r   r   
_gen_tuplei   s    z-test_aux_connect_function.<locals>._gen_tuplec             S   s   | | | | | | fS )Nr   )abcr   r   r   _sum_and_sub_mull   s    z3test_aux_connect_function.<locals>._sum_and_sub_mulc             S   s   | d S )Nr   r   )xr   r   r   _inco   s    z'test_aux_connect_function.<locals>._incr   num)fieldsparams*   r   tuple)r
   r   r   	gen_tupler.   r/   r0   sumsubZsum_and_sub_mulT)splitsZsqueezesplitinlistZout1out2N)r8   r>   )r?   r/   )r   r   r   r   r   ZIdentityInterfacer   r4   r   r   ZSplitr   r   )	r   r!   r-   r1   r3   r6   r9   Zssmr=   r   r   r   test_aux_connect_functiona   s2    
r@   )osr)   Znipype.interfacesr   Znipype.pipeline.engineZpipelineZenginer   r   r#   r$   r%   r*   r,   r@   r   r   r   r   <module>   s   &