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_callback.cpython-310.pyc
o

���g^�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddlmZGdd�dej
�ZGdd�de�ZGd	d
�d
ej
�ZGdd�dej
�ZGd
d�dej
�ZdS)�N)�IS_PYPY�)�utilc@s�eZdZe�dddd�gZej�dd�	d��dd	��Z
ejjed
d�dd
��Z
dd�Zejjejdkdd�dd��Zejjejdkdd�dd��Zdd�Zdd�ZdS)�TestF77Callback�tests�src�callbackzfoo.f�namezt,t2�,cCs|�|�dS�N)�check_function)�selfr	�r�I/usr/local/lib/python3.10/dist-packages/numpy/f2py/tests/test_callback.py�test_allszTestF77Callback.test_allz,PyPy cannot modify tp_doc after PyType_Ready)�reasoncCs t�d�}|jjj|ksJ�dS)Na�        a = t(fun,[fun_extra_args])

        Wrapper for ``t``.

        Parameters
        ----------
        fun : call-back function

        Other Parameters
        ----------------
        fun_extra_args : input tuple, optional
            Default: ()

        Returns
        -------
        a : int

        Notes
        -----
        Call-back functions::

            def fun(): return a
            Return objects:
                a : int
        )�textwrap�dedent�module�t�__doc__)r
�expectedrrr�test_docstrings
zTestF77Callback.test_docstringcCsFt|j|�}|dd��}|dksJ�|dd�dd�}|dks J�|dd�dd�}|d	ks.J�|d
d�dd�}|dks<J�|d
d�tjfd�}|dksLJ�|tjtjfd�}|dks[J�||jjdd�}|dksiJ�||jj�}|dksuJ�||jjj�}|dks�J�Gdd�d�}|�}||�}|dks�J�||j�}|dks�J�dS)NcS�dS)N�rrrrr�<lambda>6�z0TestF77Callback.check_function.<locals>.<lambda>rcSr�N�r��arrrr8r)�)�fun_extra_argsrcSs|Srrrrrrr:rr!cSsd|Srrrrrrr<�)��cSs
t�|�Sr)�math�degreesrrrrr>s
���c@seZdZdd�Zdd�ZdS)z)TestF77Callback.check_function.<locals>.AcSr)Nr$r�r
rrr�__call__K�z2TestF77Callback.check_function.<locals>.A.__call__cSr)N�	rr+rrr�mthNr-z-TestF77Callback.check_function.<locals>.A.mthN)�__name__�
__module__�__qualname__r,r/rrrr�AJsr3r$r.)	�getattrrr&�pir'�func�func0�	_cpointerr/)r
r	r�rr3r rrrr4s2
zTestF77Callback.check_function�win32z)Fails with MinGW64 Gfortran (Issue #9673)cCs,dd�}t|jd�}||�}|dksJ�dS)NcSs|dkrdSdS)Nr9rrr)�coderrrrZsz6TestF77Callback.test_string_callback.<locals>.callback�string_callbackr)r4r)r
r�fr9rrr�test_string_callbackWsz$TestF77Callback.test_string_callbackcCsht�dd�}t�dd�}t�dgd�}dd�}t|jd�}|||fD]}||||j�}|d	ks1J�q"dS)
N)r�S8)r��c�cSs4|j|fkrdS|jdkrdSt�|dk�sdSdS)Nrr?���r)�shape�dtype�np�all)�cu�lencurrrrls
z<TestF77Callback.test_string_callback_array.<locals>.callback�string_callback_arrayr)rH�zeros�arrayr4r�size)r
�cu1�cu2�cu3rr=rJ�resrrr�test_string_callback_arrayds	�z*TestF77Callback.test_string_callback_arraycspg��fdd�����fdd���fdd�dD�}|D]}|��q|D]}|��q$d�����r6t���dS)	Ncs*t�d��j�dd��}|dksJ�dS)Ng����MbP?cSr�N�{rrrrrr�rz?TestF77Callback.test_threadsafety.<locals>.cb.<locals>.<lambda>rV�*)�time�sleeprr)r9r+rr�cbs
z-TestF77Callback.test_threadsafety.<locals>.cbcsZztd�D]}�j���}|dksJ���|�qWdSty,��t���YdSw)N�2rW)�rangerrr�	Exception�append�	traceback�
format_exc)r	�jr9)rZ�errorsr
rr�runner�s��z1TestF77Callback.test_threadsafety.<locals>.runnercs*g|]}td�D]
}tj�|fd��qqS)�)�target�args)r\�	threading�Thread)�.0�arg�n)rcrr�
<listcomp>�s���z5TestF77Callback.test_threadsafety.<locals>.<listcomp>)r�t2z

)�start�join�AssertionError)r
�threadsrr)rZrbrcr
r�test_threadsafetyzs
	�


