id3>ddlZddlZddlZddlZddlZddlZddlmZm Z ddl m Z ddl m Z ddlZGdde jZGdd ZGd d ZGd d e jZGdde jZGddZGdde jZGddZGdde jZGdde jZGdde jZGddZGdde jZGd d!e jZdS)"N)markinnerspacesnameargspattern)util) crackfortranc<eZdZejddddgZdZdS) TestNoSpacetestssrcrz gh15035.fctjgdtj}tjgdtj}|j||j||gdS)N)r)dtype)nparrayfloat64modulesubbsubc)selfkws W/opt/cloudlinux/venv/lib/python3.11/site-packages/numpy/f2py/tests/test_crackfortran.py test_modulezTestNoSpace.test_modulesl HYYYbj 1 1 1 HYYYbj 1 1 1  !Q     N)__name__ __module__ __qualname__rgetpathsourcesrrrr r s?t|GUNKHHIG,,,,,rr c&eZdZdZdZdZdZdS)TestPublicPrivatectjdddd}tjt|g}|d}dS)Nr r rzprivatemod.f90rrrrstr)rfpathmods rtest_defaultPrivatez%TestPublicPrivate.test_defaultPrivate= We^=MNN'U 55!frctjdddd}tjt|g}|d}dS)Nr r rz publicmod.f90rr%rtmp_pathr'r(s rtest_defaultPublicz$TestPublicPrivate.test_defaultPublic)< We^_MM'U 55!frctjdddd}tjt|g}|dd}dS)Nr r rzaccesstype.f90rvarsr%)rr-r'r(tts rtest_access_typez"TestPublicPrivate.test_access_type3sA We^=MNN'U 55 VF^rctjdddd}tjt|g}tj|}dS)Nr r rz gh23879.f90)rrrr& crack2fortran)rr-r'r(pyfs rtest_nowrap_private_proceeduresz1TestPublicPrivate.test_nowrap_private_proceedures<sC We^]KK'U 55(--rN)rrrr)r.r3r7r!rrr#r#sP ; ; ;;;;666     rr#ceZdZdZdZdS)TestModuleProcedurectjdddd}tjt|g}|d}dS)Nr r rz operators.f90rr%r,s rtest_moduleOperatorsz(TestModuleProcedure.test_moduleOperatorsDr/rctjdddd}tjt|g}|d}dS)Nr r rzpubprivmod.f90rr%r,s rtest_notPublicPrivatez)TestModuleProcedure.test_notPublicPrivateVr*rN)rrrr;r=r!rrr9r9Cs2$$$$?????rr9cBeZdZejddddgZdZdZdS) TestExternalr r rz gh17859.fc@d}|j|}dS)Nc |dzSN{r!xs rincrz5TestExternal.test_external_as_statement..incre s7Nr)rexternal_as_statementrrFrs rtest_external_as_statementz'TestExternal.test_external_as_statementd,    K - -d 3 3rc@d}|j|}dS)Nc |dzSrBr!rDs rrFz5TestExternal.test_external_as_attribute..incrlrGr)rexternal_as_attributerIs rtest_external_as_attributez'TestExternal.test_external_as_attributekrLrN)rrrrrr rKrPr!rrr?r?`sLt|GUNKHHIGrr?c<eZdZejddddgZdZdS)TestCrackFortranr r rz gh2848.f90c<|jdd}dS)Nrr )rgh2848)rrJs r test_gh2848zTestCrackFortran.test_gh2848ws K  q! $ $rN)rrrrrr rUr!rrrRrRss=t|GUNLIIJGrrRc&eZdZdZdZdZdZdS)TestMarkinnerspacescgd}|D]}dS)N)za z aza b cz 'abcdefghij'r!)r test_listis rtest_do_not_touch_normal_spacesz3TestMarkinnerspaces.test_do_not_touch_normal_spacess(999  + +AA + +rcdSNr!rs rtest_one_relevant_spacez+TestMarkinnerspaces.test_one_relevant_spacercdSr]r!r^s rtest_ignore_inner_quotesz,TestMarkinnerspaces.test_ignore_inner_quotesr`rcdSr]r!r^s rtest_multiple_relevant_spacesz1TestMarkinnerspaces.test_multiple_relevant_spacesr`rN)rrrr[r_rbrdr!rrrWrW|s[+++ GGGOOOIIIIIrrWc eZdZdZdZejdZgdZdgZ ee zZ dZ e e D]R\Z ZdedDZe ee ed e z Z Sejd e d Zejd e d ZdS) TestDimSpecaThis test suite tests various expressions that are used as dimension specifications. There exists two usage cases where analyzing dimensions specifications are important. In the first case, the size of output arrays must be defined based on the inputs to a Fortran function. Because Fortran supports arbitrary bases for indexing, for instance, `arr(lower:upper)`, f2py has to evaluate an expression `upper - lower + 1` where `lower` and `upper` are arbitrary expressions of input parameters. The evaluation is performed in C, so f2py has to translate Fortran expressions to valid C expressions (an alternative approach is that a developer specifies the corresponding C expressions in a .pyf file). In the second case, when user provides an input array with a given size but some hidden parameters used in dimensions specifications need to be determined based on the input array size. This is a harder problem because f2py has to solve the inverse problem: find a parameter `p` such that `upper(p) - lower(p) + 1` equals to the size of input array. In the case when this equation cannot be solved (e.g. because the input array size is wrong), raise an error before calling the Fortran function (that otherwise would likely crash Python process when the size of input arrays is wrong). f2py currently supports this case only when the equation is linear with respect to unknown parameter. z.f90a function get_arr_size_{count}(a, n) result (length) integer, intent(in) :: n integer, dimension({dimspec}), intent(out) :: a integer length length = size(a) end function subroutine get_inv_arr_size_{count}(a, n) integer :: n ! the value of n is computed in f2py wrapper !f2py intent(out) n integer, dimension({dimspec}), intent(in) :: a end subroutine )nz2*nz2:nzn/2z5 - n/2z3*n:20zn*(n+1):n*(n+5)z2*n, nz 2*n:3*n*n+2*ncPg|]#}d|vr|ddnd$S):r1)split).0ds r zTestDimSpec.s2RRR!3!88 QRRRr,z, )countdimspecfirstrrc|j|}t|jd|}dD]}||\}}dS)N get_arr_size_rr r) all_dimspecsindexgetattrr)rrrrq get_arr_sizergszas rtest_array_sizezTestDimSpec.test_array_sizes`!''00t{,CE,C,CDD    A LOOEB  rc|j|}t|jd|}t|jd|}dD]?}||\}}||jvr |||}n ||}||\} } @dS)Nruget_inv_arr_size_rv)ryrzr{rnonlinear_dimspecs) rrrrqr|get_inv_arr_sizergr}r~n1sz1_s rtest_inv_array_sizezTestDimSpec.test_inv_array_sizes!''00t{,CE,C,CDD "4;0KE0K0KLL  / /A LOOEB$111&%a++&%a(("\"%%FC / /rN)rrr__doc__suffixtextwrapdedent code_templatelinear_dimspecsrrycode enumeraterqrrrllstformatjoinpytestmark parametrizerrr!rrrfrfs7<F#HO%  M O**"%77L D#)L11  wRRw}}S?Q?QRRR $$))C..%     [Y 55  65  [Y 55//65///rrfceZdZdZdS)TestModuleDeclarationcxtjdddd}tjt|g}dS)Nr r rz foo_deps.f90r%r,s rtest_dependenciesz'TestModuleDeclaration.test_dependenciess3 We^^LL'U 55rN)rrrrr!rrrrs#<<<<d}d}d\}}t||D]}||z}t|D]f}g} t|D]R}tj} tj|} | tj| z Sg|dz} dS)zPaddress ReDOS vulnerability: https://github.com/numpy/numpy/issues/23338 rw)z@)@N)rangetime perf_counterrsearchappend) rrtrials_per_batchbatches_per_regex start_repsend_repsiirepeated_adversaryrtimest0mtchgood_version_of_adversarys r!test_nameargspattern_backtrackingzATestNameArgsPatternBacktracking.test_nameargspattern_backtracking!s% H H-- E EB!*R ,-- . ./00;;A*,,B*12DEEDLL!2!4!4r!9::::;);U(B % %% E ErN)rrrrrrrr!rrrr s[ [     EEEEErrc<eZdZejddddgZdZdS)TestFunctionReturnr r rz gh23598.f90cdSr]r!r^s rtest_function_rettypez(TestFunctionReturn.test_function_rettypeHr`rN)rrrrrr rr!rrrrEs=t|GUNMJJKG22222rrceZdZdZdS)TestFortranGroupCountersctjdddd} tjt|gdS#t$r }Yd}~dSd}~wwxYw)Nr r rz gh23533.f)rrrr& Exception)rr'excs rtest_end_if_commentz,TestFortranGroupCounters.test_end_if_commentNs We^[II S  %s5zzl 3 3 3 3 3 S S S S S S S S S Ss"= A AN)rrrrr!rrrrMs(SSSSSrr)rcodecsr unicodedatarnumpyrnumpy.f2py.crackfortranrrrhr numpy.f2pyrrF2PyTestr r#r9r?rRrWrfrrrrrrrr!rrrs   DDDDDDDD###### , , , , ,$- , , ,% % % % % % % % N????????:4=&t}IIIIIIII*`/`/`/`/`/$-`/`/`/F<<<<<<<<33333t}333 ' ' ' ' ' ' ' '"E"E"E"E"E"E"E"EJ22222222SSSSSt}SSSSSr