HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/numpy/f2py/tests/__pycache__/test_f2py2e.cpython-310.pyc
o

���gOc�@sddlZddlZddlZddlZddlZddlmZddlmZddl	Z	ddl
Z
ddlmZddl
mZedd�Zd�d
d�Ze
jdd
�dd��Ze
jdd
�dd��Ze
jdd
�dd��Ze
jdd
�dd��Ze
jdd
�dd��Ze
jdd
�dd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Ze
jj e	�!�d&kp�ej"d'kd(d)�d*d+��Z#e
jj e	�!�d&kp�ej"d'kd(d)�d,d-��Z$e
jj%d.d/��Z&d0d1�Z'd2d3�Z(d4d5�Z)d6d7�Z*d8d9�Z+d:d;�Z,d<d=�Z-d>d?�Z.d@dA�Z/dBdC�Z0dDdE�Z1dFdG�Z2dHdI�Z3dJdK�Z4e
jj%dLd)�dMdN��Z5dOdP�Z6dQdR�Z7dSdT�Z8dUdV�Z9dWdX�Z:dYdZ�Z;d[d\�Z<d]d^�Z=d_d`�Z>e
jj%dLd)�dadb��Z?dcdd�Z@dedf�ZAdgdh�ZBdidj�ZCdkdl�ZDdmdn�ZEdodp�ZFdqdr�ZGdsdt�ZHdudv�ZIdwdx�ZJdydz�ZKd{d|�ZLd}d~�ZMdd��ZNd�d��ZOd�d��ZPd�d��ZQdS)��N)�Path)�
namedtuple�)�util)�main�PPathsz(finp, f90inp, pyf, wrap77, wrap90, cmodf�untitledc
CsRt|�}t|�d�|�d�|�d�|�|�d��|�|�d��|�|�d��d�S)axTakes 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)rr�with_suffix�	with_name)�	fname_inp�mname�bpath�r�G/usr/local/lib/python3.10/dist-packages/numpy/f2py/tests/test_f2py2e.py�get_io_pathss�r�session)�scopecC�2t�dddd���}|��d}|j|dd�|S)�'Generates a single f90 file for testing�tests�src�clizhiworld.f90z	hello.f90�ascii��encoding�r�getpath�	read_text�getbasetemp�
write_text��tmpdir_factory�fdat�fnrrr�hello_world_f909�r,cC�2t�dddd���}|��d}|j|dd�|S)z(F90 file for testing warnings in gh23598rr�crackfortranzgh23598Warn.f90r r!r#r(rrr�gh23598_warnBr-r0cCr.)z8F90 file for testing disallowed CLI arguments in ghff819rrrzgh_22819.pyfr r!r#r(rrr�gh22819_cliKr-r1cCr)�'Generates a single f77 file for testingrrrzhi77.fzhello.fr r!r#r(rrr�hello_world_f77Tr-r3cCr)r2rr�return_realzfoo77.fzfoo.fr r!r#r(rrr�retreal_f77]r-r5cCs`t�dddd���}t�dddd���}|��d}|��d}|j|dd	�|j|dd	�|S)
rrr�f2cmapzisoFortranEnvMap.f90z.f2py_f2cmapz
f2cmap.f90�mapfiler r!r#)r)r*r6r+�fmaprrr�
f2cmap_f90esr9cCs�t|�}|�tdd|�����t�|j��0t�dd�|j�d�D�}d|vs+J�d|vs1J�d|vs7J�d	|vs=J�	Wd�dS1sIwYdS)z�Check 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 cSsg|]	}|��r|j�qSr)�is_file�name)�.0�itemrrr�
<listcomp>}sz$test_gh22819_cli.<locals>.<listcomp>�*zblahmodule.czblah-f2pywrappers.fztest_22819-f2pywrappers.fztest_22819module.cz
Ignoring blahN)	r�setattr�sys�splitr�	switchdir�parent�f2pycli�rglob)�capfdr1�monkeypatch�ipath�	gen_pathsrrr�test_gh22819_cliqs"�rMc	Cs�t|�}|�tdd|�d����t�|j��+tjt	dd��t
�Wd�n1s-wYWd�dSWd�dS1sEwYdS)zBOnly one .pyf file allowed
    gh-22819
    CLI :: .pyf files
    r:r;z
 hello.pyfzOnly one .pyf file per call)�matchN)rrBrCrDrrErF�pytest�raises�
ValueErrorrG)rIr1rJrKrrr�test_gh22819_many_pyf�s��"�rRcCszt|dd�}|j}|�tdd|�d����t�|j��t�|j	�
�}d|vs+J�Wd�dS1s6wYdS)N�test�rr:�f2py z -m testzintproductf2pywrap, intpr)rrrBrCrDrrErFrGrr%)rIr0rJ�foutlrK�wrapperrrr�test_gh23598_warn�s�
"�rXcCs�t|�}t|�jd}|�tdd|�d|�����t�|j��!t�|�	�\}}d|vs0J�t|���
�s9J�Wd�dS1sDwYdS)zIEnsures that a signature file is generated via the CLI
    CLI :: -h
    r	r:zf2py -h � �Saving signatures to fileN)r�stemrBrCrDrrErFrG�
readouterr�exists)rIr,rJrK�opath�out�_rrr�test_gen_pyf�s"�racCs|t|�}|�tdd|�����t�|j��t�|��\}}d|vs&J�d|vs,J�Wd�dS1s7wYdS)zHEnsures that a signature file can be dumped to stdout
    CLI :: -h
    r:zf2py -h stdout rZzfunction hi() ! in N�	rrBrCrDrrErFrGr\�rIr,rJrKr_r`rrr�test_gen_pyf_stdout�s"�rdc	Cs�t|�}|�tdd|�����t�|j��>td�jddd�t�	t
��t�|��\}}d|vs5J�Wd�n1s?wYWd�dSWd�dS1sWwYdS)	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)
rrBrCrDrrErFr'rOrP�
SystemExitrGr\)rIr,rJrKr`�errrrr�test_gen_pyf_no_overwrite�s��"�rj�Linux)��zCompiler and 3.12 required)�reasoncCspt|�}|�tdd|�����t�|j��t�|��\}}d|vs&J�Wd�dS1s1wYdS)z@Check that modules are named correctly

    CLI :: defaults
    r:zf2py --backend meson -c zuntitledmodule.cNrbrcrrr�test_untitled_cli�s"�roc	CsNd}t||d�}|j}|�tdd|�d|�����t�|j��t�|�	�\}}d|vs0J�Wd�n1s:wY|�tdd���t�|j��t�|�	�\}}d	|vs^J�Wd�n1shwYd
}|�tdd|�d|�d����t�|j��t�|�	�\}}d
|vs�J�Wd�dS1s�wYdS)zqCheck that no distutils imports are performed on 3.12
    CLI :: --fcompiler --help-link --backend distutils
    �hirTr:rUz -c --fcompiler=gfortran -m z%--fcompiler cannot be used with mesonNzf2py --help-linkzUse --dep for meson builds�hi2z -c -m z --backend distutilsz.Cannot use distutils backend with Python>=3.12)
