
    Khl                     z   S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	r	S SK
r
SSKJr  S SKJr  S SKJr  S r\" S	S
5      rSQS jr\
R*                  " SS9S 5       r\
R*                  " SS9S 5       r\
R*                  " SS9S 5       r\
R*                  " SS9S 5       r\
R*                  " SS9S 5       r\
R*                  " SS9S 5       rS rS rS rS rS r S r!\
RD                  RG                  \RH                  S:*  SS9S 5       r%\
RD                  RG                  \	RL                  " 5       S:g  =(       d    \RH                  S:*  SS9S  5       r'\
RD                  RP                  S! 5       r)S" r*S# r+S$ r,S% r-S& r.S' r/S( r0S) r1S* r2S+ r3S, r4S- r5S. r6S/ r7\
RD                  Rq                  S0S9S1 5       r9S2 r:S3 r;S4 r<S5 r=S6 r>S7 r?S8 r@S9 rAS: rB\
RD                  Rq                  S0S9S; 5       rC\
RD                  RG                  \	RL                  " 5       S:g  =(       d    \RH                  S:*  S<S9S= 5       rD\
RD                  RG                  \	RL                  " 5       S:g  =(       d    \RH                  S:*  S<S9S> 5       rES? rFS@ rGSA rHSB rISC rJSD rKSE rLSF rMSG rNSH rOSI rPSJ rQSK rRSL rSSM rTSN rUSO rVSP rWg)R    N)Path)
namedtuple   )util)main)NOGIL_BUILDc                  z    [         R                  " 5       (       d  [        R                  " S5        g [	        5         g )Nz$CLI command needs a Fortran compiler)r   has_fortran_compilerpytestskipf2pycli     N/var/www/html/env/lib/python3.13/site-packages/numpy/f2py/tests/test_f2py2e.pycompiler_check_f2pyclir      s#    $$&&:;	r   PPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodfc                     [        U 5      n[        UR                  S5      UR                  S5      UR                  S5      UR                  U S35      UR                  U S35      UR                  U S35      S9$ )a8  Takes in a temporary file for testing and returns the expected output and input paths

Here expected output is essentially one of any of the possible generated
files.

..note::

     Since this does not actually run f2py, none of these are guaranteed to
     exist, and module names are typically incorrect

Parameters
----------
fname_inp : str
            The input filename
mname : str, optional
            The name of the module, untitled by default

Returns
-------
genp : NamedTuple PPaths
        The possible paths which are generated, not all of which exist
