o
    tBh6M                     @   sH  d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	Z	ddl
mZ d dlmZ eddZdrd
dZe	jdddd Ze	jdddd Ze	jdddd Zdd Zdd Zdd Ze	jjdd Zdd Zdd Zd d! Zd"d# Zd$d% Zd&d' Z d(d) Z!d*d+ Z"d,d- Z#d.d/ Z$d0d1 Z%d2d3 Z&d4d5 Z'e	jjd6d7d8d9 Z(d:d; Z)d<d= Z*d>d? Z+d@dA Z,dBdC Z-dDdE Z.dFdG Z/dHdI Z0dJdK Z1e	jjd6d7dLdM Z2dNdO Z3dPdQ Z4dRdS Z5dTdU Z6dVdW Z7dXdY Z8dZd[ Z9d\d] Z:d^d_ Z;d`da Z<dbdc Z=ddde Z>dfdg Z?dhdi Z@djdk ZAdldm ZBdndo ZCdpdq ZDdS )s    N)Path)
namedtuple   )util)mainPPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodfuntitledc              
   C   sR   t | }t|d|d|d|| d|| d|| ddS )ax  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bpath r   s/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/numpy/f2py/tests/test_f2py2e.pyget_io_paths   s   r   session)scopec                 C   2   t dddd }|  d }|j|dd |S )z'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fnr   r   r   hello_world_f908      r+   c                 C   r   )'Generates a single f77 file for testingr   r   r   zhi77.fzhello.fr   r    r"   r'   r   r   r   hello_world_f77A   r,   r.   c                 C   r   )r-   r   r   return_realzfoo77.fzfoo.fr   r    r"   r'   r   r   r   retreal_f77J   r,   r0   c                 C   s   t |}t |jd }|tdd| d|   t|j! t  | 	 \}}d|v s0J t | 
 s9J W d   dS 1 sDw   Y  dS )zIEnsures that a signature file is generated via the CLI
    CLI :: -h
    r	   argvzf2py -h  Saving signatures to fileN)r   stemsetattrsyssplitr   	switchdirparentf2pycli
readouterrexists)capfdr+   monkeypatchipathopathout_r   r   r   test_gen_pyfS   s   "rC   c                 C   sp   t |}|tdd|   t|j t  |  \}}d|v s&J W d   dS 1 s1w   Y  dS )zHEnsures that a signature file can be dumped to stdout
    CLI :: -h
    r1   zf2py -h stdout r3   N	r   r5   r6   r7   r   r8   r9   r:   r;   r=   r+   r>   r?   rA   rB   r   r   r   test_gen_pyf_stdoutb   s   "rF   c              	   C   s   t |}|tdd|   t|j> t djddd t	t
 t  |  \}}d|v s5J W d   n1 s?w   Y  W d   dS W d   dS 1 sWw   Y  dS )	zjEnsures that the CLI refuses to overwrite signature files
    CLI :: -h without --overwrite-signature
    r1   f2py -h faker.pyf 	faker.pyf	Fake newsr   r    z&Use --overwrite-signature to overwriteN)r   r5   r6   r7   r   r8   r9   r&   pytestraises
SystemExitr:   r;   )r=   r+   r>   r?   rB   errr   r   r   test_gen_pyf_no_overwriten   s   "rN   c                 C   s   t |dd}|j}d}d}|tdd| d|   t|j4 t  | 	 \}}| D ]}	d|	 d	|v s<J q0| D ]}
d
|
 d|v sMJ qAW d   dS 1 sYw   Y  dS )z9Tests that functions can be skipped
    CLI :: skip:
    testr   t0 t4 t8 sd s8 s4td s0r1   f2py z -m test skip: z=buildmodule: Could not found the body of interfaced routine "". Skipping.Constructing wrapper function ""N
r   r   r5   r6   r7   r   r8   r9   r:   r;   )r=   r0   r>   foutlr?   toskip	remainingrA   rM   skeyrkeyr   r   r   test_f2py_skip}   s&   

"r]   c                 C   s   t |dd}|j}d}d}|tdd| d|   t|j4 t  | 	 \}}| D ]}	d|	 d	|v s<J q0| D ]}
d
|
 d|v sMJ qAW d   dS 1 sYw   Y  dS )z>Test that functions can be kept by only:
    CLI :: only:
    rO   rP   rQ   rR   r1   rS   z -m test only: <buildmodule: Could not find the body of interfaced routine "rT   rU   rV   NrW   )r=   r0   r>   rX   r?   rY   tokeeprA   rM   r[   r\   r   r   r   test_f2py_only   s&   

