a ;jg@sddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z Gddde j ZGdddeZGd d d e j ZGd d d e j ZGd dde j ZdS)N)IS_PYPY)utilc@seZdZeddddgZejdd dejj dd Z ejj e d d d d ZddZejjejdkdd ddZejjejdkdd ddZddZddZdS)TestF77Callbacktestssrccallbackzfoo.fnamezt,t2,cCs||dSN)check_function)selfr rH/usr/local/lib/python3.9/site-packages/numpy/f2py/tests/test_callback.pytest_allszTestF77Callback.test_allz,PyPy cannot modify tp_doc after PyType_Ready)reasoncCs td}|jjj|ksJdS)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 )textwrapdedentmodulet__doc__)r expectedrrrtest_docstrings zTestF77Callback.test_docstringcCsLt|j|}|dd}|dks$J|dddd}|dks@J|dddd}|d ks\J|d dd d}|d ksxJ|d dtjfd}|dksJ|tjtjfd}|dksJ||jjdd}|dksJ||jj}|dksJ||jjj}|dksJGddd}|}||}|dks0J||j}|dksHJdS)NcSsdS)Nrrrrr7z0TestF77Callback.check_function..rcSsdSNrarrrr9r))Zfun_extra_argsrcSs|Sr rrrrrr;rr cSsd|Srrrrrrr=r) cSs t|Sr )mathdegreesrrrrr?r c@seZdZddZddZdS)z)TestF77Callback.check_function..AcSsdS)Nr!rr rrr__call__Lsz2TestF77Callback.check_function..A.__call__cSsdS)N rr(rrrmthOsz-TestF77Callback.check_function..A.mthN)__name__ __module__ __qualname__r)r+rrrrAKsr/r!r*) getattrrr#pir$funcZfunc0Z _cpointerr+)r r rrr/rrrrr 5s2            zTestF77Callback.check_functionwin32z)Fails with MinGW64 Gfortran (Issue #9673)cCs,dd}t|jd}||}|dks(JdS)NcSs|dkr dSdSdS)Nr3rrr)coderrrr[sz6TestF77Callback.test_string_callback..callbackZstring_callbackr)r0r)r rfr3rrrtest_string_callbackXs z$TestF77Callback.test_string_callbackcCshtdd}tdd}tdgd}dd}t|jd}|||fD]}||||j}|d ksDJqDdS) N)rS8)rccSs4|j|fkrdS|jdkrdSt|dks0dSdS)Nrr8rr)shapedtypenpall)cuZlencurrrrms  z.callbackZstring_callback_arrayr)r@Zzerosarrayr0rsize)r Zcu1Zcu2Zcu3rr6rBresrrrtest_string_callback_arrayes   z*TestF77Callback.test_string_callback_arraycspgfddfddfdddD}|D] }|q6|D] }|qHdrltdS) Ncs*tdjdd}|dks&JdS)NgMbP?cSsdSN{rrrrrrrz?TestF77Callback.test_threadsafety..cb..rH*)timesleeprr)r3r(rrcbs  z-TestF77Callback.test_threadsafety..cbcsZz4tdD]&}j}|dks&J|q Wn tyTtYn0dS)N2rI)rangerrr Exceptionappend traceback format_exc)r jr3)rLerrorsr rrrunners    z1TestF77Callback.test_threadsafety..runnercs*g|]"}tdD]}tj|fdqqS))targetargs)rN threadingThread).0argn)rUrr sz5TestF77Callback.test_threadsafety..)rt2z )startjoinAssertionError)r threadsrr)rLrTrUr rtest_threadsafety{s     z!TestF77Callback.test_threadsafetyc Cspz|jdWn6tyF}zt|ds2JWYd}~n d}~00z|jdWn6ty}zt|dszJWYd}~n d}~00dd|j_|jd}|dksJdd|j_|jd}|dksJ|j`z|jdWn:ty(}z t|dsJWYd}~n d}~00d d d|j_|jd}|d ksRJ|jd}|dkslJdS) Nr<zCallback global_f not definedz!cb: Callback global_f not definedcSs|dS)Nrrxrrrrrz6TestF77Callback.test_hidden_callback..r=cSs|dS)Nr<rrerrrrrrrcSs|dS)Nr=rrerrrrrr)r)rZhidden_callbackrOstr startswithZhidden_callback2Zglobal_f)r msgr3rrrtest_hidden_callbacks0((      *  z$TestF77Callback.test_hidden_callbackN)r,r-r.rgetpathsourcespytestmarkZ parametrizesplitslowrZxfailrrr Zskipifsysplatformr7rFrdrjrrrrrs&  #  (rc@seZdZdZdgZdS)TestF77CallbackPythonTLSz[ Callback tests using Python thread-local storage instead of compiler-provided z-DF2PY_USE_PYTHON_TLSN)r,r-r.roptionsrrrrrssrsc@s.eZdZeddddgZejjddZ dS)TestF90Callbackrrrz gh17797.f90cCs:dd}tjgdtjd}|j||}|dks6JdS)NcSs|dSrGrrerrrincrsz*TestF90Callback.test_gh17797..incr)rr<r=)r?)r@rCZint64rZgh17797)r rvyr3rrr test_gh17797szTestF90Callback.test_gh17797N) r,r-r.rrkrlrmrnrpryrrrrrusruc@s2eZdZdZeddddgZejj ddZ dS) TestGH18335zThe 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! rrrz gh18335.f90cCs$dd}|j|}|dks JdS)NcSs|dd7<dS)Nrrrrerrrfoosz%TestGH18335.test_gh18335..foo|)rZgh18335)r r{r3rrr test_gh18335s zTestGH18335.test_gh18335N) r,r-r.rrrkrlrmrnrpr}rrrrrzsrzc@s8eZdZeddddeddddgZdZddZd S) TestGH25211rrrz gh25211.fz gh25211.pyfZ callback2cCs$dd}|j|}|dks JdS)NcSs||Sr rrerrrbarsz%TestGH25211.test_gh25211..barn)rr{)r rrErrr test_gh25211s zTestGH25211.test_gh25211N)r,r-r.rrkrl module_namerrrrrr~s r~)r#rrqrmrYrQrJnumpyr@Z numpy.testingrr;rZF2PyTestrrsrurzr~rrrrs  8