z.fz.f90.pyfz-f2pywrappers.fz-f2pywrappers2.f90module.c)finpf90inppyfwrap77wrap90cmodf)r   r   with_suffix	with_name)	fname_inpmnamebpaths      r   get_io_pathsr!   $   s~    . OEt$  (f%%89%(:;<oox01 r   session)scopec                     [         R                  " SSSS5      R                  5       nU R                  5       S-  nUR	                  USS9  U$ )'Generates a single f90 file for testingtestssrcclizhiworld.f90z	hello.f90asciiencodingr   getpath	read_textgetbasetemp
write_texttmpdir_factoryfdatfns      r   hello_world_f90r5   K   sI     <<}=GGID		#	#	%	3BMM$M)Ir   c                     [         R                  " SSSS5      R                  5       nU R                  5       S-  nUR	                  USS9  U$ )z(F90 file for testing warnings in gh23598r&   r'   crackfortranzgh23598Warn.f90r)   r*   r,   r1   s      r   gh23598_warnr8   T   sK     <<8IJTTVD		#	#	%(9	9BMM$M)Ir   c                     [         R                  " SSSS5      R                  5       nU R                  5       S-  nUR	                  USS9  U$ )z8F90 file for testing disallowed CLI arguments in ghff819r&   r'   r(   zgh_22819.pyfr)   r*   r,   r1   s      r   gh22819_clir:   ]   sI     <<~>HHJD		#	#	%	6BMM$M)Ir   c                     [         R                  " SSSS5      R                  5       nU R                  5       S-  nUR	                  USS9  U$ )'Generates a single f77 file for testingr&   r'   r(   zhi77.fzhello.fr)   r*   r,   r1   s      r   hello_world_f77r=   f   sI     <<x8BBDD		#	#	%		1BMM$M)Ir   c                     [         R                  " SSSS5      R                  5       nU R                  5       S-  nUR	                  USS9  U$ )r<   r&   r'   return_realzfoo77.fzfoo.fr)   r*   r,   r1   s      r   retreal_f77r@   o   sI     <<yAKKMD		#	#	%	/BMM$M)Ir   c                 .   [         R                  " SSSS5      R                  5       n[         R                  " SSSS5      R                  5       nU R                  5       S-  nU R                  5       S-  nUR	                  USS	9  UR	                  USS	9  U$ )
r%   r&   r'   f2cmapzisoFortranEnvMap.f90z.f2py_f2cmapz
f2cmap.f90mapfiler)   r*   r,   )r2   r3   rB   r4   fmaps        r   
f2cmap_f90rE   w   s     <<2HISSUD\\'5(NCMMOF		#	#	%	4B%%')3DMM$M)OOFWO-Ir   c                    [        U5      nUR                  [        SSU 3R                  5       5        [        R
                  " UR                  5         [        5         UR                  R                  S5       Vs/ s H%  oDR                  5       (       d  M  UR                  PM'     nnSU;  d   eSU;  d   eSU;   d   eSU;   d   e SSS5        gs  snf ! , (       d  f       g= f)	zCheck that module names are handled correctly
gh-22819
Essentially, the -m name cannot be used to import the module, so the module
named in the .pyf needs to be used instead

CLI :: -m and a .pyf file
argvf2py -m blah *zblahmodule.czblah-f2pywrappers.fztest_22819-f2pywrappers.fztest_22819module.cN)r   setattrsyssplitr   	switchdirparentr   rglobis_filename)capfdr:   monkeypatchipathitem	gen_pathss         r   test_gh22819_clirW      s     EV}UG%<%B%B%DE		%	+0<<+=+=c+BU+B4llnYTYY+B	UY...$I555*i777#y000 
&	%U 
&	%s$   (C<CC("CC
C'c                 Z   [        U5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        R                  " [        SS9   [        5         SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)z6Only one .pyf file allowed
gh-22819
CLI :: .pyf files
rG   rH   z
 hello.pyfzOnly one .pyf file per call)matchN)r   rJ   rK   rL   r   rM   rN   r   raises
ValueErrorr   )rR   r:   rS   rT   s       r   test_gh22819_many_pyfr\      st    
 EV}UG:%F%L%L%NO		%]]:-JKI L 