rrrBrCrDrrErFrGr\)rIr,rJ�MNAMErVrKr_r`rrr�!test_no_py312_distutils_fcompiler�s8��
���"�rscCs�t|dd�}|j}d}d}|�tdd|�d|�����t�|j��4t�|�	�\}}|��D]}	d|	�d	�|vs<J�q0|��D]}
d
|
�d�|vsMJ�qAWd�dS1sYwYdS)
z9Tests that functions can be skipped
    CLI :: skip:
    rSrT�t0 t4 t8 sd s8 s4�td s0r:rUz -m test skip: z=buildmodule: Could not found the body of interfaced routine "�". Skipping.�Constructing wrapper function "�"N�
rrrBrCrDrrErFrGr\)rIr5rJrVrK�toskip�	remainingr_ri�skey�rkeyrrr�test_f2py_skip�s&�

��"�r~cCs�t|dd�}|j}d}d}|�tdd|�d|�����t�|j��4t�|�	�\}}|��D]}	d|	�d	�|vs<J�q0|��D]}
d
|
�d�|vsMJ�qAWd�dS1sYwYdS)
z>Test that functions can be kept by only:
    CLI :: only:
    rSrTrtrur:rUz -m test only: �<buildmodule: Could not find the body of interfaced routine "rvrwrxNry)rIr5rJrVrKrz�tokeepr_rir|r}rrr�test_f2py_onlys&�

��"�r�cCs�t|dd�}|j}d}t|�}d}d}	|�tdd|�d|	�d	|�d
|�����t�|j��4t	�|�
�\}
}|��D]}d|�d�|vsHJ�q<|��D]}
d
|
�d�|
vsYJ�qMWd�dS1sewYdS)zfTests that it is possible to return to file processing mode
    CLI :: :
    BUG: numpy-gh #20520
    rSrTrtztd s0 hi�blahr:rU� -m z only: z : rrvrwrxN)rrrrBrCrDrrErFrGr\)rIr,r5rJrVrKrz�ipath2r�rr_rir|r}rrr�test_file_processing_switch's,�

��"�r�cCs�d}t||d�}|j}|�tdd|�d|�����t�|j��t�Wd�n1s.wYt	�
|j�s;J�t	�
|j�sCJ�dS)zHChecks the generation of files based on a module name
    CLI :: -m
    rprTr:rUr�N)
rrrBrCrDrrErFrGrr]rr)rIr,rJrrrVrKrrr�test_mod_gen_f77Es�r�c	Cs�d}t||d�}|j}|�tdd|�d|�d����t�|j��4t�t	d��
��}|��}d|vs6J�Wd	�n1s@wYWd	�d	SWd	�d	S1sXwYd	S)
z�Check that pyf files are correctly generated with module structure
    CLI :: -m <name> -h pyf_file
    BUG: numpy-gh #20520
    rprTr:rUr�z
 -h hi.pyfzhi.pyfzpython module hiN)rrrBrCrDrrErFrGr�open�read)rIr3rJrrrVrK�hipyf�pyfdatrrr�test_mod_gen_gh25263Vs ��"�r�c	Cs$t|dd�}|j}t�d�}t�d�}|�tdd|�d����t�|j	��#t
�|��\}}|�|�dus9J�|�|�dusBJ�Wd�n1sLwY|�tdd|�d	����t�|j	��$t
�|��\}}|�|�duswJ�|�|�dus�J�Wd�dS1s�wYdS)
zHLowers cases by flag or when -h is present

    CLI :: --[no-]lower
    rSrTzHI\(\)zhi\(\)r:rUz -m test --lowerNz -m test --no-lower)
rr�re�compilerBrCrDrrErFrGr\�search�	rIr3rJrVrK�capshi�capslor_r`rrr�test_lower_cmodfs(

��"�r�c		Cs4t|dd�}|j}t�d�}t�d�}|�tdd|�d|j�d����t�	|j
��#t�|��\}}|�
|�d	us=J�|�
|�d	usFJ�Wd	�n1sPwY|�tdd|�d|j�d
����t�	|j
��$t�|��\}}|�
|�d	usJ�|�
|�d	us�J�Wd	�d	S1s�wYd	S)z^Lowers cases in signature files by flag or when -h is present

    CLI :: --[no-]lower -h
    rSrTz	Block: HIz	Block: hir:rUz -h z -m test --overwrite-signatureNz) -m test --overwrite-signature --no-lower)rrr�r�rBrCr
rDrrErFrGr\r�r�rrr�test_lower_sig�s6

���"�r�c
Cs�t|�}d}d}|�tdd|�d|�d|�����t�|j��t�|��\}}d|�d�|vs4J�Wd	�d	S1s?wYd	S)
zNEnsures that the build directory can be specified

    CLI :: --build-dir
    r��tttmpr:�f2py -m rYz
 --build-dir zWrote C/API module "rxNrb)rIr,rJrKr�odirr_r`rrr�test_build_dir�s�"�r�cCs�t|�}|�tdd|�d����t�|j��!td�jddd�t�|�	�\}}d|vs0J�Wd	�d	S1s;wYd	S)
zXEnsures that the build directory can be specified

    CLI :: --overwrite-signature
    r:rez --overwrite-signaturerfrgr r!rZN)