"r`   c                 C   s   t |dd}|j}d}t|}d}d}	|tdd| d|	 d	| d
|   t|j4 t	  | 
 \}
}| D ]}d| d|v sHJ q<| D ]}d| d|
v sYJ qMW d   dS 1 sew   Y  dS )zfTests that it is possible to return to file processing mode
    CLI :: :
    BUG: numpy-gh #20520
    rO   rP   rQ   ztd s0 hiblahr1   rS    -m z only: z : r^   rT   rU   rV   N)r   r   r   r5   r6   r7   r   r8   r9   r:   r;   )r=   r+   r0   r>   rX   r?   rY   ipath2r_   r   rA   rM   r[   r\   r   r   r   test_file_processing_switch   s,   

"rd   c                 C   s   d}t ||d}|j}|tdd| d|   t|j t  W d   n1 s.w   Y  t	
|js;J t	
|jsCJ dS )zHChecks the generation of files based on a module name
    CLI :: -m
    hirP   r1   rS   rb   N)r   r   r5   r6   r7   r   r8   r9   r:   r   r<   r   r   )r=   r+   r>   MNAMErX   r?   r   r   r   test_mod_gen_f77   s   rg   c           	      C   s$  t |dd}|j}td}td}|tdd| d  t|j	# t
  |  \}}||dus9J ||du sBJ W d   n1 sLw   Y  |tdd| d	  t|j	$ t
  |  \}}||du swJ ||dusJ W d   dS 1 sw   Y  dS )
zHLowers cases by flag or when -h is present

    CLI :: --[no-]lower
    rO   rP   zHI\(\)zhi\(\)r1   rS   z -m test --lowerNz -m test --no-lower)r   r   recompiler5   r6   r7   r   r8   r9   r:   r;   search	r=   r.   r>   rX   r?   capshicapslorA   rB   r   r   r   test_lower_cmod   s(   

"rn   c           	   	   C   s4  t |dd}|j}td}td}|tdd| d|j d  t	|j
# t  |  \}}||d	us=J ||d	u sFJ W d	   n1 sPw   Y  |tdd| d|j d
  t	|j
$ t  |  \}}||d	u sJ ||d	usJ W d	   d	S 1 sw   Y  d	S )z^Lowers cases in signature files by flag or when -h is present

    CLI :: --[no-]lower -h
    rO   rP   z	Block: HIz	Block: hir1   rS   z -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)r   r   rh   ri   r5   r6   r   r7   r   r8   r9   r:   r;   rj   rk   r   r   r   test_lower_sig   s6   

"ro   c              
   C   s   t |}d}d}|tdd| d| d|   t|j t  |  \}}d| d|v s4J W d	   d	S 1 s?w   Y  d	S )
zNEnsures that the build directory can be specified

    CLI :: --build-dir
    ra   tttmpr1   f2py -m r2   z --build-dir zWrote C/API module "rV   NrD   )r=   r+   r>   r?   r   odirrA   rB   r   r   r   test_build_dir  s   "rs   c                 C   s   t |}|tdd| d  t|j! t djddd t  | 	 \}}d|v s0J W d	   d	S 1 s;w   Y  d	S )
zXEnsures that the build directory can be specified

    CLI :: --overwrite-signature
    r1   rG   z --overwrite-signaturerH   rI   r   r    r3   N)
