U
    #cQ                     @   sJ  d dl Z d dlZd dlZd dlmZmZ d dlmZ d dl	m
Z
 ejdej dejdiZejdejejejgd	d
 Zejdejejejgdd Zejdejejejgdd Zejdejejejgdd ZdddZejdejejejgdd Zejdejejejgdd Zdd ZG dd deZdS )    N)assert_assert_equal)CommaDecimalPointLocale)StringIOinfz-infnantpc                 C   s   dD ]&}t t| |tt|d|  d q| djdkr^t t| dttdd|  d nd}t t| d|d|  d dS )	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.

    r      g@xD!Failed str formatting for type %serr_msg 7yAC   Z1e161e+16N)r   strfloatitemsizer   xref r   ?/tmp/pip-unpacked-wheel-b2rbor69/numpy/core/tests/test_print.pytest_float_types   s    	r   c                 C   s:   t jt j t jfD ]"}tt| |t| d|  d qdS )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)npr   r   r   r   _REF)r   r   r   r   r   test_nan_inf_float%   s    	r   c                 C   s   dD ]}t t| |tt|d|  d t t| |d tt|d d|  d t t| ||d  tt||d  d|  d q| djdkrt t| dttdd|  d nd}t t| d|d|  d dS )	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)r   r   complexr   r   r   r   r   test_complex_types3   s$    	&r!   dtypec              !   C   s   t tjddt dtjdt tj ddt dtj dt tjddt dtjdt tj dd	t dtj d
t tjddt dtjdt tj ddt dtj dt tjddt dtjdt tj ddt dtj di}| D ]\}}tt| || qdS )z*Check inf/nan formatting of complex types.r   z(inf+0j)Zinfjz	(-inf+0j)z-infjr
   (inf+1j)z(1+infj)	(-inf+1j)z(1-infj)z(nan+0j)Znanj(nan+1j)z(1+nanj)N)r    r   r   r   itemsr   r   )r"   ZTESTScsr   r   r   test_complex_inf_nanM   sF    
 
   
 
   
 
   
 
   r)   c                 C   sl   t  }t  }tj}z2|t_t||  |t_|r:t| nt|  W 5 |t_X t| | d| d d S )Nzprint failed for type%sr   )r   sysstdoutprintr   getvalue)r   r   r   fileZfile_tpr+   r   r   r   _test_redirected_printg   s    
r/   c                 C   sz   dD ]}t t||  qtjtj tjfD ]}t t|| t|  q*| djdkrbt td|  nd}t td| | dS )"Check formatting when using print r	   r   r   r   N)r/   r   r   r   r   r   r   r   r   r   r   test_float_type_printz   s    r1   c                 C   s   dD ]}t t||  q| djdkr6t td|  nd}t td| | t ttjd| d t ttj d| d t ttj d| d d	S )
r0   r	   r   r   r   r
   r#   r$   r%   N)r/   r    r   r   r   r   r   r   r   r   test_complex_type_print   s    r2   c                  C   s2  ddt jfddt jfddt jfddt jfddt jfddt jfdd	t jfdd
t jfddt jfddt j	fddt j
fddt jfddt jfddt jfddt jfddt jfddt jfg} | D ]z\}}}z(t|||||d||f  W q tk
r* } z&tdd|t|t|t|f  W 5 d}~X Y qX qdS )z2Test the str.format method with NumPy scalar typesz{0}TFz{0:d}   iP  l    ^e l     RU iiЊi lʈl  x'{'	 z{0:g}g      ?y      ?      ?zfailed with val %s, type %sz=format raised exception (fmt='%s', val=%s, type=%s, exc='%s')N)r   Zbool_Zuint8Zuint16Zuint32Zuint64Zint8Zint16Zint32Zint64Zfloat16float32Zfloat64
longdouble	complex64Z
complex128clongdoubler   format
ValueErrorr   reprr   )testsZfmatvalZvaltypeer   r   r   test_scalar_format   s:    

















r>   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestCommaDecimalPointLocalec                 C   s    t ttdttd d S N333333?)r   r   r   r4   r   selfr   r   r   test_locale_single   s    z.TestCommaDecimalPointLocale.test_locale_singlec                 C   s    t ttdttd d S r@   )r   r   r   doubler   rB   r   r   r   test_locale_double   s    z.TestCommaDecimalPointLocale.test_locale_doublec                 C   s    t ttdttd d S )Nz1.2rA   )r   r   r   r5   r   rB   r   r   r   test_locale_longdouble   s    z2TestCommaDecimalPointLocale.test_locale_longdoubleN)__name__
__module____qualname__rD   rF   rG   r   r   r   r   r?      s   r?   )N)r*   ZpytestZnumpyr   Znumpy.testingr   r   Znumpy.core.tests._localesr   ior   r   r   r   markZparametrizer4   rE   r5   r   r   r6   Zcdoubler7   r!   r)   r/   r1   r2   r>   r?   r   r   r   r   <module>   s*   






"