o
    U=ºi"P  ã                   @   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Úwrap77Zwrap90ÚcmodfN)r   r   Úwith_suffixÚ	with_name)Z	fname_inpÚmnameÚbpath© r   úbC:\Users\psant\Downloads\PAF backend\school\venv\Lib\site-packages\numpy/f2py/tests/test_f2py2e.pyÚget_io_paths   s   úr   Úsession)Z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©ÚencodingN©r   ZgetpathÚ	read_textZgetbasetempÚ
write_text©Ztmpdir_factoryZ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   Nr   r"   r   r   r   Úhello_world_f77A   r%   r'   c                 C   r   )	r&   r   r   Zreturn_realzfoo77.fzfoo.fr   r   Nr   r"   r   r   r   Úretreal_f77J   r%   r(   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ÚipathZopathÚoutÚ_r   r   r   Útest_gen_pyfS   s   "ür:   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
    r)   zf2py -h stdout r+   N©	r   r-   r.   r/   r   r0   r1   r2   r3   ©r5   r$   r6   r7   r8   r9   r   r   r   Útest_gen_pyf_stdoutb   s   "ýr=   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
    r)   úf2py -h faker.pyf ú	faker.pyfú	Fake newsr   r   z&Use --overwrite-signature to overwriteN)r   r-   r.   r/   r   r0   r1   r!   ÚpytestÚraisesÚ
SystemExitr2   r3   )r5   r$   r6   r7   r9   Úerrr   r   r   Útest_gen_pyf_no_overwriten   s   ýþ"þrE   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 s0r)   úf2py z -m test skip: z=buildmodule: Could not found the body of interfaced routine "ú". Skipping.úConstructing wrapper function "ú"N©
r   r   r-   r.   r/   r   r0   r1   r2   r3   )r5   r(   r6   Úfoutlr7   ÚtoskipÚ	remainingr8   rD   ÚskeyÚrkeyr   r   r   Útest_f2py_skip}   s(   þ
ÿÿÿ"ùrT   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:
    rF   rG   rH   rI   r)   rJ   z -m test only: ú<buildmodule: Could not find the body of interfaced routine "rK   rL   rM   NrN   )r5   r(   r6   rO   r7   rP   Útokeepr8   rD   rR   rS   r   r   r   Útest_f2py_only•   s(   þ
ÿÿÿ"ùrW   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
    rF   rG   rH   ztd s0 hiÚblahr)   rJ   ú -m z only: z : rU   rK   rL   rM   N)r   r   r   r-   r.   r/   r   r0   r1   r2   r3   )r5   r$   r(   r6   rO   r7   rP   Zipath2rV   r   r8   rD   rR   rS   r   r   r   Útest_file_processing_switch¬   s.   ý
ÿÿÿ"ùrZ   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
    ÚhirG   r)   rJ   rY   N)r   r   r-   r.   r/   r   r0   r1   r2   r   r4   r   r   )r5   r$   r6   ZMNAMErO   r7   r   r   r   Útest_mod_gen_f77Ê   s   ÿr\   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s€J ‚W d  ƒ dS 1 s‹w   Y  dS )
zHLowers cases by flag or when -h is present

    CLI :: --[no-]lower
    rF   rG   zHI\(\)zhi\(\)r)   rJ   z -m test --lowerNz -m test --no-lower)r   r   ÚreÚcompiler-   r.   r/   r   r0   r1   r2   r3   Úsearch©	r5   r'   r6   rO   r7   ZcapshiZcapslor8   r9   r   r   r   Útest_lower_cmodÛ   s(   