r   r5   r6   r7   r   r8   r9   r&   r:   r;   rE   r   r   r   test_overwrite-  s   "rt   c              	   C   s   t |}d}|tdd| d| d  t|jA t  |  \}}d|v s,J t | d	 }d|
 v s>J W d	   n1 sHw   Y  W d	   d	S W d	   d	S 1 s`w   Y  d	S )
zJEnsures that TeX documentation is written out

    CLI :: --latex-doc
    ra   r1   rq   r2   z --latex-docDocumentation is saved to file
module.tex\documentclassNr   r5   r6   r7   r   r8   r9   r:   r;   openreadr=   r+   r>   r?   r   rA   rB   otexr   r   r   test_latexdoc>  s   "r}   c              	   C   |   t |}d}|tdd| d| d  t|j t  |  \}}d|vs,J W d   dS 1 s7w   Y  dS )zMEnsures that TeX documentation is written out

    CLI :: --no-latex-doc
    ra   r1   rq   r2   z --no-latex-docru   NrD   r=   r+   r>   r?   r   rA   rB   r   r   r   test_nolatexdocP     "r   c              	   C   s   t |}d}|tdd| d| d  t|jB t  |  \}}d|v s,J t d| d	 }d	|
 vs?J W d
   n1 sIw   Y  W d
   d
S W d
   d
S 1 saw   Y  d
S )zEnsures that truncated documentation is written out

    TODO: Test to ensure this has no effect without --latex-doc
    CLI :: --latex-doc --short-latex
    ra   r1   rq   r2   z --latex-doc --short-latexru   ./rv   rw   Nrx   r{   r   r   r   test_shortlatex`  s"   "r   c              	   C   s   t |}d}|tdd| d| d  t|jB t  |  \}}d|v s,J t d| d	 }d	|
 v s?J W d
   n1 sIw   Y  W d
   d
S W d
   d
S 1 saw   Y  d
S )zIEnsures that RsT documentation is written out

    CLI :: --rest-doc
    ra   r1   rq   r2   z --rest-doc#ReST Documentation is saved to filer   zmodule.restz.. -*- rest -*-Nrx   )r=   r+   r>   r?   r   rA   rB   orstr   r   r   test_restdocv  s   "r   c              	   C   r~   )zLEnsures that TeX documentation is written out

    CLI :: --no-rest-doc
    ra   r1   rq   r2   z --no-rest-docr   NrD   r   r   r   r   test_norestexdoc  r   r   c              	   C   s   t |}d}|tdd| d| d  t|j6 t  t d| d }d|	 v s3J W d	   n1 s=w   Y  W d	   d	S W d	   d	S 1 sUw   Y  d	S )
zIEnsures that debugging wrappers are written

    CLI :: --debug-capi
    ra   r1   rq   r2   z --debug-capir   r
   z#define DEBUGCFUNCSN
r   r5   r6   r7   r   r8   r9   r:   ry   rz   )r=   r+   r>   r?   r   ocmodr   r   r   test_debugcapi  s   "r   zConsistently fails on CI.)reasonc              	   C   s   t | }d}|tdd| d| d  t|j. t  td}t	j
|ddd	}d
}td}|j|ks;J |j|ksBJ W d   dS 1 sMw   Y  dS )zEEnsures that debugging wrappers work

    CLI :: --debug-capi -c
    ra   r1   rq   r2   z -c --debug-capiz#python3 -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   r5   r6   r7   r   r8   r9   r:   shlex
subprocessruntextwrapdedentstdoutstderr)r+   r>   r?   r   cmd_runrouteouteerrr   r   r   test_debugcapi_bld  s   


"r   c              	   C   s   t |}d}|tdd| d|   t|j t  W d   n1 s)w   Y  |  \}}d|v s:J |tdd| d| d  t|j t  |  \}}d|v s`J W d   dS 1 skw   Y  dS )zoEnsures that fortran subroutine wrappers for F77 are included by default

    CLI :: --[no]-wrap-functions
    ra   r1   rq   r2   N Fortran 77 wrappers are saved toz --wrap-functionsrD   r   r   r   r   test_wrapfunc_def  s    "r   c              	   C   r~   )zeEnsures that fortran subroutine wrappers for F77 can be disabled

    CLI :: --no-wrap-functions
    ra   r1   rq   r2   z --no-wrap-functionsr   NrD   r   r   r   r   test_nowrapfunc  r   r   c              	   C   s   t |}d}|tdd| d| d  t|j> t  t d| d }|	 }d|v s5J d	|v s;J W d
   n1 sEw   Y  W d
   d
S W d
   d
S 1 s]w   Y  d
S )zcAdd to the include directories

    CLI :: -include
    TODO: Document this in the help string
    ra   r1   rq   r2   z' -include<stdbool.h> -include<stdio.h> r   r
   z#include <stdbool.h>z#include <stdio.h>Nr   )r=   r+   r>   r?   r   r   ocmrr   r   r   test_inclheader  s$   "r   c                   C      dS )z?Add to the include directories

    CLI :: --include-paths
    Nr   r   r   r   r   test_inclpath     r   c                   C   r   )z;Add to the include directories

    CLI :: --help-link
    Nr   r   r   r   r   