rrBrCrDrrErFr'rGr\rcrrr�test_overwrite�s�"�r�c	Cs�t|�}d}|�tdd|�d|�d����t�|j��At�|��\}}d|vs,J�t|�d���	��}d|�
�vs>J�Wd	�n1sHwYWd	�d	SWd	�d	S1s`wYd	S)
zJEnsures that TeX documentation is written out

    CLI :: --latex-doc
    r�r:r�rYz --latex-doc�Documentation is saved to file�
module.tex�\documentclassN�rrBrCrDrrErFrGr\r�r��rIr,rJrKrr_r`�otexrrr�
test_latexdoc�s���"�r�c	C�|t|�}d}|�tdd|�d|�d����t�|j��t�|��\}}d|vs,J�Wd�dS1s7wYdS)zMEnsures that TeX documentation is written out

    CLI :: --no-latex-doc
    r�r:r�rYz --no-latex-docr�Nrb�rIr,rJrKrr_r`rrr�test_nolatexdoc���"�r�c	Cs�t|�}d}|�tdd|�d|�d����t�|j��Bt�|��\}}d|vs,J�td|�d���	��}d	|�
�vs?J�Wd
�n1sIwYWd
�d
SWd
�d
S1sawYd
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
    r�r:r�rYz --latex-doc --short-latexr��./r�r�Nr�r�rrr�test_shortlatex�s"���"�r�c	Cs�t|�}d}|�tdd|�d|�d����t�|j��Bt�|��\}}d|vs,J�td|�d���	��}d	|�
�vs?J�Wd
�n1sIwYWd
�d
SWd
�d
S1sawYd
S)zIEnsures that RsT documentation is written out

    CLI :: --rest-doc
    r�r:r�rYz --rest-doc�#ReST Documentation is saved to filer�zmodule.restz.. -*- rest -*-Nr�)rIr,rJrKrr_r`�orstrrr�test_restdocs���"�r�c	Cr�)zLEnsures that TeX documentation is written out

    CLI :: --no-rest-doc
    r�r:r�rYz --no-rest-docr�Nrbr�rrr�test_norestexdocr�r�c	Cs�t|�}d}|�tdd|�d|�d����t�|j��6t�td|�d�����}d|�	�vs3J�Wd	�n1s=wYWd	�d	SWd	�d	S1sUwYd	S)
zIEnsures that debugging wrappers are written

    CLI :: --debug-capi
    r�r:r�rYz
 --debug-capir�r
z#define DEBUGCFUNCSN�
rrBrCrDrrErFrGr�r�)rIr,rJrKr�ocmodrrr�test_debugcapi#s���"�r�zConsistently fails on CI.c	Cs�t|�}d}|�tdd|�d|�d����t�|j��.t�t�d�}t	j
|ddd	�}d
}t�d�}|j
|ks;J�|j|ksBJ�Wd�dS1sMwYdS)
zEEnsures that debugging wrappers work

    CLI :: --debug-capi -c
    r�r:r�rYz -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)rrBrCrDrrErFrG�shlex�
subprocess�run�textwrap�dedent�stdout�stderr)r,rJrKr�cmd_run�rout�eout�eerrrrr�test_debugcapi_bld3s�


"�r�c	Cs�t|�}d}|�tdd|�d|�����t�|j��t�Wd�n1s)wY|��\}}d|vs:J�|�tdd|�d|�d����t�|j��t�|��\}}d|vs`J�Wd�dS1skwYdS)zoEnsures that fortran subroutine wrappers for F77 are included by default

    CLI :: --[no]-wrap-functions
    r�r:r�rYN� Fortran 77 wrappers are saved toz --wrap-functionsrbr�rrr�test_wrapfunc_defQs ��"�r�c	Cr�)zeEnsures that fortran subroutine wrappers for F77 can be disabled

    CLI :: --no-wrap-functions
    r�r:r�rYz --no-wrap-functionsr�Nrbr�rrr�test_nowrapfuncjr�r�c	Cs�t|�}d}|�tdd|�d|�d����t�|j��>t�td|�d�����}|�	�}d|vs5J�d	|vs;J�Wd
�n1sEwYWd
�d
SWd
�d
S1s]wYd
S)zcAdd to the include directories

    CLI :: -include
    TODO: Document this in the help string
    r�r:r�rYz' -include<stdbool.h> -include<stdio.h> r�r
z#include <stdbool.h>z#include <stdio.h>Nr�)rIr,rJrKrr��ocmrrrr�test_inclheaderzs$���"�r�cC�dS)z?Add to the include directories

    CLI :: --include-paths
    Nrrrrr�
test_inclpath��r�cCr�)z;Add to the include directories

    CLI :: --help-link
    Nrrrrr�
test_hlink�r�r�cCs�t|�}|�tdd|�d����t�|j��0t�|��\}}d|vs'J�d|vs-J�d|vs3J�d|vs9J�d|vs?J�Wd	�d	S1sJwYd	S)
zOCheck that Fortran-to-Python KIND specs can be passed

    CLI :: --f2cmap
    r:r;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 changesNrb)rIr9rJrKr_r`rrr�test_f2cmap�s"�r�cCsvt|�}|�tdd|�d����t�|j��t�|��\}}t	|�dks)J�Wd�dS1s4wYdS)z)Reduce verbosity

    CLI :: --quiet
    r:r;z --quietrN)
rrBrCrDrrErFrGr\�lenrcrrr�
test_quiet�s"�r�cCsrt|�}|�tdd|�d����t�|j��t�|��\}}d|vs'J�Wd�dS1s2wYdS)z-Increase verbosity

    CLI :: --verbose
    r:r;z
 --verbose�analyzelineNrbrcrrr�test_verbose�s"�r�cCsn|�tdd���t�t��t�|��\}}ddl}|j	|�
�ks%J�Wd�dS1s0wYdS)z"Ensure version

    CLI :: -v
    r:zf2py -vrN)rBrCrDrOrPrhrGr\�numpy�__version__�strip)rIrJr_r`�nprrr�test_version�s"�r�cCs�t|�}|�tdd|�d����t�|j��"t�t�d�}t	j
|ddd�}d}|j|ks1J�Wd	�d	S1s<wYd	S)
z
    CLI :: -c
    r:r;z -cz"python -c "import blah; blah.hi()"Tr�r�r�N)rrBrCrDrrErFrGr�r�r�r�)r,rJrKr�r�r�rrr�
test_npdistop�s
"�r�cCr�)z
    CLI :: -c --fcompiler
    Nrrrrr�test_npd_fcompiler��r�cCr�)z
    CLI :: -c --compiler
    Nrrrrr�test_npd_compiler�r�r�cCr�)z$
    CLI :: -c --help-fcompiler
    Nrrrrr�test_npd_help_fcompilerr�r�cCr�)z
    CLI :: -c --f77exec
    Nrrrrr�test_npd_f77execr�r�cCr�)z
    CLI :: -c --f90exec
    Nrrrrr�test_npd_f90execr�r�cCr�)z
    CLI :: -c --f77flags
    Nrrrrr�test_npd_f77flagsr�r�cCr�)z
    CLI :: -c --f90flags
    Nrrrrr�test_npd_f90flags#r�r�cCr�)z
    CLI :: -c --opt
    Nrrrrr�test_npd_opt+r�r�cCr�)z
    CLI :: -c --arch
    Nrrrrr�
test_npd_arch3r�r�cCr�)z
    CLI :: -c --noopt
    Nrrrrr�test_npd_noopt;r�r�cCr�)z
    CLI :: -c --noarch
    Nrrrrr�test_npd_noarchCr�r�cCr�)z
    CLI :: -c --debug
    Nrrrrr�test_npd_debugKr�r�cCr�)z%
    CLI :: -c --link-<resource>
    Nrrrrr�test_npd_link_autoSr�r�cCr�)z/
    CLI :: -c -L/path/to/lib/ -l<libname>
    Nrrrrr�test_npd_lib[r�r�cCr�)z
    CLI :: -D<define>
    Nrrrrr�test_npd_definecr�r�cCr�)z
    CLI :: -U<name>
    Nrrrrr�test_npd_undefinekr�r�cCr�)z$
    CLI :: -I/path/to/include/
    Nrrrrr�
test_npd_inclsr�r�cCr�)z8
    CLI :: <filename>.o <filename>.so <filename>.a
    Nrrrrr�test_npd_linker{r�r�)r)Rr�r�rCr�r��pathlibr�collectionsr�platformrO�r�numpy.f2py.f2py2errGrr�fixturer,r0r1r3r5r9rMrRrXrardrj�mark�skipif�system�version_inforors�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�rrrr�<module>s�(


'












�
 

'