üÿ"üra   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sˆJ ‚W d	  ƒ d	S 1 s“w   Y  d	S )z^Lowers cases in signature files by flag or when -h is present

    CLI :: --[no-]lower -h
    rF   rG   z	Block: HIz	Block: hir)   rJ   z -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)r   r   r]   r^   r-   r.   r   r/   r   r0   r1   r2   r3   r_   r`   r   r   r   Útest_lower_sigõ   s6   

ýüü"ürb   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
    rX   Ztttmpr)   úf2py -m r*   z --build-dir zWrote C/API module "rM   Nr;   )r5   r$   r6   r7   r   Zodirr8   r9   r   r   r   Útest_build_dir  s   ÿ"ýrd   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
    r)   r>   z --overwrite-signaturer?   r@   r   r   r+   N)
r   r-   r.   r/   r   r0   r1   r!   r2   r3   r<   r   r   r   Útest_overwrite-  s   þ"üre   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
    rX   r)   rc   r*   z --latex-docúDocumentation is saved to fileú
module.texú\documentclassN©r   r-   r.   r/   r   r0   r1   r2   r3   ÚopenÚread©r5   r$   r6   r7   r   r8   r9   Zotexr   r   r   Útest_latexdoc>  s   ÿÿü"ürm   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
    rX   r)   rc   r*   z --no-latex-docrf   Nr;   ©r5   r$   r6   r7   r   r8   r9   r   r   r   Útest_nolatexdocP  ó   ÿ"ýrp   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 )zžEnsures that truncated documentation is written out

    TODO: Test to ensure this has no effect without --latex-doc
    CLI :: --latex-doc --short-latex
    rX   r)   rc   r*   z --latex-doc --short-latexrf   ú./rg   rh   Nri   rl   r   r   r   Útest_shortlatex`  s"   ýÿü"ürs   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
    rX   r)   rc   r*   z --rest-docú#ReST Documentation is saved to filerr   zmodule.restz.. -*- rest -*-Nri   )r5   r$   r6   r7   r   r8   r9   Zorstr   r   r   Útest_restdocv  s   ÿÿü"üru   c              	   C   rn   )zLEnsures that TeX documentation is written out

    CLI :: --no-rest-doc
    rX   r)   rc   r*   z --no-rest-docrt   Nr;   ro   r   r   r   Útest_norestexdocˆ  rq   rv   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
    rX   r)   rc   r*   z --debug-capirr   r
   z#define DEBUGCFUNCSN©
r   r-   r.   r/   r   r0   r1   r2   rj   rk   )r5   r$   r6   r7   r   Úocmodr   r   r   Útest_debugcapi˜  s   ÿÿþ"þry   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
    rX   r)   rc   r*   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   r-   r.   r/   r   r0   r1   r2   ÚshlexÚ
subprocessÚrunÚtextwrapÚdedentÚstdoutÚstderr)r$   r6   r7   r   Úcmd_runÚroutÚeoutZ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
    rX   r)   rc   r*   Nú Fortran 77 wrappers are saved toz --wrap-functionsr;   ro   r   r   r   Útest_wrapfunc_defÆ  s    ÿÿ"ýr‹   c              	   C   rn   )zeEnsures that fortran subroutine wrappers for F77 can be disabled

    CLI :: --no-wrap-functions
    rX   r)   rc   r*   z --no-wrap-functionsrŠ   Nr;   ro   r   r   r   Útest_nowrapfuncß  rq   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
    rX   r)   rc   r*   z' -include<stdbool.h> -include<stdio.h> rr   r
   z#include <stdbool.h>z#include <stdio.h>Nrw   )r5   r$   r6   r7   r   rx   Z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
    r)   úf2py -m blah z --quietr   N)
r   r-   r.   r/   r   r0   r1   r2   r3   Úlenr<   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
    r)   r“   z
 --verboseZanalyzelineNr;   r<   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
    r)   zf2py -vr   N)r-   r.   r/   rA   rB   rC   r2   r3   ZnumpyÚ__version__Ústrip)r5   r6   r8   r9   Ú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
    r)   r“   z -cz"python -c "import blah; blah.hi()"Tr{   r|   r~   N)r   r-   r.   r/   r   r0   r1   r2   r   r€   r�   r„   )r$   r6   r7   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‚   r]   r.   r€   r   Úpathlibr   Úcollectionsr   rA   Ú r   Znumpy.f2py.f2py2er   r2   r   r   Zfixturer$   r'   r(   r:   r=   rE   ÚmarkZxfailrT   rW   rZ   r\   ra   rb   rd   re   rm   rp   rs   ru   rv   ry   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~   ( 


'





'
			
