o 6a]@sddlZddlZddlZddlZddlZddlZddlZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZddlm Z GdddZ!Gddde!Z"Gdd d Z#Gd d d e"Z$Gd d d e!Z%Gddde!Z&GdddZ'GdddZ(ej)j*ddGdddZ+GdddZ,GdddZ-GdddZ.GdddZ/Gd d!d!Z0d?d"d#Z1d$d%Z2d&d'Z3d(d)Z4d*d+Z5d,d-Z6d.d/Z7d0d1Z8d2d3Z9d4d5Z:d6d7Z;Gd8d9d9eZe dd>Z?dS)@N) assert_equalassert_array_equalassert_almost_equalassert_array_almost_equalassert_array_less build_err_msgraises assert_raises assert_warnsassert_no_warningsassert_allcloseassert_approx_equalassert_array_almost_equal_nulpassert_array_max_ulpclear_and_catch_warningssuppress_warningsassert_string_equalassert_tempdirtemppathassert_no_gc_cycles HAS_REFCOUNT)ARRAY_FUNCTION_ENABLEDc@LeZdZddZddZddZddZd d Zd d Zd dZ ddZ dS) _GenericTestcCs|||dSN _assert_funcselfabr"@/usr/lib/python3/dist-packages/numpy/testing/tests/test_utils.py _test_equalz_GenericTest._test_equalcCs:tt|||WddS1swYdSr)r AssertionErrorrrr"r"r#_test_not_equals "z_GenericTest._test_not_equalcCs,tddg}tddg}|||dS)z/Test two equal array of rank 1 are found equal.Nnparrayr$rr"r"r#test_array_rank1_eqz _GenericTest.test_array_rank1_eqcCs,tddg}tddg}|||dS)z7Test two different array of rank 1 are found not equal.r(r)Nr+r,r'rr"r"r#test_array_rank1_noteq$r.z#_GenericTest.test_array_rank1_noteqcCs<tddgddgg}tddgddgg}|||dS)z/Test two equal array of rank 2 are found equal.r(r)Nr*rr"r"r#test_array_rank2_eq+sz _GenericTest.test_array_rank2_eqcCs4tddg}tddgddgg}|||dS):Test two arrays with different shapes are found not equal.r(r)Nr/rr"r"r#test_array_diffshape2sz!_GenericTest.test_array_diffshapecCs"tjddgtd}||ddS)zTest object arrays.r(dtypeN)r+r,objectr$rr r"r"r# test_objarray9sz_GenericTest.test_objarraycCs|gdddS)Nr(r)r1)r$rr"r"r#test_array_likes>z_GenericTest.test_array_likesN) __name__ __module__ __qualname__r$r'r-r0r3r5r:r=r"r"r"r#rs rc@sneZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ e j je ddddZdS)TestArrayEqualcC t|_dSr)rrr<r"r"r#setupD zTestArrayEqual.setupc4fdd}dD]}||qdD]}||qdS)z!Test rank 1 array for all dtypes.cLtd|}|d|}|}|d||||dS)Nr)r(rr+emptyfillcopyr$r'tr r!cr<r"r#fooI    z.TestArrayEqual.test_generic_rank1..foo?bhilqpBHILQPfdgFDGS1U1Nr"rrOrMr"r<r#test_generic_rank1G   z!TestArrayEqual.test_generic_rank1cCsltd}td}tt|j|||}|||td}td}tt|j|||}|||dS)NlCj.foorQrRNr"rUr"r<r#test_generic_rank3irWz!TestArrayEqual.test_generic_rank3cCsNtddtjg}tddtjg}|||tgd}|||dS)z$Test arrays with nan values in them.r(r)r;N)r+r,nanr$r'rr r!rNr"r"r#test_nan_array|s  zTestArrayEqual.test_nan_arraycCsFtddg}tddg}|||tddg}|||dS)r4floupifloupafloupipiN)r+r,r$r'r`r"r"r#test_string_arrayss  z!TestArrayEqual.test_string_arrayscCstddtfdtfg}ddg|d<ddg|d<|}|||tddtfdtfg}|d|d<|d|d<t}|jtdd}|||t t |dWddS1sawYdS) zTest record arrays.r)rbrcr(rdzelementwise == messageN) r+rIfloatrKr$rrecord FutureWarningr'rlen)rr r!rNsuplr"r"r#test_recarrayss    "zTestArrayEqual.test_recarrayscCstjjgdgdd}tdtjdg}||||||tjjgdgdd}ttjddg}||||||dS)N@@@)FTFmaskrprr)TFFrq)r+ma MaskedArrayr,r_r$infrr"r"r#test_masked_nan_infs   z"TestArrayEqual.test_masked_nan_infcCsGdddtj}tddg|}tddg|}tt||ktt||kt||k|||||||||dS)Nc@eZdZddZddZdS)z?TestArrayEqual.test_subclass_that_overrides_eq..MyArraycSstt||Sr)boolr+equalallrotherr"r"r#__eq__r>zFTestArrayEqual.test_subclass_that_overrides_eq..MyArray.__eq__cSs ||k Srr"r}r"r"r#__ne__rEzFTestArrayEqual.test_subclass_that_overrides_eq..MyArray.__ne__N)r?r@rArrr"r"r"r#MyArrays r?@rp) r+ndarrayr,viewrtyperzr$r'rrr r!r"r"r#test_subclass_that_overrides_eqs    z.TestArrayEqual.test_subclass_that_overrides_eqzrequires __array_function__reasoncCsGdddtj}tddg|}tddg|}tt t|Wdn1s1wY|||||||||dS)Nc@eZdZddZdS)zKTestArrayEqual.test_subclass_that_does_not_implement_npall..MyArrayc_stSr)NotImplementedrargskwargsr"r"r#__array_function__z^TestArrayEqual.test_subclass_that_does_not_implement_npall..MyArray.__array_function__N)r?r@rArr"r"r"r#r rrrrp) r+rr,rr TypeErrorr|r$r'rr"r"r#+test_subclass_that_does_not_implement_npalls    z:TestArrayEqual.test_subclass_that_does_not_implement_npallN)r?r@rArDrVr]r^rarernrxrpytestmarkskipifrrr"r"r"r#rBBs   rBc@s,eZdZddZddZddZddZd S) TestBuildErrorMessagecCs@tgd}tgd}d}t||g|}d}t||dS)NgrZ| ?rZ| @&@g㈵?&@㈵@There is a mismatchz Items are not equal: There is a mismatch ACTUAL: array([1.00001, 2.00002, 3.00003]) DESIRED: array([1.00002, 2.00003, 3.00004])r+r,rrrr[r\err_msgr r!r"r"r#test_build_err_msg_defaultss z1TestBuildErrorMessage.test_build_err_msg_defaultscCDtgd}tgd}d}t||g|dd}d}t||dS)NrrrF)verbosez) Items are not equal: There is a mismatchrrr"r"r#test_build_err_msg_no_verboses z3TestBuildErrorMessage.test_build_err_msg_no_verbosecCr)Nrrr)FOOBAR)namesz{ Items are not equal: There is a mismatch FOO: array([1.00001, 2.00002, 3.00003]) BAR: array([1.00002, 2.00003, 3.00004])rrr"r"r#test_build_err_msg_custom_names z5TestBuildErrorMessage.test_build_err_msg_custom_namescCr)N)g0D?rr)g_p?rrrrY) precisionz Items are not equal: There is a mismatch ACTUAL: array([1.000000001, 2.00002 , 3.00003 ]) DESIRED: array([1.000000002, 2.00003 , 3.00004 ])rrr"r"r##test_build_err_msg_custom_precisionrz9TestBuildErrorMessage.test_build_err_msg_custom_precisionN)r?r@rArrrrr"r"r"r#rs   rc@\eZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ dS) TestEqualcCrCr)rrr<r"r"r#rDrEzTestEqual.setupcCsH|tjtj|tjgtjg|tjtjg|tjddSNr()rr+r_r'r<r"r"r#test_nan_itemsszTestEqual.test_nan_itemscCs:|tjtj|tjgtjg|tjtjgdSr)rr+rwr'r<r"r"r#test_inf_items szTestEqual.test_inf_itemscCst|tddtdd|tddtdd|tddtdd|tddtdddS)N 2017-01-01smz 2017-01-02)r$r+ datetime64r'r<r"r"r# test_datetimes         zTestEqual.test_datetimec Csttd}tdd}tdd}td}tdd}tdd}|||g}|||g}t||D]\} } || | || g| g|| g| q2t||D]\} } || | || g| g|| g| qRt||D]E\} } || | || | g|| g| g|| gtdd|| gtdd|| gtdd|| gtddqrdS)NNaTrnsr{)r+r timedelta64 itertoolsproductrr') r nadt_no_unitnadt_snadt_d natd_no_unitnatd_snatd_ddtstdsr r!r"r"r#test_nat_items$s2           zTestEqual.test_nat_itemscCs|dd|dddS)Nababb)rr'r<r"r"r#test_non_numericCs zTestEqual.test_non_numericcCs|tddtdd|tdtjtdtj|tdtjtdd|ttjdtdtj|ttjtjttjddSNr(r))rcomplexr+r_r'rwr<r"r"r#test_complex_itemGs "zTestEqual.test_complex_itemcCs|tjtjdSr)r'r+PZERONZEROr<r"r"r#test_negative_zeroNr>zTestEqual.test_negative_zerocCsRttddtdtjg}ttddtddg}||||||dSrr+r,rr_rr'rZr"r"r# test_complexQs zTestEqual.test_complexcCsDddl}t|ddd|dddg}|||ddddS)Nrir(r))datetimer+r,r')rrr r"r"r# test_objectWs  zTestEqual.test_objectN) r?r@rArDrrrrrrrrrr"r"r"r#rs rc@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)TestArrayAlmostEqualcCrCr)rrr<r"r"r#rDarEzTestArrayAlmostEqual.setupcLjddddttfddjdgdgddttfdddS)N?rdecimalcjddddSNg?rrrrr"r<r"r#nz5TestArrayAlmostEqual.test_closeness..cjdgdgddSrrr"r<r"r#rsrr r&r<r"r<r#test_closenessd  z#TestArrayAlmostEqual.test_closenesscsRtdgtdgjddjddttfdddS)NgeH@gwH@r1rr2cjddS)Nrrr"rZr"r#r|rz2TestArrayAlmostEqual.test_simple..r+r,rr r&r<r"rZr# test_simpleus  z TestArrayAlmostEqual.test_simplecszttjgtdgttjgttfddttfddttfdddS)Nr(c Srrr"ananaonerr"r#r z/TestArrayAlmostEqual.test_nan..c Srrr"ainfrrr"r#rrcrrrr"rr"r#rrr+r,r_rwrr r&r<r"rrrrr#test_nan~s  zTestArrayAlmostEqual.test_nancsdtddgddggtjd<ttfddtj d<ttfdddS) Nrrrprq)rrcrrrr"r r!rr"r#rrz/TestArrayAlmostEqual.test_inf..crrrr"rr"r#rr)r+r,rKrwr r&r<r"rr#test_infs  zTestArrayAlmostEqual.test_infcCs@tddgddgg}tjddgddggddgddgg}|||||||||tjjddd }tgd }||||||tjj}tgd }||||||tjjgd gd d }tgd }||||||tjjgd gd d }td}||||||dS) NrrrprqrFTg @rsro)TTT)rrrp)r+r,ru masked_arrayrrvr$maskedrr"r"r# test_subclasss.           z"TestArrayAlmostEqual.test_subclasscC6Gdddtj}tddg|}|||dS)Nc0eZdZfddZfddZddZZS)zGTestArrayAlmostEqual.test_subclass_that_cannot_be_bool..MyArrayct|tjSrsuperrrr+rr} __class__r"r#rr>zNTestArrayAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.__eq__crrr__lt__rr+rr}rr"r#rr>zNTestArrayAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.__lt__c_trNotImplementedErrorrr"r"r#r|rzKTestArrayAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.allr?r@rArrr| __classcell__r"r"rr#r  rrrr+rr,rrrrr r"r"r#!test_subclass_that_cannot_be_bool z6TestArrayAlmostEqual.test_subclass_that_cannot_be_boolN) r?r@rArDrrrrrr r"r"r"r#r_s   rc@r)TestAlmostEqualcCrCr)rrr<r"r"r#rDrEzTestAlmostEqual.setupcr)Nrrrrcrrrr"r<r"r#rrz0TestAlmostEqual.test_closeness..crrrr"r<r"r#rrrr<r"r<r#rrzTestAlmostEqual.test_closenesscsJtjtjttfddttfddttfdddS)NctjdSr)rr+r_r"r<r"r#rz/TestAlmostEqual.test_nan_item..ctjtjSr)rr+r_rwr"r<r"r#rrcrr)rr+rwr_r"r<r"r#rr)rr+r_r r&r<r"r<r# test_nan_items   zTestAlmostEqual.test_nan_itemcsLtjtjtj tj ttfddttfdddS)Ncr rrr+rwr"r<r"r#rr z/TestAlmostEqual.test_inf_item..cstj tjSrrr"r<r"r#rs)rr+rwr r&r<r"r<r# test_inf_items  zTestAlmostEqual.test_inf_itemcCs|dddSr)r'r<r"r"r#test_simple_itemr%z TestAlmostEqual.test_simple_itemcCs|tddtdd|tdtjtdtj|ttjtjttjtj|tdtjtdd|ttjdtdtj|ttjtjttjddSr)rrr+r_rwr'r<r"r"r#rs  "z!TestAlmostEqual.test_complex_itemcCszttddtdtjg}ttddttjdg}ttddtddg}|||||||||dSrr)rr[zr\r"r"r#rs   zTestAlmostEqual.test_complexcCsvtgd}tgd}tt}|j||ddWdn1s&wYt|jd}t |ddt |d d t |d d t |d dt |ddtt}|||Wdn1slwYt|jd}t |ddt |d d t |d d t |d dt |ddttj dg}ttj dg}tt}|||Wdn1swYt|jd}t |ddt |d dt |d dt |d dt |ddtddg}tddg}tt}|||Wdn 1swYt|jd}t |ddt |d dt |d ddS)zCheck the message is formatted correctly for the decimal value. Also check the message when input includes inf or nan (gh12200))g?g@r)g_?g@r rN r1z!Mismatched elements: 3 / 3 (100%)r2zMax absolute difference: 1.e-05rz'Max relative difference: 3.33328889e-06z8 x: array([1.00000000001, 2.00000000002, 3.00003 ])z8 y: array([1.00000000002, 2.00000000003, 3.00004 ])z"Mismatched elements: 1 / 3 (33.3%)z& x: array([1. , 2. , 3.00003])z& y: array([1. , 2. , 3.00004])rr(z Mismatched elements: 1 / 2 (50%)Max absolute difference: 1.Max relative difference: 1.z x: array([inf, 0.])z y: array([inf, 1.])r)z!Mismatched elements: 2 / 2 (100%)zMax absolute difference: 2zMax relative difference: inf) r+r,rrr&rstrvaluesplitrrwrr[r\exc_infomsgsr"r"r#test_error_messages\    z"TestAlmostEqual.test_error_messagecCsd}td}tt}|||Wdn1swYt|jd}t |ddt |ddt |d d d}td}tt}|||Wdn1s\wYt|jd}t |ddt |ddt |d d dS) zHCheck the message is formatted correctly when either x or y is a scalar.r)Nrr1z#Mismatched elements: 20 / 20 (100%)r2rrrMax relative difference: 0.5) r+onesrrr&rrrrrrr"r"r#test_error_message_21s$    z$TestAlmostEqual.test_error_message_2cCr)Ncr)zBTestAlmostEqual.test_subclass_that_cannot_be_bool..MyArraycrrrr}rr"r#rKr>zITestAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.__eq__crrrr}rr"r#rNr>zITestAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.__lt__c_rrrrr"r"r#r|QrzFTestAlmostEqual.test_subclass_that_cannot_be_bool..MyArray.allrr"r"rr#rJrrrrrrr"r"r#r Er z1TestAlmostEqual.test_subclass_that_cannot_be_boolN) r?r@rArDrrrrrrr r$r r"r"r"r#r s 6 r c@4eZdZddZddZddZddZd d Zd S) TestApproxEqualcCrCr)r rr<r"r"r#rDZrEzTestApproxEqual.setupcsNtdtdjddjddttfdddS)N{GH@RH@r significantrcrNrr)rr"rZr"r#rdrz7TestApproxEqual.test_simple_0d_arrays..rr<r"rZr#test_simple_0d_arrays]s  z%TestApproxEqual.test_simple_0d_arrayscsRddjddjddjddttfdddS) Nr'r(r2r)rrcrr+rr"rZr"r#rnrz3TestApproxEqual.test_simple_items..rr<r"rZr#test_simple_itemsfsz!TestApproxEqual.test_simple_itemsctttjtdttjttfddttfddttfdddS)Nr(crrrr"rr"r#rurz0TestApproxEqual.test_nan_array..crrrr"rr"r#rvrcrrrr"rr"r#rwrrr<r"rr#rap    zTestApproxEqual.test_nan_arraycr.)Nr(crrrr"rr"r#r~rz0TestApproxEqual.test_nan_items..crrrr"rr"r#rrcrrrr"rr"r#rrrr<r"rr#ryr/zTestApproxEqual.test_nan_itemsN)r?r@rArDr,r-rarr"r"r"r#r&Xs   r&c@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)TestArrayAssertLesscCrCr)rrr<r"r"r#rDrEzTestArrayAssertLess.setupcs|tddgtddgttfddtddgttfddttfd ddS) N皙?皙@333333?ffffff@c Srrr"rZr"r#rrz8TestArrayAssertLess.test_simple_arrays..rc Srrr"rZr"r#rrcr5rrr"rZr"r#rrrr<r"rZr#test_simple_arrayss z&TestArrayAssertLess.test_simple_arrayscstddgddggtddgddggttfd d td dgddggttfd d ttfd d dS)Nr1r2ffffff @g@r3r4g333333 @g@cr5rrr"rZr"r#rrz0TestArrayAssertLess.test_rank2..rcr6rrr"rZr"r#rrcr5rrr"rZr"r#rrrr<r"rZr# test_rank2s zTestArrayAssertLess.test_rank2csvtjddtjdddttfdddd<ttfddttfd ddS) N)r)r)r))shaper(cr5rrr"rZr"r#rrz0TestArrayAssertLess.test_rank3..r)rrrcr6rrr"rZr"r#rrcr5rrr"rZr"r#rr)r+r#rr r&r<r"rZr# test_rank3s  zTestArrayAssertLess.test_rank3csddttfddtddgttfddtddgttfdddS) Nr1r2cr5rrr"rZr"r#rrz7TestArrayAssertLess.test_simple_items..r8cr5rrr"rZr"r#rrrcr6rrr"rZr"r#rr)rr r&r+r,r<r"rZr#r-s  z%TestArrayAssertLess.test_simple_itemscsttjtdttjttfddttfddttfddttfdddS)Nr(crrrr"rr"r#rrz9TestArrayAssertLess.test_nan_noncompare..crrrr"rr"r#rrcrrrr"rr"r#rrcrrrr"rr"r#rrrr<r"rr#test_nan_noncompares    z'TestArrayAssertLess.test_nan_noncomparecstgdttjttfddttfddtddtjgttfddttfddtd d tjgttfd ddS) N)r1r2r8c Srrr"rrr[r"r#rrz?TestArrayAssertLess.test_nan_noncompare_array..c Srrr"r>r"r#rrr1r2cr=rrr"r>r"r#rrcr?rrr"r>r"r#rrrrcr6rrr"rZr"r#rr)r+r,r_r r&rr<r")rrr[r\r#test_nan_noncompare_arrays  z-TestArrayAssertLess.test_nan_noncompare_arraycstdttj  ttfddttfddttfddttfddttfdddS)Nr(crrrr"rrrr"r#rrz6TestArrayAssertLess.test_inf_compare..cs Srrr"rAr"r#rr cs Srrr"rrr"r#rrcs Srrr"rBr"r#rr cs Srrr"rBr"r#rr)r+r,rwrr r&r<r"rAr#test_inf_compares   z$TestArrayAssertLess.test_inf_comparecstddtjgttjttfddttfddttfddttfddttfdd dS) Nr1r2cr=rrr"rrr[r"r#rrz.cr?rrr"rDr"r#rrcs Srrr"rDr"r#rr cs Srrr"rDr"r#rrcs  Srrr"rDr"r#rr)r+r,rwr r&rr<r"rDr#test_inf_compare_arrays z*TestArrayAssertLess.test_inf_compare_arrayN) r?r@rArDr7r9r;r-r<r@rCrEr"r"r"r#r0s     r0z$The raises decorator depends on Noserc@s<eZdZddZddZddZddZd d Zd d Zd S) TestRaisescCsGdddt}||_dS)Nc@ eZdZdS)z%TestRaises.setup..MyExceptionNr?r@rAr"r"r"r# MyExceptionrI) Exceptione)rrIr"r"r#rDs zTestRaises.setupcCs|rr")rrLr"r"r#raises_exceptionrzTestRaises.raises_exceptioncCdSrr"r<r"r"r#does_not_raise_exceptionrz#TestRaises.does_not_raise_exceptioncCst|j|j|jdSr)rrLrMr<r"r"r#test_correct_catchszTestRaises.test_correct_catchcCs4zt|j|jtWtdtyYdSw)Nzshould have caught RuntimeError)rrLrM RuntimeErrorr&r<r"r"r#test_wrong_exceptions  zTestRaises.test_wrong_exceptioncCs2zt|j|jWtdtyYdSw)Nz$should have raised an AssertionError)rrLrOr&r<r"r"r#test_catch_no_raise s  zTestRaises.test_catch_no_raiseN) r?r@rArDrMrOrPrRrSr"r"r"r#rFs rFc@s$eZdZddZddZddZdS) TestWarnscCshdd}tjdjdd}ttt|dtjdj}ttt|ttddddt||ddS) NcSstddS)Nyor1warningswarnr"r"r"r#fs zTestWarns.test_warn..frWr1cSs|Srr")r[r"r"r#rz%TestWarns.test_warn..r(.assert_warns does not preserver warnings state) sysmodulesfiltersrr UserWarningr r&r )rrYbefore_filters after_filtersr"r"r# test_warns  zTestWarns.test_warncCsttjdjdd}tt tdWdn1swYtjdj}dd}tt|t ||ddS)NrWrUcSs6ttdWddS1swYdSNrU)r rWrXr"r"r"r# no_warnings,s "z3TestWarns.test_context_manager..no_warningsr[) r\r]r^r r_rWrXr r&r)rr`rardr"r"r#test_context_manager%s    zTestWarns.test_context_managerc Csvdd}d}t!tdtz tt|d}Wn ty#YnwWdn1s.wY|r9tddS)NcSstdtdSrc)rWrXDeprecationWarningr"r"r"r#rY5r%z,TestWarns.test_warn_wrong_warning..fFerrorTz#wrong warning caught by assert_warn)rWcatch_warnings simplefilterrfr r_r&)rrYfailedr"r"r#test_warn_wrong_warning4s     z!TestWarns.test_warn_wrong_warningN)r?r@rArbrerkr"r"r"r#rTs rTc@r)TestAssertAllclosecCsd}d}t||ddttt||t||||g}t||||g}t||ddttt|||d|d<t||ttt||ddtdd d dtttd dd ddS) NgMbP?g& .>r()atolg1?r)rtolrrYg?)r r r&r+r,)rr[r\r r!r"r"r#rHs  zTestAssertAllclose.test_simplecCs*tjttjjgtjd}t||dS)Nr6)r+r,iinfoint_minr r9r"r"r# test_min_int\szTestAssertAllclose.test_min_intcCsjtgd}tgd}tt }t||Wdn1s#wYt|j}td|vdS)N)r(r(r(r()r(r(r(r)zXMismatched elements: 1 / 4 (25%) Max absolute difference: 1 Max relative difference: 0.5 r+r,rrr&r rrrrr r!rmsgr"r"r#test_report_fail_percentageas    z.TestAssertAllclose.test_report_fail_percentagecCs.ttjg}ttjg}t||dddS)NT equal_nan)r+r,r_r rr"r"r#test_equal_nanlsz!TestAssertAllclose.test_equal_nancCs2ttjg}ttjg}ttt||dddS)NFrw)r+r,r_r r&r rr"r"r#test_not_equal_nanrsz%TestAssertAllclose.test_not_equal_nancCsHttjg}ttjg}t||t||t||t||dSr)r+r,r_rrrr rr"r"r#test_equal_nan_defaultws    z)TestAssertAllclose.test_equal_nan_defaultcCsjtddg}tddg}tt }t||Wdn1s#wYt|j}td|vdS)Nrr(r)r"rsrtr"r"r#test_report_max_relative_errors   z1TestAssertAllclose.test_report_max_relative_errorcCs"tjgdgdd}t||dS)N)r(r)r1rzm8[ns]r6)r+r,r r9r"r"r#test_timedeltasz!TestAssertAllclose.test_timedeltaN) r?r@rArrrrvryrzr{r|r}r"r"r"r#rlFs  rlc@steZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS)TestArrayAlmostEqualNulpcCd}tjdddtjd}d|}tj| |f}t|jj}||||d}t|||t|jj}||||d}t|||dSNrr!2r6rYr r+linspacefloat64r_finfor7epsrepsnegrnulpr[rr\rr"r"r#test_float64_passs z*TestArrayAlmostEqualNulp.test_float64_passcCd}tjdddtjd}d|}tj| |f}t|jj}||||d}ttt |||t|jj }||||d}ttt |||dSr r+rrrrr7rr r&rrrr"r"r#test_float64_failz*TestArrayAlmostEqualNulp.test_float64_failcCTtd}tjtjtjdtj}||A}|tj}|tj}t||ddS)Nlr6r)r+uint64r,r_rrr)roffsetnan1_i64nan2_i64nan1_f64nan2_f64r"r"r#test_float64_ignore_nan   z0TestArrayAlmostEqualNulp.test_float64_ignore_nancCrr r+rfloat32rrr7rrrrr"r"r#test_float32_pass z*TestArrayAlmostEqualNulp.test_float32_passcCrr r+rrrrr7rr r&rrrr"r"r#test_float32_failrz*TestArrayAlmostEqualNulp.test_float32_failcCr)Nir6r)r+uint32r,r_rrr)rrnan1_i32nan2_i32nan1_f32nan2_f32r"r"r#test_float32_ignore_nanrz0TestArrayAlmostEqualNulp.test_float32_ignore_nancCsd}tjdddtjd}d|}tj| |f}t|jj}||||d}t|||t|jj}||||d}t|||dSNrr2rYr6r) r+rfloat16rrr7rrrrr"r"r#test_float16_passrz*TestArrayAlmostEqualNulp.test_float16_passcCsd}tjdddtjd}d|}tj| |f}t|jj}||||d}ttt |||t|jj }||||d}ttt |||dSr) r+rrrrr7rr r&rrrr"r"r#test_float16_failrz*TestArrayAlmostEqualNulp.test_float16_failcCr)Nr6r)r+uint16r,r_rrr)rrnan1_i16nan2_i16nan1_f16nan2_f16r"r"r#test_float16_ignore_nanrz0TestArrayAlmostEqualNulp.test_float16_ignore_nancC$d}tjdddtjd}d|}tj| |f}||d}t|jj}||||d}t|||d|t|||d|||||d }t|||d|t|jj}||||d}t|||d|t|||d|||||d }t|||d|dS Nrrr!rr6rY?rrqrrrr[xirr\rr"r"r#test_complex128_passs" z-TestArrayAlmostEqualNulp.test_complex128_passcC4d}tjdddtjd}d|}tj| |f}||d}t|jj}||||d}ttt |||d|ttt |||d|||||}ttt |||d|t|jj }||||d}ttt |||d|ttt |||d|||||}ttt |||d|dS Nrrr!rr6rYrrrrr"r"r#test_complex128_fail)s: z-TestArrayAlmostEqualNulp.test_complex128_failcCrrrrr"r"r#test_complex64_passFs" z,TestArrayAlmostEqualNulp.test_complex64_passcCrrrrr"r"r#test_complex64_fail[s: z,TestArrayAlmostEqualNulp.test_complex64_failN)r?r@rArrrrrrrrrrrrrr"r"r"r#r~s    r~c@r%) TestULPcCstjd}t||dddS)NrYrmaxulp)r+randomrandnr)rr[r"r"r# test_equalys zTestULP.test_equalcCRtdtj}|dtjdtj7}ttjj}t|||dddS)NrY{Gz?r!r) r+r#astyperrrrrrrr[rr"r"r# test_single}zTestULP.test_singlecCr)NrYrr) r+r#rrrrrrrrr"r"r# test_doublerzTestULP.test_doublecCsLtjtjfD]}ttjg|}tt|jg}t||ddqdS)Nrr) r+rrr,rwrrmaxr)rdtrwbigr"r"r#rs zTestULP.test_infcstjtjfD]}|tjkrdndttjg|ttjg|tt|jgtt|j gttj g|ttj g|t t fddt t fddt t fddt t fddt t fddqdS) Ng.AgmBctdSNrrr")rwrr_r"r#rz"TestULP.test_nan..crrrr")rrr_r"r#rrctdSrrr")rr_tinyr"r#rrcrrrr")rr_zeror"r#rrcrrrr")rr_nzeror"r#rr)r+rrr,rwrr_rrrrrr r&)rrr")rrwrr_rrrr#rs4 zTestULP.test_nanN)r?r@rArrrrrr"r"r"r#rws  rc@ry)TestStringEqualcCsntddtddtt }tddWdn1swYt|j}t|dttdddS)Nhellozhello multilinezfoo barz hello barz%Differences in strings: - foo + hellocS tddS)NrOrrr"r"r"r#r z-TestStringEqual.test_simple..)rrrr&rrrr )rrrur"r"r#rs      zTestStringEqual.test_simplecCstddttdddS)Nza+*bcSr)Naaaza+brr"r"r"r#rrz,TestStringEqual.test_regex..)rr r&r<r"r"r# test_regexs zTestStringEqual.test_regexN)r?r@rArrr"r"r"r#rs rcCstz|j}Wn tyi}Ynwt|}d|vr3|d8}tjdddkr-|dur,|}n|dur3|}t||dS)Nversionr(r))r1r)__warningregistry__AttributeErrorrkr\ version_infor)mod n_in_contextpy34py37 mod_warns num_warnsr"r"r#assert_warn_len_equals   rcCsDGddd}|}t|ddGddd}|}t|dddS)Nc@rG)/test_warn_len_equal_call_scenarios..modNrHr"r"r"r#rrJrr)rrc@r)rcSsddd|_dS)Nr(r))warning1warning2)rr<r"r"r#__init__s z8test_warn_len_equal_call_scenarios..mod.__init__N)r?r@rArr"r"r"r#rrr))r)rmod_instr"r"r#"test_warn_len_equal_call_scenarioss rcCs0tjt}z|jW|StyY|Swr)r\r]r?rclearrmy_modr"r"r#_get_fresh_mods   rcCsHt}tt|diit|gdtdtdWdn1s'wYt|jittdtdWdn1sJwYt|dddt|gdtdtdWdn1sqwYt|dddttdtdWdn1swYt|d ddd dS) Nr)r]ignore Some warningr(rrzAnother warningr))rr) rrgetattrrrWrirXrrrr"r"r#test_clear_and_catch_warnings s,         rcCst}tt|diidd}t|dt}|t|jtj j dt d|Wdn1s8wYtt |jdt|jdjjddt|dddt}|j|d| t dWdn1sswYt|d|j|d| t dWdn1swYt|dtt d t dWdn1swYt|ddddS) NrcSdd}t|ddgdS)NcStjddd|S)NzSome warning 2r) stacklevelrVarrr"r"r#rX1zFtest_suppress_warnings_module..warn_other_module..warnrr+apply_along_axisrXr"r"r#warn_other_module.z8test_suppress_warnings_module..warn_other_modulermodulerr(rr)rrrrrrir_filterr+lib shape_baserWrXrklogrgrri)rrrlr"r"r#test_suppress_warnings_module)s:            r cCs4t}tt|diit}|ttdWdn1s$wYt|dt}|t| tdWdn1sHwYt|d|j|d| tdWdn1sjwYt|dtt dtdWdn1swYt|ddddS)Nrrrrrr(r) rrrrrr_rWrXrri)rrlr"r"r#test_suppress_warnings_typeWs.           r cCsvt}|t|dd}tjdd}td|t|ttt|dWddS1s4wYdS)NcSstd|dS)NrrV)categoryr"r"r#rXxsz7test_suppress_warnings_decorate_no_record..warnT)rialwaysr() rrr_rWrhriRuntimeWarningrrk)rlrXwr"r"r#)test_suppress_warnings_decorate_no_recordts   "rc Cst}|}|D|jdd}|jddtdtdtdtt|jdtt|dtt|dt|djj ddWdn1sPwY|D|jdd}|jddtdtdtdtt|jdtt|dtt|dt|djj ddWdn1swYt@}|t }|jddtdtdtt|jdWdn1swYtt|jdWddS1swYdS)NzSome other warning 2rfrSome other warningr)r(r) rrirrWrXrrkrrgr)rllog1log2sup2r"r"r#test_suppress_warnings_recordsD              "rc Cs2dd}t4}|tdtdD]}tdqWdn1s'wYtt|jdWdn1s>wYt9}|tdtdD] }tdtdqTWdn1skwYtt|jdWdn1swYt<}|tdtdD]}tdtd|qWdn1swYtt|jdWdn1swYt=}|tdtdD]}tdtd |qWdn1swYtt|jdWddS1swYdS) NcSr)NcSr)Nrr)rrVrr"r"r#rXrzJtest_suppress_warnings_forwarding..warn_other_module..warnrrrr"r"r#rrz.warn_other_moduler r)rlocationroncer)rrirangerWrXrrkr)rrlir"r"r#!test_suppress_warnings_forwardingsT                 $rc Cst$}tj|d}t|dWdn1swYWdn1s*wYttj| d}zt}t1sEwYWn tyVd}Ynwt|ttj| dS)NtmprFT)rospathjoinopenrisdir ValueError)tdirfpathraisedr"r"r# test_tempdirs$  r$c Cst}t|dWdn1swYWdn1s#wYttj| d}zt}t1s>wYWn tyOd}Ynwt|ttj| dS)NrFT)rrrrrisfiler )r"r#r"r"r# test_temppaths"  r&c@seZdZejefZdS)my_cacwN)r?r@rAr\r] class_modulesr"r"r"r#r'sr'cCsPt}ttdtdWdn1swYt|jidS)Nrr)rr'rWrirXrrrr"r"r#%test_clear_and_catch_warnings_inherits   r)zPython lacks refcountsc@s0eZdZdZddZddZejjddZ dS) TestAssertNoGcCyclesz Test assert_no_gc_cycles cCs@dd}t |Wdn1swYt|dS)NcSsg}|g|Srappend)r!r"r"r#no_cycle s z2TestAssertNoGcCycles.test_passes..no_cycle)r)rr-r"r"r# test_passes s  z TestAssertNoGcCycles.test_passesc Csdd}ttt |Wdn1swYWdn1s)wYtt t|WddS1sBwYdS)NcSsg}|||||Srr+)r r"r"r# make_cycles  z5TestAssertNoGcCycles.test_asserts..make_cycle)r r&r)rr/r"r"r# test_assertss   "z!TestAssertNoGcCycles.test_assertscsGfdddzCt}ztttddWdn1s&wYWnty@|dur>tdYnwWd_dSWd_dSd_w)z Test that in cases where the garbage cannot be collected, we raise an error, instead of hanging forever trying to clear it. cs(eZdZdZdZddZfddZdS)z.ReferenceCycleInDelz An object that not only contains a reference cycle, but creates new cycles whenever it's garbage-collected and its __del__ runs TcSs ||_dSr)cycler<r"r"r#r3rEzETestAssertNoGcCycles.test_fails..ReferenceCycleInDel.__init__csd|_jr dSdSr)r1r/r<ReferenceCycleInDelr"r#__del__6s zDTestAssertNoGcCycles.test_fails..ReferenceCycleInDel.__del__N)r?r@rA__doc__r/rr4r"r2r"r#r3,s r3cSrNrr"r"r"r"r#rDrZz1TestAssertNoGcCycles.test_fails..Nz*GC does not call __del__ on cyclic objectsF) weakrefrefr rQrr&rskipr/)rrr"r2r# test_fails%s$      zTestAssertNoGcCycles.test_failsN) r?r@rAr5r.r0rrslowr9r"r"r"r#r* s  r*)NN)@rWr\rrrr6numpyr+ numpy.testingrrrrrrrr r r r r rrrrrrrrrrnumpy.core.overridesrrrBrrrr r&r0rr8rFrTrlr~rrrrrrr r rrrr$r&r'r)rr*r"r"r"r#sT` .-_b+ m"3Kg8 " .(/