a :jg@sNddlZddlZddlZddlmZmZmZddlm Z ddl m Z ej dej dej diZejdejejejgd d Zejdejejejgd d Zejdejejejgd dZejdejejejgddZdddZejdejejejgddZejdejejejgddZddZGddde ZdS)N)assert_ assert_equalIS_MUSL)CommaDecimalPointLocale)StringIOinfz-infnantpcCsdD]&}tt||tt|d|dq|djdkr^tt|dttdd|dnd}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_msg7yACZ1e161e+16N)rstrfloatitemsizer xrefrF/usr/local/lib/python3.9/site-packages/numpy/_core/tests/test_print.pytest_float_typess rcCs:tjtj tjfD]"}tt||t|d|dqdS)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 rN)nprrrr_REF)r rrrrtest_nan_inf_float%s rcCsdD]}tt||tt|d|dtt||dtt|dd|dtt|||dtt||dd|dq|djdkrtt|dttdd|dnd}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 ry?r (1e+16+0j)N)rrcomplexrrrrrtest_complex_types3s$ &r"dtypec!Csttjddtdtjdttj ddtdtj dttjddtdtjdttj dd tdtj d ttjdd tdtjd ttj dd tdtj d ttjdd tdtjdttj dd tdtj di}|D]\}}tt|||qdS)z*Check inf/nan formatting of complex types.rz(inf+0j)Zinfjz (-inf+0j)z-infjr (inf+1j)z(1+infj) (-inf+1j)z(1-infj)z(nan+0j)Znanj(nan+1j)z(1+nanj)N)r!rrritemsrr)r#ZTESTScsrrrtest_complex_inf_nanMs&        r*cCsrt}t}tj}z8|t_t|||t_|r:t|nt|W|t_n|t_0t||d|ddS)Nzprint failed for type%sr)rsysstdoutprintrgetvalue)rr rfileZfile_tpr,rrr_test_redirected_printgs   r0cCszdD]}tt||qtjtj tjfD]}tt||t|q*|djdkrbttd|nd}ttd||dS)"Check formatting when using print r rrrN)r0rrrrrrrrrrtest_float_type_printzsr2cCsdD]}tt||q|djdkr6ttd|nd}ttd||tttjd|dtttj d|dtttj d|dd S) r1r rrr r r$r%r&N)r0r!rrrrrrrrtest_complex_type_printsr3cCs4ddtjfddtjfddtjfddtjfddtjfddtjfdd tjfdd tjfdd tjfdd tj fd dtj fd dtj fd dtj fd dtj fd dtjfd dtjfd dtjfg}|D]|\}}}z(t|||||d||fWqty,}z.tdd|t|t|t|fWYd}~qd}~00qdS)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)rboolZuint8Zuint16Zuint32Zuint64Zint8Zint16Zint32Zint64Zfloat16float32Zfloat64 longdouble complex64Z complex128 clongdoublerformat ValueErrorrreprr)ZtestsZfmatvalZvaltypeerrrtest_scalar_formats:                  r?c@s4eZdZddZddZejjeddddZ d S) TestCommaDecimalPointLocalecCs tttdttddSN333333?)rrrr6rselfrrrtest_locale_singlesz.TestCommaDecimalPointLocale.test_locale_singlecCs tttdttddSrA)rrrdoublerrCrrrtest_locale_doublesz.TestCommaDecimalPointLocale.test_locale_doubleztest flaky on musllinux)reasoncCs tttdttddS)Nz1.2rB)rrrr7rrCrrrtest_locale_longdoublesz2TestCommaDecimalPointLocale.test_locale_longdoubleN) __name__ __module__ __qualname__rErGpytestmarkZskipifrrIrrrrr@s r@)N) r+rMnumpyrZ numpy.testingrrrZnumpy._core.tests._localesriorrrrrNZ parametrizer6rFr7rrr8Zcdoubler9r"r*r0r2r3r?r@rrrrs*         "