&	%KK 
&	%s$   B/B:B
B	B
B*c                 P   [        USS9nUR                  nUR                  [        SSU S3R	                  5       5        [
        R                  " UR                  5         [        5         UR                  R                  5       nSU;  d   e S S S 5        g ! , (       d  f       g = f)Ntestr   rG   f2py z -m testzintproductf2pywrap, intpr)r!   r   rJ   rK   rL   r   rM   rN   r   r   r.   )rR   r8   rS   foutlrT   wrappers         r   test_gh23598_warnrc      s    V4ELLEV
wh%%') 
	%	,,((**'999 
&	%	%s    -B
B%c                    [        U5      n[        U5      R                  S-   nUR                  [        SSU SU 3R	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pVSU;   d   e[        U 5      R                  5       (       d   e SSS5        g! , (       d  f       g= f)zAEnsures that a signature file is generated via the CLI
CLI :: -h
r   rG   zf2py -h  Saving signatures to fileN)r   stemrJ   rK   rL   r   rM   rN   r   
readouterrexists)rR   r5   rS   rT   opathout_s          r   test_gen_pyfrm      s     !E!&&/EVxwaw%?%E%E%GH		%	!!#*c111ug&&((((	 
&	%	%s   /AB??
Cc                 8   [        U5      nUR                  [        SSU 3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pESU;   d   eSU;   d   e SSS5        g! , (       d  f       g= f)z@Ensures that a signature file can be dumped to stdout
CLI :: -h
rG   zf2py -h stdout rf   zfunction hi() ! in N	r   rJ   rK   rL   r   rM   rN   r   rh   rR   r5   rS   rT   rk   rl   s         r   test_gen_pyf_stdoutrq      s}     !EVug%>%D%D%FG		%	!!#*c111$+++	 
&	%	%s   -B
Bc                    [        U5      nUR                  [        SSU 3R                  5       5        [        R
                  " UR                  5         [        S5      R                  SSS9  [        R                  " [        5         [        5         U R                  5       u  pESU;   d   e SSS5        SSS5        g! , (       d  f       N= f! , (       d  f       g= f)	zbEnsures that the CLI refuses to overwrite signature files
CLI :: -h without --overwrite-signature
rG   f2py -h faker.pyf 	faker.pyf	Fake newsr)   r*   z&Use --overwrite-signature to overwriteN)r   rJ   rK   rL   r   rM   rN   r0   r   rZ   
SystemExitr   rh   )rR   r5   rS   rT   rl   errs         r   test_gen_pyf_no_overwriterx      s     !EV'9%%A%G%G%IJ		%[$$[7$C]]:&I%%'FA;sBBB ' 
&	%&& 
&	%s$   4C%B?.C?
C		C
C)      zPython 3.12 required)reasonc                 (   [        U5      nUR                  [        SSU 3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pESU;   d   e SSS5        g! , (       d  f       g= f)z8Check that modules are named correctly

CLI :: defaults
rG   zf2py --backend meson -c zuntitledmodule.cN)	r   rJ   rK   rL   r   rM   rN   r   rh   rp   s         r   test_untitled_clir}      sq     !EV'?w%G%M%M%OP		% !!#!S((( 
&	%	%s   %B
BLinuxzCompiler and 3.12 requiredc           	      h   Sn[        XS9nUR                  nUR                  [        SSU SU 3R	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pgSU;   d   e SSS5        UR                  [        SSR	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pgS	U;   d   e SSS5        S
nUR                  [        SSU SU S3R	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pgSU;   d   e SSS5        g! , (       d  f       N= f! , (       d  f       N= f! , (       d  f       g= f)ziCheck that no distutils imports are performed on 3.12
CLI :: --fcompiler --help-link --backend distutils
hir_   rG   r`   z -c --fcompiler=gfortran -m z%--fcompiler cannot be used with mesonNzf2py --help-linkzUse --dep for meson buildshi2z -c -m z --backend distutilsz.Cannot use distutils backend with Python>=3.12)r!   r   rJ   rK   rL   r   rM   rN   r   rh   r   )rR   r5   rS   MNAMEra   rT   rk   rl   s           r   !test_no_py312_distutils_fcompilerr      sk   
 E6ELLEVuUG#?wGMMO 
	% !!#6#=== 
& V'--/ 
	%	!!#+s222 
& EVuUG75'1EFLLN 
	%	!!#?3FFF 
&	% 
&	% 
&	% 
&	%s$   #%F%F%F#
F
F #
F1c                    [        USS9nUR                  nSnSnUR                  [        SSU SU 3R	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pxUR	                  5        H  n	SU	 S	3U;   a  M   e   UR	                  5        H  n
S
U
 S3U;   a  M   e   SSS5        g! , (       d  f       g= f)z1Tests that functions can be skipped
CLI :: skip:
r^   r_   t0 t4 t8 sd s8 s4td s0rG   r`   z -m test skip: z=buildmodule: Could not found the body of interfaced routine "". Skipping.Constructing wrapper function ""N
r!   r   rJ   rK   rL   r   rM   rN   r   rh   )rR   r@   rS   ra   rT   toskip	remainingrk   rw   skeyrkeys              r   test_f2py_skipr     s    
 F3EJJE FIV
wofX.4468 
	%	##%LLNDOPTvUab # OO%D4TF!<CCC & 
&	%	%   &8C"CC
C c                    [        USS9nUR                  nSnSnUR                  [        SSU SU 3R	                  5       5        [
        R                  " UR                  5         [        5         U R                  5       u  pxUR	                  5        H  n	SU	 S	3U;   a  M   e   UR	                  5        H  n
S
U
 S3U;   a  M   e   SSS5        g! , (       d  f       g= f)z6Test that functions can be kept by only:
CLI :: only:
r^   r_   r   r   rG   r`   z -m test only: <buildmodule: Could not find the body of interfaced routine "r   r   r   Nr   )rR   r@   rS   ra   rT   r   tokeeprk   rw   r   r   s              r   test_f2py_onlyr   $  s     F3EJJE FFV
wofX.4468 
	%	##%LLNDNtfT`a # LLND4TF!<CCC # 
&	%	%r   c                    [        USS9nUR                  nSn[        U5      nSnSn	UR                  [        SSU SU	 S	U S
U 3R                  5       5        [        R                  " UR                  5         [        5         U R                  5       u  pUR                  5        H  nSU S3U;   a  M   e   UR                  5        H  nSU S3U
;   a  M   e   SSS5        g! , (       d  f       g= f)zZTests that it is possible to return to file processing mode
CLI :: :
BUG: numpy-gh #20520
r^   r_   r   ztd s0 hiblahrG   r`    -m z only: z : r   r   r   r   N)r!   r   r   rJ   rK   rL   r   rM   rN   r   rh   )rR   r5   r@   rS   ra   rT   r   ipath2r   r   rk   rw   r   r   s                 r   test_file_processing_switchr   ;  s     F3EJJE F/"FFE
wd5'F8<BB 	
 
	%	##%LLNDNtfT`a # LLND4TF!<CCC # 
&	%	%s   98C%5C%C%%
C3c                    Sn[        XS9nUR                  nUR                  [        SSU SU 3R	                  5       5        [
        R                  " UR                  5         [        5         SSS5        [        R                  " UR                  5      (       d   e[        R                  " UR                  5      (       d   eg! , (       d  f       N]= f)z@Checks the generation of files based on a module name
CLI :: -m
r   r_   rG   r`   r   N)r!   r   rJ   rK   rL   r   rM   rN   r   r   ri   r   r   )rR   r5   rS   r   ra   rT   s         r   test_mod_gen_f77r   Y  s     E6ELLEVuUG4w%?%E%E%GH		%	 
& ;;u{{####;;u||$$$$ 
&	%s   #C
Cc           	         Sn[        XS9nUR                  nUR                  [        SSU SU S3R	                  5       5        [
        R                  " UR                  5         [        5         [        S5      R                  5        nUR                  5       nSU;   d   e S	S	S	5        S	S	S	5        g	! , (       d  f       N= f! , (       d  f       g	= f)
zuCheck that pyf files are correctly generated with module structure
CLI :: -m <name> -h pyf_file
BUG: numpy-gh #20520
r   r_   rG   r`   r   z
 -h hi.pyfzhi.pyfzpython module hiN)r!   r   rJ   rK   rL   r   rM   rN   r   r   openread)rR   r=   rS   r   ra   rT   hipyfpyfdats           r   test_mod_gen_gh25263r   j  s    
 E6EJJEVuUG4wj%I%O%O%QR		%	(^  "eZZ\F%/// # 
&	%"" 
&	%s$   $$CB3"C3
C	=C
Cc                 (   [        USS9nUR                  n[        R                  " S5      n[        R                  " S5      nUR	                  [
        SSU S3R                  5       5        [        R                  " UR                  5         [        5         U R                  5       u  pxUR                  U5      c   eUR                  U5      b   e SSS5        UR	                  [
        SSU S	3R                  5       5        [        R                  " UR                  5         [        5         U R                  5       u  pxUR                  U5      b   eUR                  U5      c   e SSS5        g! , (       d  f       N= f! , (       d  f       g= f)
z@Lowers cases by flag or when -h is present

CLI :: --[no-]lower
r^   r_   zHI\(\)zhi\(\)rG   r`   z -m test --lowerNz -m test --no-lower)r!   r   recompilerJ   rK   rL   r   rM   rN   r   rh   search	rR   r=   rS   ra   rT   capshicapslork   rl   s	            r   test_lower_cmodr   z  sB   
 7EJJEZZ	"FZZ	"FVuUG3C%D%J%J%LM		%	!!#}}S!---}}S!)))	 
& Vw&9:@@BD		%	!!#}}S!)))}}S!---	 
&	% 
&	% 
&	%s   AE2#AF2
F 
Fc           	      \   [        USS9nUR                  n[        R                  " S5      n[        R                  " S5      nUR	                  [
        SSU SUR                   S3R                  5       5        [        R                  " UR                  5         [        5         U R                  5       u  pxUR                  U5      c   eUR                  U5      b   e S	S	S	5        UR	                  [
        SSU SUR                   S
3R                  5       5        [        R                  " UR                  5         [        5         U R                  5       u  pxUR                  U5      b   eUR                  U5      c   e S	S	S	5        g	! , (       d  f       N= f! , (       d  f       g	= f)zVLowers cases in signature files by flag or when -h is present

CLI :: --[no-]lower -h
r^   r_   z	Block: HIz	Block: hirG   r`   z -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)r!   r   r   r   rJ   rK   r   rL   r   rM   rN   r   rh   r   r   s	            r   test_lower_sigr     s`   
 7EJJEZZ%FZZ%F 
wd599+%CDJJL 
	%	!!#}}S!---}}S!)))	 
& 
wd599+%NO		 
	%	!!#}}S!)))}}S!---	 
&	% 
&	% 
&	%s   AF=AF
F
F+c           
      D   [        U5      nSnSnUR                  [        SSU SU SU 3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pgSU S3U;   d   e S	S	S	5        g	! , (       d  f       g	= f)
zFEnsures that the build directory can be specified

CLI :: --build-dir
r   tttmprG   f2py -m re   z --build-dir zWrote C/API module "r   Nro   )rR   r5   rS   rT   r   odirrk   rl   s           r   test_build_dirr     s    
 !EEDV"5'5'tfEKKMO 
	%	!!#&ugR0C777 
&	%	%s   )B
Bc                 \   [        U5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        S5      R                  SSS9  [        5         U R                  5       u  pESU;   d   e S	S	S	5        g	! , (       d  f       g	= f)
zPEnsures that the build directory can be specified

CLI :: --overwrite-signature
rG   rs   z --overwrite-signaturert   ru   r)   r*   rf   N)
r   rJ   rK   rL   r   rM   rN   r0   r   rh   rp   s         r   test_overwriter     s    
 !EV
UG#9:@@BD 
	%[$$[7$C	!!#*c111	 
&	%	%s   >B
B+c           	         [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;   d   e[        U S35      R                  5        nSUR                  5       ;   d   e S	S	S	5        S	S	S	5        g	! , (       d  f       N= f! , (       d  f       g	= f)
zBEnsures that TeX documentation is written out

CLI :: --latex-doc
r   rG   r   re   z --latex-docDocumentation is saved to file
module.tex\documentclassNr   rJ   rK   rL   r   rM   rN   r   rh   r   r   rR   r5   rS   rT   r   rk   rl   otexs           r   test_latexdocr     s    
 !EEV"5'5'>DDFH 
	%	!!#/3666UG:&',,.$$		333 /	 
&	% /.	 
&	%s%   ACC3C
C	C
C#c           	      4   [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;  d   e SSS5        g! , (       d  f       g= f)zEEnsures that TeX documentation is written out

CLI :: --no-latex-doc
r   rG   r   re   z --no-latex-docr   Nro   rR   r5   rS   rT   r   rk   rl   s          r   test_nolatexdocr     s    
 !EEV"5'5'AGGIK 
	%	!!#/s::: 
&	%	%   %B		
Bc           	         [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;   d   e[        SU S35      R                  5        nS	UR                  5       ;  d   e S
S
S
5        S
S
S
5        g
! , (       d  f       N= f! , (       d  f       g
= f)zEnsures that truncated documentation is written out

TODO: Test to ensure this has no effect without --latex-doc
CLI :: --latex-doc --short-latex
r   rG   r   re   z --latex-doc --short-latexr   ./r   r   Nr   r   s           r   test_shortlatexr     s     !EE
5'5'!;<BBD 
	%	!!#/3666BugZ()..0D$DIIK777 1	 
&	% 10	 
&	%%   ACC4C
C	C
C$c           	         [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;   d   e[        SU S35      R                  5        nS	UR                  5       ;   d   e S
S
S
5        S
S
S
5        g
! , (       d  f       N= f! , (       d  f       g
= f)zAEnsures that RsT documentation is written out

CLI :: --rest-doc
r   rG   r   re   z --rest-doc#ReST Documentation is saved to filer   zmodule.restz.. -*- rest -*-Nr   )rR   r5   rS   rT   r   rk   rl   orsts           r   test_restdocr     s    
 !EEV"5'5'=CCEG 
	%	!!#4;;;Bug[)*//1T%444 2	 
&	% 21	 
&	%r   c           	      4   [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;  d   e SSS5        g! , (       d  f       g= f)zDEnsures that TeX documentation is written out

CLI :: --no-rest-doc
r   rG   r   re   z --no-rest-docr   Nro   r   s          r   test_norestexdocr   '  s    
 !EEV"5'5'@FFHJ 
	%	!!#4C??? 
&	%	%r   c           	         [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         [        SU S35      R                  5        nSUR                  5       ;   d   e S	S	S	5        S	S	S	5        g	! , (       d  f       N= f! , (       d  f       g	= f)
zAEnsures that debugging wrappers are written

CLI :: --debug-capi
r   rG   r   re   z --debug-capir   r   z#define DEBUGCFUNCSN
r   rJ   rK   rL   r   rM   rN   r   r   r   )rR   r5   rS   rT   r   ocmods         r   test_debugcapir   7  s    
 !EEV"5'5'?EEGI 
	%	BugX&',,.%)UZZ\999 / 
&	%.. 
&	%s$   (B<B+B<+
B9	5B<<
C
z2Consistently fails on CI; noisy so skip not xfail.c           	         [        U 5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         [        R                  " [        R                   S35      n[        R                  " USSS	9nS
n[        R                  " S5      nUR                  U:X  d   eUR                  U:X  d   e SSS5        g! , (       d  f       g= f)z=Ensures that debugging wrappers work

CLI :: --debug-capi -c
r   rG   r   re   z -c --debug-capi -c "import blah; blah.hi()"TUTF-8capture_outputr+    Hello World
a   debug-capi:Python C/API function blah.hi()
debug-capi:float hi=:output,hidden,scalar
debug-capi:hi=0
debug-capi:Fortran subroutine `f2pywraphi(&hi)'
debug-capi:hi=0
debug-capi:Building return value.
debug-capi:Python C/API function blah.hi: successful.
debug-capi:Freeing memory.
        N)r   rJ   rK   rL   r   rM   rN   r   shlex
executable
subprocessruntextwrapdedentstdoutstderr)r5   rS   rT   r   cmd_runrouteouteerrs           r   test_debugcapi_bldr   G  s     !EEV"5'5'1ABHHJL 
	%	++ 00NOP~~gdWM 	  	 {{d"""{{d"""! 
&	%	%s   BC((
C6c           	      F   [        U5      nSnUR                  [        SSU SU 3R                  5       5        [        R
                  " UR                  5         [        5         SSS5        U R                  5       u  pVSU;   d   eUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;   d   e SSS5        g! , (       d  f       N= f! , (       d  f       g= f)zgEnsures that fortran subroutine wrappers for F77 are included by default

CLI :: --[no]-wrap-functions
r   rG   r   re   N Fortran 77 wrappers are saved toz --wrap-functionsro   r   s          r   test_wrapfunc_defr   e  s     !EEVxwaw%?%E%E%GH		%	 
&FC.#555 V"5'5'1BCIIKM 
	%	!!#2c999 
&	% 
&	% 
&	%s   D%D
D
D c           	      4   [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pVSU;  d   e SSS5        g! , (       d  f       g= f)z]Ensures that fortran subroutine wrappers for F77 can be disabled

CLI :: --no-wrap-functions
r   rG   r   re   z --no-wrap-functionsr   Nro   r   s          r   test_nowrapfuncr   ~  s    
 !EEV"5'5'1EFLLNP 
	%	!!#2#=== 
&	%	%r   c           	         [        U5      nSnUR                  [        SSU SU S3R                  5       5        [        R
                  " UR                  5         [        5         [        SU S35      R                  5        nUR                  5       nSU;   d   eS	U;   d   e S
S
S
5        S
S
S
5        g
! , (       d  f       N= f! , (       d  f       g
= f)zWAdd to the include directories

CLI :: -include
TODO: Document this in the help string
r   rG   r   re   z' -include<stdbool.h> -include<stdio.h> r   r   z#include <stdbool.h>z#include <stdio.h>Nr   )rR   r5   rS   rT   r   r   ocmrs          r   test_inclheaderr     s     !EE
5'5'!HI	 
	%	BugX&',,.%::<D)T111'4/// / 
&	%.. 
&	%s$   (C!B5$C5
C	?C
Cc                      g)z7Add to the include directories

CLI :: --include-paths
Nr   r   r   r   test_inclpathr          	r   c                      g)z3Add to the include directories

CLI :: --help-link
Nr   r   r   r   
test_hlinkr     r   r   c                 j   [        U5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pESU;   d   eSU;   d   eSU;   d   eSU;   d   eSU;   d   e S	S	S	5        g	! , (       d  f       g	= f)
zGCheck that Fortran-to-Python KIND specs can be passed

CLI :: --f2cmap
rG   rH   z --f2cmap mapfilez!Reading f2cmap from 'mapfile' ...z&Mapping "real(kind=real32)" to "float"z'Mapping "real(kind=real64)" to "double"z,Mapping "integer(kind=int64)" to "long_long"z0Successfully applied user defined f2cmap changesNro   )rR   rE   rS   rT   rk   rl   s         r   test_f2cmapr     s    
 EV}UG;L%M%S%S%UV		%	!!#2c999;sBBB<CCCASHHHASHHH 
&	%	%s   AB$$
B2c                 <   [        U5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pE[        U5      S:X  d   e SSS5        g! , (       d  f       g= f)z!Reduce verbosity

CLI :: --quiet
rG   rH   z --quietr   N)
r   rJ   rK   rL   r   rM   rN   r   rh   lenrp   s         r   
test_quietr     ss    
 !EV}UG8%D%J%J%LM		%	!!#3x1}} 
&	%	%s   .B
Bc                 *   [        U5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         U R                  5       u  pESU;   d   e SSS5        g! , (       d  f       g= f)z%Increase verbosity

CLI :: --verbose
rG   rH   z
 --verboseanalyzelineNro   rp   s         r   test_verboser     sq    
 !EV}UG:%F%L%L%NO		%	!!#### 
&	%	%s   %B
Bc                 8   UR                  [        SSR                  5       5        [        R                  " [
        5         [        5         U R                  5       u  p#SSKnUR                  UR                  5       :X  d   e SSS5        g! , (       d  f       g= f)zEnsure version

CLI :: -v
rG   zf2py -vr   N)rJ   rK   rL   r   rZ   rv   r   rh   numpy__version__strip)rR   rS   rk   rl   nps        r   test_versionr     se    
 VY__%67	z	"	!!#~~,,,	 
#	"	"s    AB
Bc                    [        U 5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         [        R                  " [        R                   S35      n[        R                  " USSS9nSnUR                  U:X  d   e S	S	S	5        g	! , (       d  f       g	= f)
z
CLI :: -c
rG   rH   z -cr   Tr   r   r   N)r   rJ   rK   rL   r   rM   rN   r   r   r   r   r   r   )r5   rS   rT   r   r   r   s         r   test_npdistopr     s    
 !EV}UG3%?%E%E%GH		%	++ 00NOP~~gdWM{{d""" 
&	%	%s   AB;;
C	z*Compiler and Python 3.12 or newer requiredc                 &   [        U 5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         [        R                   S3n[        (       a  US-  nOUS-  n[        R                  " U5      n[        R                  " USSS	9nS
nUR                  U:X  d   e[        (       a  SUR                  ;   d   eUR                  S:X  d   e SSS5        g! , (       d  f       g= f)z&
CLI :: --no-freethreading-compatible
rG   rH   z! -c --no-freethreading-compatible -c "import blah; blah.hi();z1import sys; assert sys._is_gil_enabled() is True"r   Tr   r   r   zHThe global interpreter lock (GIL) has been enabled to load module 'blah'r   Nr   rJ   rK   rL   r   rM   rN   r   r   r   r   r   r   r   r   
returncoder5   rS   rT   cmdr   r   r   s          r    test_no_freethreading_compatibler    s     !EV}UG;\%]%c%c%ef		%   =>;GGC4KC++c"~~gdWM{{d""";]aealallll!### 
&	%	%s   B#D
Dc                    [        U 5      nUR                  [        SSU S3R                  5       5        [        R
                  " UR                  5         [        5         [        R                   S3n[        (       a  US-  nOUS-  n[        R                  " U5      n[        R                  " USSS	9nS
nUR                  U:X  d   eUR                  S:X  d   eUR                  S:X  d   e SSS5        g! , (       d  f       g= f)z#
CLI :: --freethreading_compatible
rG   rH   z -c --freethreading-compatibler   z2import sys; assert sys._is_gil_enabled() is False"r   Tr   r   r    r   Nr   r  s          r   test_freethreading_compatibler    s     !EV}UG;Y%Z%`%`%bc		%   =>;HHC4KC++c"~~gdWM{{d"""{{b   !### 
&	%	%s   BC77
Dc                      g)z
CLI :: -c --fcompiler
Nr   r   r   r   test_npd_fcompilerr  7      
 	r   c                      g)z
CLI :: -c --compiler
Nr   r   r   r   test_npd_compilerr  ?  r	  r   c                      g)z
CLI :: -c --help-fcompiler
Nr   r   r   r   test_npd_help_fcompilerr  G  r	  r   c                      g)z
CLI :: -c --f77exec
Nr   r   r   r   test_npd_f77execr  O  r	  r   c                      g)z
CLI :: -c --f90exec
Nr   r   r   r   test_npd_f90execr  W  r	  r   c                      g)z
CLI :: -c --f77flags
Nr   r   r   r   test_npd_f77flagsr  _  r	  r   c                      g)z
CLI :: -c --f90flags
Nr   r   r   r   test_npd_f90flagsr  g  r	  r   c                      g)z
CLI :: -c --opt
Nr   r   r   r   test_npd_optr  o  r	  r   c                      g)z
CLI :: -c --arch
Nr   r   r   r   test_npd_archr  w  r	  r   c                      g)z
CLI :: -c --noopt
Nr   r   r   r   test_npd_nooptr    r	  r   c                      g)z
CLI :: -c --noarch
Nr   r   r   r   test_npd_noarchr    r	  r   c                      g)z
CLI :: -c --debug
Nr   r   r   r   test_npd_debugr    r	  r   c                      g)z
CLI :: -c --link-<resource>
Nr   r   r   r   test_npd_link_autor!    r	  r   c                      g)z'
CLI :: -c -L/path/to/lib/ -l<libname>
Nr   r   r   r   test_npd_libr#    r	  r   c                      g)z
CLI :: -D<define>
Nr   r   r   r   test_npd_definer%    r	  r   c                      g)z
CLI :: -U<name>
Nr   r   r   r   test_npd_undefiner'    r	  r   c                      g)z
CLI :: -I/path/to/include/
Nr   r   r   r   test_npd_inclr)    r	  r   c                      g)z0
CLI :: <filename>.o <filename>.so <filename>.a
Nr   r   r   r   test_npd_linkerr+    r	  r   )untitled)Xr   r   r   rK   r   pathlibr   collectionsr   platformr   r  r   numpy.f2py.f2py2er   r   numpy.testing._private.utilsr   r   r   r!   fixturer5   r8   r:   r=   r@   rE   rW   r\   rc   rm   rq   rx   markskipifversion_infor}   systemr   xfailr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r!  r#  r%  r'  r)  r+  r   r   r   <module>r8     se   	   
   "    - 4 
HH	IN i  ! i  ! i  ! i  ! i  ! i  !(	
:)
,C C$$/8NO
) P
) X__&'1Ss7G7G77R\xyG zG> D D.D.D<%"0 .4$.N8"2"4$; 8,5$@ :  MN# O#::2> 0.		I$$- MN# O# X__&'1Qc6F6F'6QG  I$I$. X__&'1Qc6F6F'6QG  I$I$2																		r   