o
    1ήc                     @   s   d Z ddlZddlmZ ddlmZ ddlZddlm	Z	m
Z
mZ ejdfejdfejdfejd	fejd
fejdfejdfejdfejdfejdfejdfejdfejdfejdfejdfejdfejdfejdfgZee \Z Z!G dd dZ"dS )z2
Test scalar buffer interface adheres to PEP 3118
    N)rational)get_buffer_info)assert_assert_equalassert_raises?bhilqBHILQefdgZfZdZgc                	   @   s   e Zd Zejjdeeddd Zejjdeeddd Z	ejjde
eddd	 Zejjdeedd
d Zdd Zdd Zdd Zejdejdddejdddejdddgdd Zdd ZdS )TestScalarPEP3118scalar)idsc                 C   s<   | }t jg t |d}t|}t|}t|j|j d S )Ndtype)nparrayr   
memoryviewr   format)selfr   xamv_xmv_a r'   I/tmp/pip-target-vg8gfxp4/lib/python/numpy/core/tests/test_scalarbuffer.pytest_scalar_match_array%   s
   z)TestScalarPEP3118.test_scalar_match_arrayc                 C   sV   | }t |}t|jt|j t|jd t|jd t|jd t|jd d S )Nr   r'   )	r    r   itemsizer   r   ndimshapestrides
suboffsets)r"   r   r#   r%   r'   r'   r(   test_scalar_dim-   s   z!TestScalarPEP3118.test_scalar_dimzscalar, codec                 C   s<   | }t d|jjdd|dd}t|}| ||ksJ d S )Nr'   r   Tr-   r*   r+   r,   r!   readonly)dictr   r*   r    _as_dict)r"   r   coder#   expectedr%   r'   r'   r(   test_scalar_code_and_properties7   s   z1TestScalarPEP3118.test_scalar_code_and_propertiesc                 C   sF   | }t jtdd t|dg W d    d S 1 sw   Y  d S )Nscalar buffer is readonlymatchWRITABLE)pytestraisesBufferErrorr   )r"   r   r#   r'   r'   r(   test_scalar_buffers_readonly@   s   "z.TestScalarPEP3118.test_scalar_buffers_readonlyc                 C   s6  t dt jdfdt jdfg}t jd|dd }tt|t j t|}dt t jdfj	 }|d	t t jj	 7 }t
|j	| t
|jd
 t
|jd t
|jd t
|jd t jddg|d}tt|t j t|}t
|j	|j	 t
|j|j tjtdd t|dg W d    d S 1 sw   Y  d S )Nname   grades)   )ndarray_scalar)g333333?g      @r   r'      rB   r   )Sarah)g       @      @)John)g      @rF   r7   r8   r:   )r   r   unicode_float64r   r   
isinstancevoidr    r*   r   r+   r,   r-   r.   ndarrayr!   r;   r<   r=   r   )r"   dtr#   r%   expected_sizer$   r&   r'   r'   r(    test_void_scalar_structured_dataF   s&   "z2TestScalarPEP3118.test_void_scalar_structured_datac                 C   s    t |j|j|j|j|j|jdS )N)r-   r,   r*   r+   r!   r1   )r2   r-   r,   r*   r+   r!   r1   )r"   mr'   r'   r(   r3   _   s   zTestScalarPEP3118._as_dictc                 C   s   t d}t d}tddddddd}t|}| ||ks!J t|| }| ||ks0J t d	d
g}t d|}ttt	ft|d  t
jt	dd t|dg W d    d S 1 s`w   Y  d S )Nz
2016-01-01z
2017-01-01)rD   rD   )   r   Tr0   )r$   uint16)r   zM8[s]r   r7   r8   r:   )r   
datetime64r2   r    r3   r   emptyr   
ValueErrorr=   r;   r<   r   )r"   dt1dt2r5   vrM   r$   r'   r'   r(   test_datetime_memoryviewc   s   


"z*TestScalarPEP3118.test_datetime_memoryviews22ascii)idu   ️️zbasic multilingualu   💻💻znon-BMPc                 C   s   t |}tddddddd}t|}| ||ksJ t j|dd}t|d	d
 |D  tjt	dd t
|dg W d    d S 1 sFw   Y  d S )Nr'   rQ   r   2wTr0   i4r   c                 S   s   g | ]}t |qS r'   )ord).0cr'   r'   r(   
<listcomp>   s    z3TestScalarPEP3118.test_str_ucs4.<locals>.<listcomp>r7   r8   r:   )r   str_r2   r    r3   
frombufferr   r;   r<   r=   r   )r"   rZ   r5   rX   code_pointsr'   r'   r(   test_str_ucs4z   s   
"zTestScalarPEP3118.test_str_ucs4c                 C   sx   t d}tt t| W d    n1 sw   Y  tjtdd t|dg W d    d S 1 s5w   Y  d S )NrD   r7   r8   r:   )r   r   	TypeErrorr    r;   r<   r=   r   )r"   rr'   r'   r(   test_user_scalar_fails_buffer   s   

"z/TestScalarPEP3118.test_user_scalar_fails_bufferN)__name__
__module____qualname__r;   markparametrizescalars_only
codes_onlyr)   r/   scalars_and_codesr6   r>   rO   r3   rY   paramrg   rj   r'   r'   r'   r(   r   #   s&    

	


r   )#__doc__numpyr   numpy.core._rational_testsr   numpy.core._multiarray_testsr   r;   numpy.testingr   r   r   bool_byteshortintcint_longlongubyteushortuintcuint	ulonglonghalfsingledouble
longdoublecsinglecdoubleclongdoublerr   ziprp   rq   r   r'   r'   r'   r(   <module>   s6    