a
    LfU                     @   s   d dl Z d dlZd dlmZmZmZ d dlZd dlm	Z	 e j
jG dd de	jZG dd de	jZG dd	 d	e	jZG d
d de	jZG dd de	jZe j
jG dd de	jZe j
jG dd de	jZe j
jG dd de	jZdS )    N)assert_array_equalassert_equalassert_raises)utilc                7   @   s\  e Zd ZdZdZg dZdZeD ]ZeZe	dd
eeZeede de d	e d
e de de de d	e de de de de de de de de de de de de de de de de de d37 Zq ejdedd Zejdedd dd Zejdedd Zejded d! Zejded"d# ZdS )$TestCharacterString.f90Ztest_character_string13star (*))r   z

        subroutine _input_z(c, o, n)
          character*z, intent(in) :: c
          integer n
          !f2py integer, depend(c), intent(hide) :: n = slen(c)
          integer*1, dimension(n) :: o
          !f2py intent(out) o
          o = transfer(c, o)
        end subroutine _output_z, intent(out) :: c
          integer n
          integer*1, dimension(n), intent(in) :: o
          !f2py integer, depend(o), intent(hide) :: n = len(o)
          c = transfer(o, c)
        end subroutine _array_input_z;(c, o, m, n)
          integer m, i, n
          character*aH  , intent(in), dimension(m) :: c
          !f2py integer, depend(c), intent(hide) :: m = len(c)
          !f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c)
          integer*1, dimension(m, n), intent(out) :: o
          do i=1,m
            o(i, :) = transfer(c(i), o(i, :))
          end do
        end subroutine _array_output_z!(c, o, m, n)
          character*a  , intent(out), dimension(m) :: c
          integer n
          integer*1, dimension(m, n), intent(in) :: o
          !f2py character(f2py_len=n) :: c
          !f2py integer, depend(o), intent(hide) :: m = len(o)
          !f2py integer, depend(o), intent(hide) :: n = shape(o, 1)
          do i=1,m
            c(i) = transfer(o(i, :), c(i))
          end do
        end subroutine _2d_array_input_zH(c, o, m1, m2, n)
          integer m1, m2, i, j, n
          character*a  , intent(in), dimension(m1, m2) :: c
          !f2py integer, depend(c), intent(hide) :: m1 = len(c)
          !f2py integer, depend(c), intent(hide) :: m2 = shape(c, 1)
          !f2py integer, depend(c), intent(hide) :: n = f2py_itemsize(c)
          integer*1, dimension(m1, m2, n), intent(out) :: o
          do i=1,m1
            do j=1,m2
              o(i, j, :) = transfer(c(i, j), o(i, j, :))
            end do
          end do
        end subroutine z	
        lengthc                 C   s\   ddi ||}t| j| jd | }dddd| }t||tjttt	|dd	 d S )
Nr   r   r   aabcabcdeabcdeabcder   u1dtype)
getgetattrmodulefprefixr   nparraylistmapordselfr   fsuffixfr    r'   X/var/www/ai-form-bot/venv/lib/python3.9/site-packages/numpy/f2py/tests/test_character.py
test_inputM   s    zTestCharacterString.test_inputNc                 C   sR   |}t | j| jd | }ddd| }t|tjttt|dd|	  d S )Nr   r   r   )r	   r
   r   r   )
