o 6aQ@sJddlZddlZddlZddlmZmZddlmZddl m Z ej dej dej diZ ejdejejejgd d Zejdejejejgd d Zejdejejejgd dZejdejejejgddZdddZejdejejejgddZejdejejejgddZddZGdddeZdS)N)assert_ assert_equal)CommaDecimalPointLocale)StringIOinfz-infnantpcCsdD]}tt||tt|d|dq|djdkr0tt|dttdd|ddSd}tt|d|d|ddS) z Check formatting. This is only for the str function, and only for simple types. The precision of np.float32 and np.longdouble aren't the same as the python float precision. rg@xD!Failed str formatting for type %serr_msg7yAC1e161e+16N)rstrfloatitemsizerxrefr=/usr/lib/python3/dist-packages/numpy/core/tests/test_print.pytest_float_typess   rcCs:tjtj tjfD]}tt||t|d|dq dS)z Check formatting of nan & inf. This is only for the str function, and only for simple types. The precision of np.float32 and np.longdouble aren't the same as the python float precision. r r N)nprrrr_REF)rrrrrtest_nan_inf_float%s  rcCsdD]A}tt||tt|d|dtt||dtt|dd|dtt|||dtt||dd|dq|djdkr^tt|dttdd|ddSd}tt|d|d|ddS) zCheck formatting of complex types. This is only for the str function, and only for simple types. The precision of np.float32 and np.longdouble aren't the same as the python float precision. r r r y?r (1e+16+0j)N)rrcomplexrrrrrtest_complex_types3s$ &  r"dtypecCsittjddtdtjdttj ddtdtj dttjddtdtjdttj dd tdtj d ttjdd tdtjd ttj dd tdtj d ttjdd tdtjdttj dd tdtj d}|D] \}}tt|||q~dS)z*Check inf/nan formatting of complex types.rz(inf+0j)infjz (-inf+0j)z-infjr (inf+1j)z(1+infj) (-inf+1j)z(1-infj)z(nan+0j)nanj(nan+1j)z(1+nanj)N)r!rrritemsrr)r#TESTScsrrrtest_complex_inf_nanMsH          r-cCsrt}t}tj}z|t_t|||t_|rt|nt|W|t_n|t_wt||d|ddS)Nzprint failed for type%sr )rsysstdoutprintrgetvalue)rrrfilefile_tpr/rrr_test_redirected_printgs   r4cCs|dD] }tt||qtjtj tjfD] }tt||t|q|djdkr2ttd|dSd}ttd||dS)"Check formatting when using print r rrrN)r4rrrrrrrrrrtest_float_type_printzsr6cCsdD] }tt||q|djdkrttd|n d}ttd||tttjd|dtttj d|dtttj d|dd S) r5r rrr r r%r&r(N)r4r!rrrrrrrrtest_complex_type_printsr7cCs0ddtjfddtjfddtjfddtjfddtjfddtjfdd tjfdd tjfdd tjfdd tj fd dtj fd dtj fd dtj fd dtj fd dtjfd dtjfd dtjfg}|D]<\}}}zt|||||d||fWqYty}ztdd|t|t|t|fWYd}~qYd}~wwdS)z2Test the str.format method with NumPy scalar typesz{0}TFz{0:d}iPl^elRU iiЊilʈlx'{' z{0:g}g?y??zfailed with val %s, type %sz=format raised exception (fmt='%s', val=%s, type=%s, exc='%s')N)rbool_uint8uint16uint32uint64int8int16int32int64float16float32float64 longdouble complex64 complex128 clongdoublerformat ValueErrorrreprr)testsfmatvalvaltypeerrrtest_scalar_formats@                  rQc@s$eZdZddZddZddZdS)TestCommaDecimalPointLocalecC tttdttddSN333333?)rrrrCrselfrrrtest_locale_single z.TestCommaDecimalPointLocale.test_locale_singlecCrSrT)rrrdoublerrVrrrtest_locale_doublerYz.TestCommaDecimalPointLocale.test_locale_doublecCs tttdttddS)Nz1.2rU)rrrrErrVrrrtest_locale_longdoublerYz2TestCommaDecimalPointLocale.test_locale_longdoubleN)__name__ __module__ __qualname__rXr[r\rrrrrRs rR)N)r.pytestnumpyr numpy.testingrrnumpy.core.tests._localesriorrrrmark parametrizerCrZrErrrFcdoublerHr"r-r4r6r7rQrRrrrrs,         "