�z!TestF77Callback.test_threadsafetyc
Cshz|j�d�Wnty#}zt|��d�sJ�WYd}~nd}~wwz|j�d�WntyG}zt|��d�s=J�WYd}~nd}~wwdd�|j_|j�d�}|dksZJ�dd�|j_|j�d�}|dkslJ�|j`z|j�d�Wnty�}zt|��d�s�J�WYd}~nd}~wwdd
d�|j_|j�d�}|dks�J�|j�d�}|dks�J�dS)
NrCzCallback global_f not definedz!cb: Callback global_f not definedcS�|dS)Nrr��xrrrr�r#z6TestF77Callback.test_hidden_callback.<locals>.<lambda>rEcSrs)NrCrrtrrrr�r#rrcSrs)NrErrtrrrr�r#r)r)r�hidden_callbackr]�str�
startswith�hidden_callback2�global_f)r
�msgr9rrr�test_hidden_callback�s<������z$TestF77Callback.test_hidden_callbackN)r0r1r2r�getpath�sources�pytest�mark�parametrize�splitr�xfailrrr�skipif�sys�platformr>rTrrr|rrrrrs&
�
#�
�
(rc@seZdZdZdgZdS)�TestF77CallbackPythonTLSz[
    Callback tests using Python thread-local storage instead of
    compiler-provided
    z-DF2PY_USE_PYTHON_TLSN)r0r1r2r�optionsrrrrr��s
r�c@s&eZdZe�dddd�gZdd�ZdS)�TestF90Callbackrrrzgh17797.f90cCs:dd�}tjgd�tjd�}|j�||�}|dksJ�dS)NcSrsrUrrtrrr�incr��z*TestF90Callback.test_gh17797.<locals>.incr)rrCrE)rG�)rHrN�int64r�gh17797)r
r��yr9rrr�test_gh17797�szTestF90Callback.test_gh17797N)r0r1r2rr}r~r�rrrrr��sr�c@s*eZdZdZe�dddd�gZdd�ZdS)	�TestGH18335z�The reproduction of the reported issue requires specific input that
    extensions may break the issue conditions, so the reproducer is
    implemented as a separate test class. Do not extend this test with
    other tests!
    rrrzgh18335.f90cC�$dd�}|j�|�}|dksJ�dS)NcSs|dd7<dS)Nrrrrtrrr�foo�sz%TestGH18335.test_gh18335.<locals>.foo�|)r�gh18335)r
r�r9rrr�test_gh18335��zTestGH18335.test_gh18335N)r0r1r2rrr}r~r�rrrrr��sr�c@s8eZdZe�dddd�e�dddd�gZdZdd�Zd	S)
�TestGH25211rrrz	gh25211.fzgh25211.pyf�	callback2cCr�)NcSs||Srrrtrrr�bar�r�z%TestGH25211.test_gh18335.<locals>.bar�n)rr�)r
r�rSrrrr��r�zTestGH25211.test_gh18335N)r0r1r2rr}r~�module_namer�rrrrr��s�r�)r&rr�rrgr_rX�numpyrH�
numpy.testingrrBr�F2PyTestrr�r�r�r�rrrr�<module>s 7