r   r   r   r   r   r   r    r!   r"   encoder#   r'   r'   r(   test_outputV   s    zTestCharacterString.test_outputc                 C   sn   |}t | j| jd | }tjdddd| dddd| gd	d
}tjdd |D dd
}t||| d S )Nr   r   r   r   r   AABCABCDEABCDEABCDESr   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   .0cr'   r'   r(   
<listcomp>i       zCTestCharacterString.test_array_input.<locals>.<listcomp>.<listcomp>r'   r2   sr'   r'   r(   r4   i   r5   z8TestCharacterString.test_array_input.<locals>.<listcomp>r   r   r   r   r   r   r   r$   r   r%   r&   r   expectedr'   r'   r(   test_array_input`   s    z$TestCharacterString.test_array_inputc                 C   sn   |}t | j| jd | }tjdddd| dddd| gd	d
}tjdd |D dd
}t||| d S )Nr   r   r   r   r   r-   r.   r/   r0   r   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   r1   r'   r'   r(   r4   u   r5   zDTestCharacterString.test_array_output.<locals>.<listcomp>.<listcomp>r'   r6   r'   r'   r(   r4   u   r5   z9TestCharacterString.test_array_output.<locals>.<listcomp>r   r8   )r$   r   r%   r&   r:   r   r'   r'   r(   test_array_outputl   s    z%TestCharacterString.test_array_outputc                 C   s   |}t | j| jd | }tjdddd| dddd| gd	d
dd| dddd| ggdd}tjdd |D ddd}t||| d S )Nr   r   r   r   r   r-   r.   r/   r&   ZfghZfghijfghijfghijFZFGHZFGHIJFGHIJFGHIJr0   r   c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}d d |D qS )c                 S   s   g | ]}|qS r'   r'   r1   r'   r'   r(   r4      r5   zQTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>.<listcomp>r'   )r2   itemr'   r'   r(   r4      r5   zFTestCharacterString.test_2d_array_input.<locals>.<listcomp>.<listcomp>r'   )r2   rowr'   r'   r(   r4      r5   z;TestCharacterString.test_2d_array_input.<locals>.<listcomp>r   r   orderr8   r9   r'   r'   r(   test_2d_array_inputx   s    z'TestCharacterString.test_2d_array_input)__name__
__module____qualname__suffixr   Zlength_listcoder   r%   dictr   Zclengthtextwrapdedentpytestmarkparametrizer)   r,   r;   r<   rB   r'   r'   r'   r(   r      s   		((**,669

	

r   c                3   @   s  e Zd ZdZdZede de de de de de d	e d
e de de de de de de de de de de de de de de de de d1Zej	
dddgdd  Zd!d" Zej	
dg d#d$d% Zd&d' Zej	
dg d#d(d) Zd*d+ Zd,d- Zd.d/ Zej	
dddgd0d1 Zd2d3 Zej	
dddgd4d5 Zej	
dddgd6d7 Zd8d9 Zej	d:d;d< Zd=d> Zd?S )@TestCharacterr   Ztest_character
       subroutine z_input(c, o)
          character, intent(in) :: c
          integer*1 o
          !f2py intent(out) o
          o = transfer(c, o)
       end subroutine z_input

       subroutine z_output(c, o)
          character :: c
          integer*1, intent(in) :: o
          !f2py intent(out) c
          c = transfer(o, c)
       end subroutine z_output

       subroutine z_input_output(c, o)
          character, intent(in) :: c
          character o
          !f2py intent(out) o
          o = c
       end subroutine z!_input_output

       subroutine z_inout(c, n)
          character :: c, n
          !f2py intent(in) n
          !f2py intent(inout) c
          c = n
       end subroutine z_inout

       function z_return(o) result (c)
          character :: c
          character, intent(in) :: o
          c = transfer(o, c)
       end function z_return

       subroutine z_array_input(c, o)
          character, intent(in) :: c(3)
          integer*1 o(3)
          !f2py intent(out) o
          integer i
          do i=1,3
            o(i) = transfer(c(i), o(i))
          end do
       end subroutine z _array_input

       subroutine a'  _2d_array_input(c, o)
          character, intent(in) :: c(2, 3)
          integer*1 o(2, 3)
          !f2py intent(out) o
          integer i, j
          do i=1,2
            do j=1,3
              o(i, j) = transfer(c(i, j), o(i, j))
            end do
          end do
       end subroutine z#_2d_array_input

       subroutine z_array_output(c, o)
          character :: c(3)
          integer*1, intent(in) :: o(3)
          !f2py intent(out) c
          do i=1,3
            c(i) = transfer(o(i), c(i))
          end do
       end subroutine z!_array_output

       subroutine z_array_inout(c, n)
          character :: c(3), n(3)
          !f2py intent(in) n(3)
          !f2py intent(inout) c(3)
          do i=1,3
            c(i) = n(i)
          end do
       end subroutine z _array_inout

       subroutine a   _2d_array_inout(c, n)
          character :: c(2, 3), n(2, 3)
          !f2py intent(in) n(2, 3)
          !f2py intent(inout) c(2. 3)
          integer i, j
          do i=1,2
            do j=1,3
              c(i, j) = n(i, j)
            end do
          end do
       end subroutine z!_2d_array_inout

       function z_array_return(o) result (c)
          character, dimension(3) :: c
          character, intent(in) :: o(3)
          do i=1,3
            c(i) = o(i)
          end do
       end function z_array_return

       function z_optional(o) result (c)
          character, intent(in) :: o
          !f2py character o = "a"
          character :: c
          c = o
       end function z_optional
    r   r3   S1c                 C   s   t | j| jd }t|tjd|dtd t|tjd|dtd t|tjdg|dtd t|tjd|dtd t|tjdgg|dtd d S )N_inputr   r      ar   )r   r   r   r   r   r   r"   r$   r   r&   r'   r'   r(   r)      s    zTestCharacter.test_inputc              
   C   s  t | j| jd }t|dtd t|dtd t|dd t|dd t|dd t|dtd t|d	td t|dgtd t|tdtd t|tdgtd td}t||td tdg}t||td z|g  W n8 tyH } zt|	d
