a ;jgU@sddlZddlZddlmZmZmZddlZddlm Z ej j Gddde j Z Gddde j ZGdd d e j ZGd d d e j ZGd d d e j Zej j Gddde j Zej j Gddde j Zej j Gddde j ZdS)N)assert_array_equal assert_equal assert_raises)utilc7@s\eZdZdZdZgdZdZeD]ZeZe dd eeZ ee deded e d ededed ed e d ed eded ede ded ededede dedededede deded37Zq ejdeddZejdeddddZejdeddZejded d!Zejded"d#ZdS)$TestCharacterString.f90Ztest_character_string13star(*))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 lengthcCs\ddi||}t|j|jd|}dddd|}t||tjttt |dd dS) Nr r raabcabcdeabcdeabcderu1dtype) getgetattrmodulefprefixrnparraylistmapordselfrfsuffixfrr'I/usr/local/lib/python3.9/site-packages/numpy/f2py/tests/test_character.py test_inputMszTestCharacterString.test_inputNcCsR|}t|j|jd|}ddd|}t|tjttt|dd| dS)Nrrr)r r rr) rrrrrrr r!r"encoder#r'r'r( test_outputVs zTestCharacterString.test_outputcCsn|}t|j|jd|}tjdddd|dddd|gd d }tjd d |Dd d }t|||dS)NrrrrrAABCABCDEABCDEABCDESrcSsg|]}dd|DqS)cSsg|]}|qSr'r'.0cr'r'r( izCTestCharacterString.test_array_input...r'r2sr'r'r(r4ir5z8TestCharacterString.test_array_input..rrrrrrrr$rr%r&rexpectedr'r'r(test_array_input`sz$TestCharacterString.test_array_inputcCsn|}t|j|jd|}tjdddd|dddd|gd d }tjd d |Dd d }t|||dS)Nrrrrrr-r.r/r0rcSsg|]}dd|DqS)cSsg|]}|qSr'r'r1r'r'r(r4ur5zDTestCharacterString.test_array_output...r'r6r'r'r(r4ur5z9TestCharacterString.test_array_output..rr8)r$rr%r&r:rr'r'r(test_array_outputlsz%TestCharacterString.test_array_outputcCs|}t|j|jd|}tjdddd|dddd|gd d d d|d d dd|ggdd}tjdd|Ddd d}t|||dS)Nrrrrrr-r.r/r&ZfghZfghijfghijfghijFZFGHZFGHIJFGHIJFGHIJr0rcSsg|]}dd|DqS)cSsg|]}dd|DqS)cSsg|]}|qSr'r'r1r'r'r(r4r5zQTestCharacterString.test_2d_array_input....r')r2itemr'r'r(r4r5zFTestCharacterString.test_2d_array_input...r')r2rowr'r'r(r4r5z;TestCharacterString.test_2d_array_input..rrorderr8r9r'r'r(test_2d_array_inputxsz'TestCharacterString.test_2d_array_input)__name__ __module__ __qualname__suffixrZ length_listcoderr%dictrZclengthtextwrapdedentpytestmark parametrizer)r,r;r<rBr'r'r'r(rs9     rc3@seZdZdZdZededededededed ed ed ed ed edededededededededededededed1Zej dddgdd Z d!d"Z ej dgd#d$d%Z d&d'Zej dgd#d(d)Zd*d+Zd,d-Zd.d/Zej dddgd0d1Zd2d3Zej dddgd4d5Zej dddgd6d7Zd8d9Zej d:d;d<Zd=d>Zd?S)@ TestCharacterrZtest_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 rr3S1cCst|j|jd}t|tjd|dtdt|tjd|dtdt|tjdg|dtdt|tjd|dtdt|tjdgg|dtddS)N_inputrrar)rrrrrrr"r$rr&r'r'r(r)s zTestCharacter.test_inputc Cst|j|jd}t|dtdt|dtdt|ddt|ddt|ddt|dtdt|d tdt|dgtdt|tdtdt|tdgtdtd}t||tdtdg}t||tdz |gWn8tyH}zt| d s4WYd}~nd}~00t |j d z |d Wn8t y}zt| d sWYd}~nd}~00t |j ddS)NrQrrRr rr5absabz got 0-listz! should have failed on empty listaz got int instancez should have failed on int value) rrrrr"rr IndexErrorstrendswith SystemErrorrC TypeErrorr$r&rmsgr'r'r(test_input_varias6    zTestCharacter.test_input_varia)r3rPU1cCsvt|j|jd}t|tjgd|dtjtttdddt|tjgd|dtjtttddddS)N _array_inputrbr3rri1rRbc) rrrrrrr r!r"rSr'r'r(r; szTestCharacter.test_array_inputc Cst|j|jd}t|gdtjtttdddt|gdtjtttdddz|gdWn4t y}zt | dsWYd}~nd}~00t |j d dS) Nr`rarrcrrdrrbr3d)th dimension must be fixed to 3 but got 4" should have failed on wrong input)rrrrrrr r!r" ValueErrorrXrYrZrC)r$r&r]r'r'r(test_array_input_varia)s"   z$TestCharacter.test_array_input_variacCsZt|j|jd}tjgdgdg|dd}||dkr@tjntj}t|||dS)NZ_2d_array_inputrarher&r=r@r_) rrrrrviewZuint32Zuint8r)r$rr&rr:r'r'r(rB:s z!TestCharacter.test_2d_array_inputcCs6t|j|jd}t|tddt|dddS)N_outputrRrrT)rrrrr"r$r&r'r'r(r,CszTestCharacter.test_outputcCs<t|j|jd}t|tttdtjtddddS)NZ _array_outputrrPr) rrrrr r!r"rrrqr'r'r(r<IszTestCharacter.test_array_outputcCs@t|j|jd}t|ddt|ddt|dddS)NZ _input_outputrRrr rTrrrrrqr'r'r(test_input_outputOszTestCharacter.test_input_outputcCst|j|jd}tjtd|d}||dt|tjtd|jd||dddt|tjtd|jdtjdg|d}||dt|tjdg|jddS) N_inoutrrr-AbcBZABc)rrrrrr rr)r$rr&rr'r'r( test_inoutVs  zTestCharacter.test_inoutc Cst|j|jd}tjddd}||dt|tjd|jdtjdgdd}||dt|tjdg|jdz|ddWn4ty}zt| dsWYd}~nd}~00t |j ddS) NrtrZS3rr-ruz got 3-strz should have failed on str value) rrrrrrrrkrXrYrZrCr\r'r'r(test_inout_variads  zTestCharacter.test_inout_variac Cs4t|j|jd}tjgd|dd}tjgd|dd}|||t||tjgd|d}||dd|t|tjgd |dtjgdg|dd}|||t|tjgdg|dtjgd|dd}z|||Wn8ty}zt|d s WYd}~nd}~00t |j d dS) NZ _array_inoutr-rwCr=r@rargrrv)rr-rwr{rirj) rrrrrrrkrXrYrZrC)r$rr&nrr]r'r'r(test_array_inoutvs,    zTestCharacter.test_array_inoutcCsbt|j|jd}tjgdgdg|dd}tjgdgdg|dd}|||t||dS)NZ_2d_array_inoutrz)DEr=r=r@rarmr8)r$rr&r|rr'r'r(test_2d_array_inouts   z!TestCharacter.test_2d_array_inoutcCs$t|j|jd}t|dddS)NZ_returnrrRrrrqr'r'r( test_returnszTestCharacter.test_returnz*fortran function returning array segfaultscCs6t|j|jd}tjtddd}t|||dS)NZ _array_returnrrPr)rrrrrr r)r$r&rr'r'r(test_array_returnszTestCharacter.test_array_returncCs0t|j|jd}t|dt|dddS)NZ _optionalrRBrrrqr'r'r( test_optionals zTestCharacter.test_optionalN)rCrDrErFrrIrJrGrKrLrMr)r^r;rlrBr,r<rsrxryr}rrskiprrr'r'r'r(rNs g #       rNc@seZdZdZdZededededededed ed ed ed ed ededZej j ddZ ddZ ddZ ddZej dddgddZdS)TestMiscCharacterrZtest_misc_characterrOa(_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 cCs:t|j|jd}tjddgdd}||}t||dS)NZ_gh18684abcdeZfghijS5rr8)r$r&xyr'r'r( test_gh18684szTestMiscCharacter.test_gh18684cCs~t|j|jd}t|jjjjtdtt|jjjd|ddt|jjjdd|ddt|jjjdd dS) NZ_gh6308r rrsabcdeZ12345s12345) rrrrZ_BLNK_namerrlenrqr'r'r( test_gh6308 s  zTestMiscCharacter.test_gh6308c Cst|j|jd}dtdtddfdtdtddftjgddd td tddfgd td td dfd d gtdtddffD]2\}}||}|D]\}}tt|||qqdS)NZ_gh4519rr'rP)shapertextZS4)r 2r r))r rZ34ZS2r )) rrrrHrrritemsr)r$r&rr:rkvr'r'r( test_gh4519s zTestMiscCharacter.test_gh4519cCs@t|j|jd}t|ddt|ddt|dddS)NZ_gh3425ZabCsABCr r5ZabC12dsABC12Drrrqr'r'r( test_gh3425(szTestMiscCharacter.test_gh3425statenewoldcsrt|j|jd|\}}t|dtt|dd\}}t|dtt|dttfdddS)NZ_character_bc_rRrvrercsdS)Nrfr'r'r&r'r(=r5z5TestMiscCharacter.test_character_bc..)rrrrrr Exception)r$rr3rr'rr(test_character_bc1s    z#TestMiscCharacter.test_character_bcN)rCrDrErFrrIrJrGrKrLslowrrrrrMrr'r'r'r(rsD N   rc@s.eZdZeddddgZddZddZd S) TestStringScalarArrtestssrcstringzscalar_string.f90cCsB|jjj|jjjfD](}d}|j|ks*Jd}|j|ksJqdS)Nr'z|S8)r string_testrZstring77rrr$outr:r'r'r( test_charCszTestStringScalarArr.test_charcCsB|jjj|jjjfD](}d}|j|ks*Jd}|j|ksJqdS)N)rz|S12)rrZstrarrZstrarr77rrrr'r'r( test_char_arrKsz!TestStringScalarArr.test_char_arrN)rCrDrErgetpathsourcesrrr'r'r'r(r@src@s&eZdZeddddgZddZdS)TestStringAssumedLengthrrrz gh24008.fcCs|jdddS)NZjoeZbob)rZgreet)r$r'r'r( test_gh24008Vsz$TestStringAssumedLength.test_gh24008N)rCrDrErrrrr'r'r'r(rSsrc@s&eZdZeddddgZddZdS)TestStringOptionalInOutrrrz gh24662.f90cCsv|jtjddd}|j|d|vs8Jtt d}|j|Wdn1sh0YdS)NhiZS32rz output stringZHi) rZstring_inout_optionalrrtobytesdecoderKZraisesr)r$rZaar'r'r( test_gh24662]s   z$TestStringOptionalInOut.test_gh24662N)rCrDrErrrrr'r'r'r(rYsrc@s8eZdZeddddeddddgZdZddZd S) TestNewCharHandlingrrrz gh25286.pyf gh25286.f90_char_handling_testcCs|jd}|dksJdSNTrrZcharintr$infor'r'r( test_gh25286ps z TestNewCharHandling.test_gh25286NrCrDrErrr module_namerr'r'r'r(rgs rc@s8eZdZeddddeddddgZdZddZd S) TestBCCharHandlingrrrzgh25286_bc.pyfrrcCs|jd}|dksJdSrrrr'r'r(r}s zTestBCCharHandling.test_gh25286Nrr'r'r'r(rts r)rKrIZ numpy.testingrrrnumpyrZnumpy.f2py.testsrrLrZF2PyTestrrNrrrrrrr'r'r'r(s& ~,