test_hlink  r   r   c                   C   r   )zOCheck that Fortran-to-Python KIND specs can be passed

    CLI :: --f2cmap
    Nr   r   r   r   r   test_f2cmap  r   r   c                 C   sv   t |}|tdd| d  t|j t  |  \}}t	|dks)J W d   dS 1 s4w   Y  dS )z)Reduce verbosity

    CLI :: --quiet
    r1   f2py -m blah z --quietr   N)
r   r5   r6   r7   r   r8   r9   r:   r;   lenrE   r   r   r   
test_quiet!  s   "r   c                 C   sr   t |}|tdd| d  t|j t  |  \}}d|v s'J W d   dS 1 s2w   Y  dS )z-Increase verbosity

    CLI :: --verbose
    r1   r   z
 --verboseanalyzelineNrD   rE   r   r   r   test_verbose/  s   "r   c                 C   sn   | tdd  tt t  |  \}}ddl}|j	|
 ks%J W d   dS 1 s0w   Y  dS )z"Ensure version

    CLI :: -v
    r1   zf2py -vr   N)r5   r6   r7   rJ   rK   rL   r:   r;   numpy__version__strip)r=   r>   rA   rB   npr   r   r   test_version=  s   "r   c                 C   s   t | }|tdd| d  t|j" t  td}t	j
|ddd}d}|j|ks1J W d	   d	S 1 s<w   Y  d	S )
z
    CLI :: -c
    r1   r   z -cz"python -c "import blah; blah.hi()"Tr   r   r   N)r   r5   r6   r7   r   r8   r9   r:   r   r   r   r   )r+   r>   r?   r   r   r   r   r   r   test_npdistopK  s   
"r   c                   C   r   )z
    CLI :: -c --fcompiler
    Nr   r   r   r   r   test_npd_fcompiler_     r   c                   C   r   )z
    CLI :: -c --compiler
    Nr   r   r   r   r   test_npd_compilerg  r   r   c                   C   r   )z$
    CLI :: -c --help-fcompiler
    Nr   r   r   r   r   test_npd_help_fcompilero  r   r   c                   C   r   )z
    CLI :: -c --f77exec
    Nr   r   r   r   r   test_npd_f77execw  r   r   c                   C   r   )z
    CLI :: -c --f90exec
    Nr   r   r   r   r   test_npd_f90exec  r   r   c                   C   r   )z
    CLI :: -c --f77flags
    Nr   r   r   r   r   test_npd_f77flags  r   r   c                   C   r   )z
    CLI :: -c --f90flags
    Nr   r   r   r   r   test_npd_f90flags  r   r   c                   C   r   )z
    CLI :: -c --opt
    Nr   r   r   r   r   test_npd_opt  r   r   c                   C   r   )z
    CLI :: -c --arch
    Nr   r   r   r   r   test_npd_arch  r   r   c                   C   r   )z
    CLI :: -c --noopt
    Nr   r   r   r   r   test_npd_noopt  r   r   c                   C   r   )z
    CLI :: -c --noarch
    Nr   r   r   r   r   test_npd_noarch  r   r   c                   C   r   )z
    CLI :: -c --debug
    Nr   r   r   r   r   test_npd_debug  r   r   c                   C   r   )z%
    CLI :: -c --link-<resource>
    Nr   r   r   r   r   test_npd_link_auto  r   r   c                   C   r   )z/
    CLI :: -c -L/path/to/lib/ -l<libname>
    Nr   r   r   r   r   test_npd_lib  r   r   c                   C   r   )z
    CLI :: -D<define>
    Nr   r   r   r   r   test_npd_define  r   r   c                   C   r   )z
    CLI :: -U<name>
    Nr   r   r   r   r   test_npd_undefine  r   r   c                   C   r   )z$
    CLI :: -I/path/to/include/
    Nr   r   r   r   r   test_npd_incl  r   r   c                   C   r   )z8
    CLI :: <filename>.o <filename>.so <filename>.a
    Nr   r   r   r   r   test_npd_linker  r   r   )r   )Er   rh   r6   r   r   pathlibr   collectionsr   rJ    r   numpy.f2py.f2py2er   r:   r   r   fixturer+   r.   r0   rC   rF   rN   markxfailr]   r`   rd   rg   rn   ro   rs   rt   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>   s~   ( 


'





'
			