s4 W Y d }~nd }~0 0 t
|j dz|d W n8 ty } zt|	ds W Y d }~nd }~0 0 t
|j dd S )NrQ   r   rR   r   r   r5       abs   abz got 0-listz! should have failed on empty lista   z got int instancez  should have failed on int value)r   r   r   r   r"   r   r   
IndexErrorstrendswithSystemErrorrC   	TypeErrorr$   r&   r   msgr'   r'   r(   test_input_varia   s6    
zTestCharacter.test_input_varia)r3   rP   U1c                 C   sv   t | j| jd }t|tjg d|dtjtttddd t|tjg d|dtjtttddd d S )N_array_inputr   br3   r   r   i1rR      b   c)	r   r   r   r   r   r   r    r!   r"   rS   r'   r'   r(   r;      s    zTestCharacter.test_array_inputc              
   C   s   t | j| jd }t|g dtjtttddd t|g dtjtttddd z|g d W n4 t	y } zt
|ds W Y d }~nd }~0 0 t|j d	d S )
Nr`   ra   r   rc   r   rd   r   rb   r3   d)th dimension must be fixed to 3 but got 4" should have failed on wrong input)r   r   r   r   r   r   r    r!   r"   
ValueErrorrX   rY   rZ   rC   )r$   r&   r]   r'   r'   r(   test_array_input_varia)  s"    
z$TestCharacter.test_array_input_variac                 C   sZ   t | j| jd }tjg dg dg|dd}||dkr@tjntj}t||| d S )NZ_2d_array_inputra   rh   er&   r=   r@   r_   )	r   r   r   r   r   viewZuint32Zuint8r   )r$   r   r&   r   r:   r'   r'   r(   rB   :  s    
z!TestCharacter.test_2d_array_inputc                 C   s6   t | j| jd }t|tdd t|dd d S )N_outputrR   r   rT   )r   r   r   r   r"   r$   r&   r'   r'   r(   r,   C  s    zTestCharacter.test_outputc                 C   s<   t | j| jd }t|tttdtjtddd d S )NZ_array_outputr   rP   r   )	r   r   r   r   r    r!   r"   r   r   rq   r'   r'   r(   r<   I  s    zTestCharacter.test_array_outputc                 C   s@   t | j| jd }t|dd t|dd t|dd d S )NZ_input_outputrR   r   r   rT   r   r   r   r   rq   r'   r'   r(   test_input_outputO  s    zTestCharacter.test_input_outputc                 C   s   t | j| jd }tjtd|d}||d t|tjtd|jd ||dd  d t|tjtd|jd tjdg|d}||d t|tjdg|jd d S )	N_inoutr   r   r-   Abc   BZABc)r   r   r   r   r   r    r   r   )r$   r   r&   r   r'   r'   r(   
test_inoutV  s    

zTestCharacter.test_inoutc              
   C   s   t | j| jd }tjddd}||d t|tjd|jd tjdgdd}||d t|tjdg|jd z|dd W n4 ty } zt|	ds W Y d }~nd }~0 0 t
|j dd S )	Nrt   r   ZS3r   r-   ru   z
 got 3-strz  should have failed on str value)r   r   r   r   r   r   r   rk   rX   rY   rZ   rC   r\   r'   r'   r(   test_inout_variad  s    

zTestCharacter.test_inout_variac              
   C   s4  t | j| jd }tjg d|dd}tjg d|dd}||| t|| tjg d|d}||dd  | t|tjg d	|d tjg dg|dd}||| t|tjg dg|d tjg d|dd}z||| W n8 ty } zt|d
s
 W Y d }~nd }~0 0 t	|j
 dd S )NZ_array_inoutr-   rw   Cr=   r@   ra   rg   r   rv   )r   r-   rw   r{   ri   rj   )r   r   r   r   r   r   rk   rX   rY   rZ   rC   )r$   r   r&   nr   r]   r'   r'   r(   test_array_inoutv  s,    



zTestCharacter.test_array_inoutc                 C   sb   t | j| jd }tjg dg dg|dd}tjg dg dg|dd}||| t|| d S )NZ_2d_array_inoutrz   )DEr=   r=   r@   ra   rm   r8   )r$   r   r&   r|   r   r'   r'   r(   test_2d_array_inout  s    


z!TestCharacter.test_2d_array_inoutc                 C   s$   t | j| jd }t|dd d S )NZ_returnr   rR   rr   rq   r'   r'   r(   test_return  s    zTestCharacter.test_returnz*fortran function returning array segfaultsc                 C   s6   t | j| jd }tjtddd}t||| d S )NZ_array_returnr   rP   r   )r   r   r   r   r   r    r   )r$   r&   r   r'   r'   r(   test_array_return  s    zTestCharacter.test_array_returnc                 C   s0   t | j| jd }t| d t|dd d S )NZ	_optionalrR      Brr   rq   r'   r'   r(   test_optional  s    zTestCharacter.test_optionalN)rC   rD   rE   rF   r   rI   rJ   rG   rK   rL   rM   r)   r^   r;   rl   rB   r,   r<   rs   rx   ry   r}   r   r   skipr   r   r'   r'   r'   r(   rN      s   !#+-79@BIKUW]_d
g
	#






rN   c                   @   s   e Zd ZdZdZede de de de de de d	e d
e de de de de dZej	j
dd Zdd Zdd Zdd Zej	dddgdd ZdS )TestMiscCharacterr   Ztest_misc_characterrO   a(  _gh18684(x, y, m)
         character(len=5), dimension(m), intent(in) :: x
         character*5, dimension(m), intent(out) :: y
         integer i, m
         !f2py integer, intent(hide), depend(x) :: m = f2py_len(x)
         do i=1,m
           y(i) = x(i)
         end do
       end subroutine z_gh18684

       subroutine z_gh6308(x, i)
         integer i
         !f2py check(i>=0 && i<12) i
         character*5 name, x
         common name(12)
         name(i + 1) = x
       end subroutine z_gh6308

       subroutine z_gh4519(x)
         character(len=*), intent(in) :: x(:)
         !f2py intent(out) x
         integer :: i
         ! Uncomment for debug printing:
         !do i=1, size(x)
         !   print*, "x(",i,")=", x(i)
         !end do
       end subroutine z_gh4519

       pure function aq  _gh3425(x) result (y)
         character(len=*), intent(in) :: x
         character(len=len(x)) :: y
         integer :: i
         do i = 1, len(x)
           j = iachar(x(i:i))
           if (j>=iachar("a") .and. j<=iachar("z") ) then
             y(i:i) = achar(j-32)
           else
             y(i:i) = x(i:i)
           endif
         end do
       end function z_gh3425

       subroutine aO  _character_bc_new(x, y, z)
         character, intent(in) :: x
         character, intent(out) :: y
         !f2py character, depend(x) :: y = x
         !f2py character, dimension((x=='a'?1:2)), depend(x), intent(out) :: z
         character, dimension(*) :: z
         !f2py character, optional, check(x == 'a' || x == 'b') :: x = 'a'
         !f2py callstatement (*f2py_func)(&x, &y, z)
         !f2py callprotoargument character*, character*, character*
         if (y.eq.x) then
           y = x
         else
           y = 'e'
         endif
         z(1) = 'c'
       end subroutine z%_character_bc_new

       subroutine aG  _character_bc_old(x, y, z)
         character, intent(in) :: x
         character, intent(out) :: y
         !f2py character, depend(x) :: y = x[0]
         !f2py character, dimension((*x=='a'?1:2)), depend(x), intent(out) :: z
         character, dimension(*) :: z
         !f2py character, optional, check(*x == 'a' || x[0] == 'b') :: x = 'a'
         !f2py callstatement (*f2py_func)(x, y, z)
         !f2py callprotoargument char*, char*, char*
          if (y.eq.x) then
           y = x
         else
           y = 'e'
         endif
         z(1) = 'c'
       end subroutine z_character_bc_old
    c                 C   s:   t | j| jd }tjddgdd}||}t|| d S )NZ_gh18684abcdeZfghijS5r   r8   )r$   r&   xyr'   r'   r(   test_gh18684  s    zTestMiscCharacter.test_gh18684c                 C   s~   t | j| jd }t| jjjjtd tt| jjjd |dd t| jjjd d |dd t| jjjd d	 d S )
NZ_gh6308r      r   r   s   abcdeZ12345   s   12345)	r   r   r   r   Z_BLNK_namer   r   lenrq   r'   r'   r(   test_gh6308  s    

zTestMiscCharacter.test_gh6308c              
   C   s   t | j| jd }dtdtddfdtdtddftjg ddd	td
tddfg dtd
tddfddgtdtddffD ]2\}}||}| D ]\}}tt ||| qqd S )NZ_gh4519r   r'   rP   )shaper   textZS4)r	   2r
   r   )   )r	   r   Z34ZS2r   )   )	r   r   r   rH   r   r   r   itemsr   )r$   r&   r   r:   rkvr'   r'   r(   test_gh4519  s    zTestMiscCharacter.test_gh4519c                 C   s@   t | j| jd }t|dd t|dd t|dd d S )NZ_gh3425ZabCs   ABCr   r5   ZabC12ds   ABC12Drr   rq   r'   r'   r(   test_gh3425(  s    zTestMiscCharacter.test_gh3425statenewoldc                    sr   t | j| jd |    \}}t|d tt|d  d\}}t|d tt|d tt fdd d S )NZ_character_bc_rR   rv   re   r   c                      s    dS )Nrf   r'   r'   r&   r'   r(   <lambda>=  r5   z5TestMiscCharacter.test_character_bc.<locals>.<lambda>)r   r   r   r   r   r   	Exception)r$   r   r3   r   r'   r   r(   test_character_bc1  s    


z#TestMiscCharacter.test_character_bcN)rC   rD   rE   rF   r   rI   rJ   rG   rK   rL   slowr   r   r   r   rM   r   r'   r'   r'   r(   r     sD   	)+:<K
N
	r   c                   @   s.   e Zd ZeddddgZdd Zdd Zd	S )
TestStringScalarArrtestssrcstringzscalar_string.f90c                 C   sB   | j jj| j jjfD ](}d}|j|ks*J d}|j|ksJ qd S )Nr'   z|S8)r   string_testr   Zstring77r   r   r$   outr:   r'   r'   r(   	test_charC  s    zTestStringScalarArr.test_charc                 C   sB   | j jj| j jjfD ](}d}|j|ks*J d}|j|ksJ qd S )N)r      z|S12)r   r   ZstrarrZstrarr77r   r   r   r'   r'   r(   test_char_arrK  s    z!TestStringScalarArr.test_char_arrN)rC   rD   rE   r   getpathsourcesr   r   r'   r'   r'   r(   r   @  s   r   c                   @   s&   e Zd ZeddddgZdd ZdS )TestStringAssumedLengthr   r   r   z	gh24008.fc                 C   s   | j dd d S )NZjoeZbob)r   Zgreet)r$   r'   r'   r(   test_gh24008V  s    z$TestStringAssumedLength.test_gh24008N)rC   rD   rE   r   r   r   r   r'   r'   r'   r(   r   S  s   r   c                   @   s&   e Zd ZeddddgZdd ZdS )TestStringOptionalInOutr   r   r   zgh24662.f90c                 C   sv   | j   tjddd}| j | d|  v s8J tt  d}| j | W d    n1 sh0    Y  d S )NhiZS32r   zoutput stringZHi)	r   Zstring_inout_optionalr   r   tobytesdecoderK   Zraisesr   )r$   r   Zaar'   r'   r(   test_gh24662]  s    
z$TestStringOptionalInOut.test_gh24662N)rC   rD   rE   r   r   r   r   r'   r'   r'   r(   r   Y  s   r   c                   @   s8   e Zd ZeddddeddddgZdZdd Zd	S )
TestNewCharHandlingr   r   r   zgh25286.pyfgh25286.f90_char_handling_testc                 C   s   | j d}|dksJ d S NTr   r   Zcharintr$   infor'   r'   r(   test_gh25286p  s    z TestNewCharHandling.test_gh25286NrC   rD   rE   r   r   r   module_namer   r'   r'   r'   r(   r   g  s
   r   c                   @   s8   e Zd ZeddddeddddgZdZdd Zd	S )
TestBCCharHandlingr   r   r   zgh25286_bc.pyfr   r   c                 C   s   | j d}|dksJ d S r   r   r   r'   r'   r(   r   }  s    zTestBCCharHandling.test_gh25286Nr   r'   r'   r'   r(   r   t  s
   r   )rK   rI   Znumpy.testingr   r   r   numpyr   Znumpy.f2py.testsr   rL   r   ZF2PyTestr   rN   r   r   r   r   r   r   r'   r'   r'   r(   <module>   s&   ~  , 