Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_buffer.cpython-39.opt-2.pyc

a

��g��@sDddlZddlZddlmZddlmZmZddlmZm	Z	m
Z
ddlZddlZddl
Z
ddlZddlZddlmZddlmZzddlTWney�dZYn0zddlZWney�dZYn0zddlZWney�dZYn0zfe���He_e���ddlmZWd�n1�s&0YWd�n1�sF0YWne�yjdZYn0zddlZWne�y�dZYn0d	Zdddddddddddddddd
�Z e�r�e d=e d=e�r
z e�!d
d�de d<de d
<Wnej"�yYn0ddddddddddddddd>dd>fd�Z#dd�Z$e e e#e#e#e#d�Z%e�rze%dD]Z&e$e&�e%de&<�qbe �'�Z(e �'�Z)e D]Z*e*d v�r�e)e*=�q�e �'�Z+e D]Z*e*d!v�r�e+e*=�q�e(e%d"<e(e%d#<e)e%d$<e+e%d%<e+e%d&<dZ,dZ-gd�gd'�fd$gd(gfd(gd(gfd#d"gd(gfd&d%gd(gfd)�Z.d*d+�Z/d,d-�Z0d.d/�Z1d0d1�Z2d�d3d4�Z3d�d5d6�Z4d�d7d8�Z5d9d:�Z6d;d<�Z7d=d>�e%dD�Z8d?d@�Z9dAdB�Z:dCdD�Z;dEdF�Z<dGdH�Z=dIdJ�Z>dKdL�Z?dMdN�Z@dOdP�ZAdQdR�ZBdSdT�ZCdUdV�ZDdWdX�ZEdYdZ�ZFd[d\�ZGd]d^�ZHd_d`�ZIdadb�ZJdcdd�ZKdedf�ZLdgdh�ZMdidj�ZNd�dndo�ZOdpdq�ZPdrds�ZQd�dtdu�ZRdvdw�ZSd�dxdy�ZTdzd{�ZUd�d|d}�ZVd~d�ZWd�d��ZXd�d��ZYd�d�d��ZZd�d�d��Z[d�d�d��Z\d�d�d��Z]d�d��Z^d�Z_dkZ`d�Zae�rd�Z_d�Z`d�Zae[ZXe\ZYe]Ze�bed��e�bed��Gd�d��d�ejc���Zdeed�k�r@e�f�dS)��N)�support)�permutations�product)�	randrange�sample�choice)�Decimal)�Fraction)�*)�ndarrayT)�?�c�b�B�h�H�i�I�l�L�n�N�f�d�Prr�Q������q�r��r�)i�����)i�����)ri)���)rl�l������r���)rr
rrrrrrrrrrrrc	Cs�|dkrd}n�|dkrd}n�|dkr*d}n�|dkrFdd	>dd	>f}ndd
D]8}zt�|d|>d�Wq�WqJtjy�YqJ0qJ|d@r�d|>d|>fn
dd|>f}|S)Nr
r rrrr&rr*r+)
r"��@�?� �����r)�struct�pack�error)�fmt�lh�exp�r;�,/usr/local/lib/python3.9/test/test_buffer.py�native_type_range^s 
&r=)��@�<�>�=�!r?Z
bBhHiIlLfdZBbc�m�@m�ar�@b)r>�1�2�3r>)r�array�numpy�
memoryview�bytefmtcCsvtt||�}|dkr6t|g�}|dkr6|dkr6d}|dkrFt|�}|dksV|dkrrt�||�}t�||�d}|S)	Nr
rL��rrrr)r�fmtdict�bytes�boolr5r6�unpack)�mode�char�obj�xr;r;r<�
randrange_fmt�s
rYcCsJ|�d�\}}g}|D]}|�t|||��qt|�dkrB|dSt|�S)N�#r*r)�split�appendrY�len�tuple)r8rWrU�charsrXr
r;r;r<�gen_item�s
r`cCs<|dkrt||�Sdg|}t|�D]}t||�||<q$|S�Nr)r`�range)rr8rW�lstrr;r;r<�	gen_items�s

rdcCs�tt|t�}|d}|�d�}tdd�}t|�D]H}ttt|��}tt|t�}||t	|rf|nd�7}|||7}q4t
|||�}	t||�}
||	|
fS)NrZ�ambr�
r*)r�cap�MODE�striprrbr^rQ�MULT�intrdr`)rrWrUZxfmtr8�nmemb�_rV�
multiplier�items�itemr;r;r<�struct_items�s


rqrcCs�|durtt|t�}|dur0ttt|��}tt|t�}|d|t|rR|nd�}t|||�}t||�}|�	d�||}|||fS)NrZr*re)
rrgrhr^rQrjrkrdr`ri)rrWrUrVrnr8rorpr;r;r<�	randitems�s
rrccs4t|tD]"}t|D]}t||||�VqqdS�N)rgrhrQrr)rrWrUrVr;r;r<�	iter_mode�srtccs2t||�D]
}|Vq
|dkr"dSt||�VdS)Nr)rtrq)�nitemsZtestobj�tr;r;r<�iter_format�s
rwcCsd|vpd|vpd|vS)Nr
rrr;)r8r;r;r<�is_byte_format�srxcCs4t|�}|dks$|dko2|ddko2||dtvS)Nr*rrr?)r]�
MEMORYVIEW)r8rXr;r;r<�is_memoryview_format�s�rzcCsg|]}t|�s|�qSr;)rx��.0r
r;r;r<�
<listcomp>��r}cCst|t�Srs��
isinstance�list�rcr;r;r<�atomp�sr�cCs
t|t�Srsrr�r;r;r<�listp�sr�cCs6t|�dkrdS|d}|dd�D]}||9}q$|S�Nrr*)r])rcrX�vr;r;r<�prod�s
r�cCs�|dkrdS|dkrZt|dd��|g}t|ddd�D]}||||d9<q:n>|gt|dd��}td|�D]}||||d9<qz|S)Nrr;�Cr*r���)r�rb)�ndim�shape�itemsizeZlayout�stridesrr;r;r<�strides_from_shapesr�cCs�t|�r|St|�dkr |dSdg|d}|drFt|�|dnd}t|d�D].}||}t||||�|dd��||<qV|Sr�)r�r]rb�_ca)ro�src�strider�startr;r;r<r�s$r�cCslt|�r|St|�dkr |dSdg|d}|d}t|d�D]$}t||d|�|dd��||<qB|Sr�)r�r]rb�_fa)ror�rcr�rr;r;r<r�$s"r�cCs2t|�r(d|vr(t|�t|�kr(td��t||�S�Nrzprod(shape) != len(items))r�r�r]�
ValueErrorr��ror�r;r;r<�carray1s r�cCs2t|�r(d|vr(t|�t|�kr(td��t||�Sr�)r�r�r]r�r�r�r;r;r<�farray6s r�cCsdd�|D�}t|�S)NcSsg|]}t|��qSr;�rb�r|r�r;r;r<r}=r~zindices.<locals>.<listcomp>)r)r��	iterablesr;r;r<�indices;sr�cCs*d}t|�D]}|||||7}q|Srar�)r��indr��retrr;r;r<�getindex@sr�c	Cs�|s|St|�}t||dd�}t||ddd�dd�}dgt|�}t|�D]2}t|||�}t||ddd�|�}||||<qL|S)Nr*r�r�r)r]r�r�r�)	�srcr�r�ZsstridesZdstrides�destr��fr�tor;r;r<�	transposeGsr�cCs6|gkr|St|�r|gSt|d�t|dd��Sr��r��_flattenr�r;r;r<r�Vs
r�cCst|�r|St|�Srsr�r�r;r;r<�flatten^sr�cCs4t|�rgSt||d�gt|d|dd��Sr�)r�r]�slice_shape�rc�slicesr;r;r<r�dsr�cs&t|�r|S�fdd�|�dD�S)Ncsg|]}t|�dd���qS�r*N)�
multislice)r|Zsublst�r�r;r<r}or~zmultislice.<locals>.<listcomp>r)r�r�r;r�r<r�ksr�csFt|�r|S��fdd�t|�d|�d�D�}||�d<|S)Nc	s.g|]&\}}t||�dd��dd���qSr�)�m_assign)r|r�r��lslices�rslicesr;r<r}�s�zm_assign.<locals>.<listcomp>r)r��zip��llst�rlstr�r�r;r�r<r�qs�r�cCsft||�}t||�}t|�t|�kr(dStt|��D],}||||krNdS||dkr4dSq4dS)Nr�r)r�r]rb)r�r�r�r��lshape�rshaperr;r;r<�
cmp_structure�s

r�cCs(t||||�dkrtd��t||||�S)Nrz+lvalue and rvalue have different structures)r�r�r�r�r;r;r<�multislice_assign�sr�cs�|�rdS|dks |�|kr$dSt�fdd��D��r>dS|dkrZ|dkoX�oX�Sd�vrfdSt��fdd�t|�D��}t��fdd�t|�D��}d||ko�||�|kS)NFrc3s|]}|�VqdSrsr;r��r�r;r<�	<genexpr>�r~z#verify_structure.<locals>.<genexpr>Tc3s.|]&}�|dkr�|�|dVqdS�rr*Nr;�r|�j�r�r�r;r<r��s�c3s.|]&}�|dkr�|�|dVqdSr�r;r�r�r;r<r��s�)�any�sumrb)�memlenr�r�r�r��offset�imin�imaxr;)r�r�r�r<�verify_structure�sr�cCs|D]}||}q|Srsr;)rcr�rr;r;r<�get_item�s
r�c
Cs:|\}}}}}}|}t|�D]}	|||	||	7}q|Srsr�)
r�rvr�r�r�r�r�r��prr;r;r<�memory_index�s
r�cCsR|\}}}}}}d|>}t|�D],}t||�}	d|	>}
||
@rDdS||
O}q dS)Nr*TF)r�r�)rvr�r�r�r�r�r�Zvisitedr�r�bitr;r;r<�is_overlapping�s

r��r1r;csZ�s�t|d�}|dkrd|r,|||dddfStdd�}||}td�dkrP|n|}|||dd|fSd}	td�}
|
dkr�|r�d}	n|
dkr�d}	dg|�t|�D]}t|	|d��|<q�nt��}d	}td�}
|
dkr�|
d@r�d
nd}
dg|�|t||d��|d<|
�s0�|ddk�r0|�|d<t|ddd�D]j}|�|d�r`�|dnd9}|
�r�|t||d��|<n"d
td�|td|d��|<�q@d}}d�v�r�t��fdd�t|�D��}t��fdd�t|�D��}||}|�r ||}||d|}n*|||}td�dk�rF||n|}|||��|fS)Nr*rr;�r�d�_�Zr�TFr��r*r�c3s.|]&}�|dkr�|�|dVqdSr�r;r�r�r;r<r�s�z!rand_structure.<locals>.<genexpr>c3s.|]&}�|dkr�|�|dVqdSr�r;r�r�r;r<r�s�)rrbr]r�)r�Zvalid�maxdim�maxshaper�r�rur�r��minshaperrZ	maxstrideZzero_strider�r�r;r�r<�rand_structure�s\


"
��

r�c
Csp||}t|d�}|r$|||nd}td|d�}|||}t|||�}t||�\}}}}	|	|krlt�|S�Nr*)r�slice�
slice_indices�RuntimeError)
�slicelenZlistlenZmaxstartr�Zmaxstep�step�stopr�rm�controlr;r;r<�randslice_from_slicelen&sr�cCspdg|}dg|}t|�D]B}||}|dkr>td|d�nd}t||�||<t||�||<qt|�t|�fSr�)rbrr�r^)r�r�r�r�rrr�r;r;r<�randslice_from_shape3s

r�cCs�td|d�}d}td�}|dkr(d}n|dkr4d}td�dkrDdnd	}dg|}dg|}dg|}dg|}	t|�D�]}t||d�}
t||d�}||
kr�|
|}}
|�rt|
|
d�}t|
|
d�}
d
td�td|
d�}t||
|�}t||
�\}}}}n&|
dk�r$td|
d�nd}t||
�}t||�}td�dk�rp||
||<||<|||	|<||<qx|
|||<||<|||	|<||<qx||t|�t|	�fS)Nr*rr�r�rr��PTFr�)rrbr�r�r�r^)r�r�r�r�rZ
all_randomr�r�r�r�Zsmall�bigr�r�r�Zs_smallrmr�Zs_bigr;r;r<�rand_aligned_slices?s<


r�cCs$|\}}}}}}t||d|d�S)NrZrL)rd)r8rvr�r�rmr;r;r<�randitems_from_structurejsr�c
Cs(|\}}}}}}	t|||||	t|Bd�S)N�r�r��formatr��flags)r�ND_WRITABLE)
ror8rvr�r�r�r�r�r�r�r;r;r<�ndarray_from_structureps
�r�cCsP|\}}}}}}t|�}	t|�D]\}
}t�||	|
||�q t|	||||d�S)N)�bufferr�r��dtyper�)�	bytearray�	enumerater5�	pack_into�numpy_array)ror8rvr�r�r�r�r�r��bufr�r�r;r;r<�numpy_array_from_structurevs�r�cs�|j}|r$t|��|krld|fSnH|gkrH|jdks>�|krld|fSn$t|��\}}|g}|dkrld|fS|�����fdd�tdt����D�}g}|D]2}	t�||	�d}
|
|
kr�d|fS|�	|
�q�|gkr�||fS|d|fS)Nrcsg|]}�||���qSr;r;)r|r�r�Zmemr;r<r}�r~zcast_items.<locals>.<listcomp>�nan)
�nbytesr�r��divmod�tobytesrbr]r5rTr\)Zexporterr8r�r�Zbytelenrr�Z	byteitemsror�rpr;r�r<�
cast_items�s(

 r�c#s�td�D]}|gVqtdd�}td�dkr0dnd��fdd	�t|�D�Vtdd�}td�dkrfdnd��fd
d	�t|�D�VdS)Nr/��r�r�r*rcsg|]}t�d��qS�r��r�r|rm�r�r;r<r}�r~z!gencastshapes.<locals>.<listcomp>csg|]}t�d��qSr�r�r�r�r;r<r}�r~)rbr)rr�r;r�r<�
gencastshapes�s


r�cCs0tt||d�t||d�t||d��Sr�)rrb)rr;r;r<�	genslices�sr�cs�fdd�t|�D�}t|�S)Ncsg|]}t�|��qSr;)r��r|r�r�r;r<r}�r~z"genslices_ndim.<locals>.<listcomp>)rbr)r�r�r�r;rr<�genslices_ndim�srFcCs,|s|dkrdnd}t||d�}t||�Sr�)rr�)r�allow_emptyZminlenr�r;r;r<�rslice�srccstd�D]}t||�VqdS)Nr�)rbr)rrrmr;r;r<r��sr�c#spt|�D] }t�fdd�t|�D��Vqt|�D] }t�fdd�t|�D��Vq2tdd�t|�D��VdS)Nc3s|]}t�|�VqdSrs�rrrr;r<r��r~zrslices_ndim.<locals>.<genexpr>c3s|]}t�|dd�VqdS)T)rNrrrr;r<r��r~css|]}tddd�VqdSr�)r�r�r;r;r<r��r~)rbr^)r�r�Z
iterationsrmr;rr<�rslices_ndim�s
rccs0t|�}|durt|�n|}tt||��VdSrs)r^r]r)�iterabler��poolr;r;r<�rpermutation�sr	c
Cs�z|��}Wnttfy*|��}Yn0t|t�rD|j}|j}nd}d}td||j	|j
|j||j|j
|f�tj��dS)N�unknownz_ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, format='%s', itemsize=%s, flags=%s))�tolist�	TypeError�NotImplementedErrorr�r�rr�r��printr�r��
suboffsetsr�r��sys�stdout�flush)�ndrXr�r�r;r;r<�
ndarray_print�s

��rr�rf�r�z%struct module required for this test.z%ndarray object required for this testc@s�eZdZdd�Zddd�dd�Zd�dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zd=d>�Z d?d@�Z!dAdB�Z"dCdD�Z#dEdF�Z$dGdH�Z%dIdJ�Z&dKdL�Z'dMdN�Z(dOdP�Z)e*j+Z+dQdR�Z,dSdT�Z-dUdV�Z.dWdX�Z/dYdZ�Z0d[d\�Z1d]d^�Z2d_d`�Z3dadb�Z4e5j6dcdd��Z7dedf�Z8dgdh�Z9didj�Z:dkdl�Z;dmdn�Z<dodp�Z=dqdr�Z>dsdt�Z?dudv�Z@dwdx�ZAdydz�ZBd{d|�ZCd}d~�ZDdd��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJd�d��ZKd�d��ZLd�d��ZMd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZRe*jSd�d���ZTd�S)��TestBufferProtocolcCst�|_dSrs)Zget_sizeof_void_p�
sizeof_void_p��selfr;r;r<�setUp�szTestBufferProtocol.setUpF)�sliced�castc
%
s<�	rt�	���n�s t���n��d��jrΈ��d�d}td��D]:}
�	|
dkr\q��|
dkrH|�|
�	|
d7}qH|gdd�t�d�D���j}�ddkr�|}|gt�dd������j|���	�j
����	�j����	�j�����j
|���	�j����	�jt�	���
�r@��sR��	�jt�����	�jt���t�t��szt���r���r����n���}��	|����s�dS|�s�t�}d}t�	�D]�}zNt�|�}t�|�}t|t��r�tj�g|�R�}nt��|�}|�|�Wn t�y0d}Y�qBYn0��	||��q�|�s���	���|�t��}d� dd	�|D��}��	|�!�|���r��nd
}t"��}dD�]�}�}|dk�r�t#�d
��r�t#�d��rt$|�	�}t|�	|t%d�}n0t#�d
��rt#�d��r|dk�rt|�	|d�}t&�t'|����	���|���(t)�|���dk�rP�q�t|�}|�rbdnt*}t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t|�	|�d�} ��	t| �t���t����}!��	|!��t��jdd�}!��	|!��t��jdd�}!��	|!��t+�dt,����	t��|�����fdd�t|�D�}t|d�dk�r�dd�|D�}t|�	|t%B�d�} ��	t| �t���t��jdd�}!��	|!��t+�d
t,����	t��|�����fdd�t|�D�}t|d�dk�r,dd�|D�}t#�d��r<t%nd}"t|�	|"|B�d�} ��	t| �t���t��jd
d�}!��	|!���q�t���r8zt��}Wnt�y�YdS0t�t��rȈjn��|f���������	�
��fdd�	}#|#|�|�-��}$|#|$dd�Wd�n1�s&0Y|��dS)Nr;rr*cSsg|]}d�qS)r�r;r�r;r;r<r}r~z-TestBufferProtocol.verify.<locals>.<listcomp>Tr>css|]}d|VqdS)z%02xNr;r{r;r;r<r�Tr~z,TestBufferProtocol.verify.<locals>.<genexpr>r�r��F�Arrr��r�r�r��r�r�csg|]}t���|���qSr;�r5�unpack_fromr��contigr8r�r;r<r}s�cSsg|]}|d�qS�rr;r�r;r;r<r}�r~�r�r�r���ordercsg|]}t���|���qSr;r"rr$r;r<r}�s�cSsg|]}|d�qSr&r;r�r;r;r<r}�r~csg|]}t���|���qSr;r"rr$r;r<r}�s�cSsg|]}|d�qSr&r;r�r;r;r<r}�r~cs���|j����|j����|j����|j����|j|���|j����|jt	����	rn�s���|j
t	�
����|jt	����dkr�dnt��}��t|�|��rˆ�
�n���}��|����|��dSr�)�assertIsrW�assertEqualr�r�r��readonlyr�r�r^r�rr]rr�)rD�expected_readonlyr�rep)�ex�expected_lenr8r�rcr��resultrr�rr�rr;r<�check_memoryview�sz3TestBufferProtocol.verify.<locals>.check_memoryview)r-).r�r]rZ
assertGreaterrbrr�r*rWr+r�r�r�r,r�r�r^r�r�rrzrr�r�r��get_pointerr�r5r6�extend�BufferErrorrM�join�hexr��
is_contiguousr��
ND_FORTRAN�get_contiguous�
PyBUF_READ�
assertTrue�
cmp_contigr��py_buffer_to_contiguous�
PyBUF_FULL_RO�
toreadonly)%rr1rWr�r8r,r�r�r�rcrrZ
suboffset0rZstride0r.rZbuf_errr�Zitem1Zitem2rXrDrZffZ	flattenedr)�expectedZtransrl�roZinitlst�yZcontig_bytesrr2Zmmr;)
r%r/r0r8r�rcr�r1rr�rr�rr<�verifys




�
���
����
&
,zTestBufferProtocol.verifycCsldd�}|jr||t�s|||t�r(|jr|||t�r8|jr|||t�rH|jr|||t�sX|j	s|||t
�sh|jr|||t�s�||t�r�|j
tt||d�dSt|t�s�t|j�r�|��}nt|td�}|��}||t�r�dn|j}|j}	|j}
|j}||t��sd}	|��}||t��sd}||t��r$|jnd}||t
��r:|jnd}
t||d�}|j|||
|	||||
||d�
dS)	NcSs||@|kSrsr;)�req�flagr;r;r<�match�sz/TestBufferProtocol.verify_getbuf.<locals>.match��getbufFr>r*r;)	rWr�r8r,r�r�r�rcr)r,�PyBUF_WRITABLE�PyBUF_C_CONTIGUOUS�c_contiguous�PyBUF_F_CONTIGUOUS�f_contiguous�PyBUF_ANY_CONTIGUOUS�
contiguous�PyBUF_INDIRECTr�
PyBUF_STRIDES�PyBUF_ND�PyBUF_FORMAT�assertRaisesr5rr�rzr�rr?r�r�r�r�r�rD)rZorig_exr/rErrGrcrrBr8r�r�r�r�r;r;r<�
verify_getbuf�sh����������	�	���

�z TestBufferProtocol.verify_getbufcs�tttttttttt	t
ttt
tf}dd�td�D�dfgd�dfgd�dfdd�td�D�d	ff}ggd
fgd�gd
fdggd
fdgdgd
fdgdgd
fdgdgd
fddggd
fddgddgd
fddgddgdfddgddgdff
}d
ttttBtttBf}d
ttttBf}|D�]�\}}t�|��|D�]x\}}	}
�fdd�|	D�}	|
�9}
|D�]J}|	�rl|t@�rl�qR|�s�|t@�r��qR|�r�|n|d
}t|||||	|
d�}
|�r�|
ddd�nd}t|
�}|�r�t|�}|
jd
k�s�|
jdk�r|�r|	�r|�||
�|�r.|jdk�r.|�r.|	�r.|�||�|D]h}|D]\}|�|
|
||B�|�|
|||B�|�r:|j||||Bdd�|j||||Bdd��q:�q2�qR�q(�qgd�}t|dgtd�}|�tt|�tdgdg�}t|td�}|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�|jtt|td�t|td�}gd�gd�fD]�}d
tfD]p}t|||tBd�}|�t |d��|�t |d ��|D]2}t||d�}|�t |d��|�t |d ���q��q|�qpdS)!NcSsg|]}|drdnd�qS)rTFr;�r|rXr;r;r<r}
r~z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>�r�r*rrr�r�r�r4r3�	rf�rXrrcSs$g|]}|drd|nd|�qS)rr%r$r;rWr;r;r<r}
r~rr)r*rr*r�r[r�r���rr����r*r3csg|]}|��qSr;r;r�r�r;r<r}(r~)r�r�r�r�r�T)r�r�r�rZrH)r*rXr*)r4rr4rr�)!rQrRrS�PyBUF_SIMPLErKrMrO�
PyBUF_FULLr?�
PyBUF_RECORDS�PyBUF_RECORDS_RO�
PyBUF_STRIDED�PyBUF_STRIDED_RO�PyBUF_CONTIG�PyBUF_CONTIG_ROrbr�r9�ND_PILrJrTr5�calcsizerrMr�r+rV�ND_GETBUF_FAILrUr5r<r8)r�requestsZ	items_fmtZ	structureZndflagsZ
real_flagsror8r�r�r�r�Z_items�ex1�ex2�m1�m2rE�bitsr/�baserr)r;r�r<�test_ndarray_getbuf�s��

�
���

�$��z&TestBufferProtocol.test_ndarray_getbufc
	Cs�tdgdg�}tdgdgtd�}t|j|jfD�]H}|�t|hd��|�t|gd��|�t|gd��|jt|gd�dhd	�|jt|gd�dgdhd
�|jt|gd�dggd�|jt|dgdgid�|jt|dgdgid
�|jt|dgdgid�|jt|dgdgdgtd�|jt|dggtd
�|jt|gdgd	�|jt|dgdgdd�|jtj	|dgdgdd�|jt|ddgdgdd�|jt|gd�dgdd�t
d}|jt|dg|dg|d	�|jt|dgdgd	�|jt|gd�dgd	�|jt|dgddgd	�|jt|gd�ddgdd�|jt|gd�dgdgd
�|jt|dgdgddgd
�|jt|ddgddgdgd
�|jt|gd�dgdgdd�|jt|gd�dgdd�|jt|gd�dgddd�|jt|gd�dgd d�|jtj	|dgdgd!d�gd"�}|jt||ddgd#d$gd%d&�|jt|t�d'd(�|jt|dgdgt
d�|�t|dg�q.|jttd)td*�tdgdgtd�}|jt|jdgdgtd�td)�}|�t|jdgdg�|�t|j�tdgdg�}|�dgdg�t|�}|�t|jdgdg�|�t|j�|��|��|�t|j�~|�ttigd��|�ttd)i�tttd+��dgd+d	�}|�tt|d%g�tttd,��ddgd	�}|�tt|gd-��|�tt|ddg�|�tt|d#dg�|�tt|d.dg�tgd�dgdd�}t|td*�}|�t|j�tgd�dgdd�}t|�}	t|	�}|�t|j�td/gdgd0d�}|�t|j�t
}ttt|��dg|d	�}|�t|j�tdgdgd	�}|�ttddddd%�|�tt|d1d2�|�tt|d.d2�|�tt|td3�|�tt|td4�|�tt|td5�|�tt|d6d7�tdgdgd	�}|�ttddddd%�|�tti|�|�tt|i�tdgdgd	�}|�ttddddd%�|�ttid7�|�tt|d8�dS)9NrZr*�r�>r*rr)r*rrJ)r*r�rr��r*rrrrr��r�r�r!r^)r�rI�r�r�r�ZXXXri�r�rrrZQLr�rJr"�r*rrr�r�rH�r*rrr��r�r�r�r�)r�r�r�r>z@#$)
r*rrr�r�r�r4r3rZrf���r\r�)r�r�r�r�r��123rHr�rX)rrr�r))�r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*r*Z�LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL�xyzr��u �Z�r��)r�ND_VAREXPORT�pushrUrr9rgr�r5r7ZND_MAX_NDIM�
OverflowErrorr�r`r5rJ�poprM�releaser3r�rbr_r�memoryview_from_bufferr:r;�UnicodeEncodeErrorr=r8)
rrZndmr
rrorDr/rkrlr;r;r<�test_ndarray_exceptionsfs��������z*TestBufferProtocol.test_ndarray_exceptionscCs�ttd��D]�}dgd}tgd�dgtd�}t|�|d<tdd�D]$}|jgd�dgd�t|�||<qDtd�D]}|||��qr|�t|j	�~qdS)Nr�rrtrr^r*r)
rrbrr�rMr�r�rUr5r�)r�permrDrrr;r;r<�test_ndarray_linked_lists
z+TestBufferProtocol.test_ndarray_linked_listcCsLtd�D]>\}}}t�|�}t|d|d�}|j|d||dddd|d�	qdS)Nrr;r!T�rWr�r8r,r�r�r�rc)rwr5rhrrD)rr8Zscalarrmr�rr;r;r<�test_ndarray_format_scalars
�z-TestBufferProtocol.test_ndarray_format_scalarc
Csltdd�}t|�D]T\}}}t�|�}dtfD]6}t||g||d�}|j|d||dd|f|f|d�	q.qdS)Nr*rfrr Tr�)rrwr5rhrgrrD)rrur8rormr�r�rr;r;r<�test_ndarray_format_shapes


�z,TestBufferProtocol.test_ndarray_format_shapecCs�tdd�}t|�D]�\}}}t�|�}tdd�D]�}|dkr>q0t|dd|��g}||g}|dkrp||dnd}	dtfD]>}
t|||||	|
d�}|j|d||dd|||dd|�d�	q|q0qdS)	Nr*����r�rr�Tr�)	rrwr5rhrbr]rgrrD)rrur8rormr�r�r�r�r�r�rr;r;r<�test_ndarray_format_strides*s$


��z.TestBufferProtocol.test_ndarray_format_stridescCs@gd�}t|ddd�}t|ttBd�}|�|��t|d��dS)NrYrs)r*rr�rH)rrMrTr+rr�)rror/rr;r;r<�test_ndarray_fortran?sz'TestBufferProtocol.test_ndarray_fortrancCs^td�D�]N}dd�t|�D�}t|�}t|�D�]$}t|�\}}}t�|�}dtfD]�}	|dkrl|	tkrlqVt||||	d�}
t|||d�}t	||�}|j
|
d||d||||d�	t|��rt|||d	�}
t|
tt
Bd
�}
|�|
jdk�|
��}|j
|d||d||||d�	t||||	tBd�}
t|||d�}t||�}|j
|
d||d||||d�	qVq0qdS)
Nr�cSsg|]}tdd��qS)rrfr�r�r;r;r<r}Gr~z<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>rr r�Tr�r!rHr;r)rbr�rrrr5rhrgrr�r�rDrzrfrTr<r�r�r9r�)rr��shape_trur�r8rormr�r�rr�rcr/�mvr;r;r<�test_ndarray_multidimEsJ

�
��
�z(TestBufferProtocol.test_ndarray_multidimcCs�tdgdgd�}|�t|jdd�t|�}|�||�|�t|jdd�tdgdgtd�}|�t|jd�t|�}|�||�|�t|jd�tdgdgtd�}|�t|j	d�|�t|jdd�t|�}|�||�|�t
|j	d�|�t
|jdd�gd�}t|t|�gdtd�}|�tj
|jd	d
�|�t|jdd�t|�}|�||�|�t|jd	d
�|�t|jdd�gd�}t|t|�gd
td�}|�t|jd	d
�|�tj
|jdd�dS)Nr*rr3r^r)�r*rrr�r�r�r4r3rr ri,)r���)�r*rrs)r�r�ZLQ)s1r�)rrUr�__setitem__rMr+r��__delitem__r��__getitem__�
IndexErrorr]r5r7r�)rrr�ror;r;r<�test_ndarray_index_invalidrs:z-TestBufferProtocol.test_ndarray_index_invalidcCsJtddtd�}t|�}|�||�|d}|�|d�|d}|�|��|���|d}|�|d�|d}|�|��|���|�t|jd�|�t|jd�|�t|jdd�|�t|jdd�|�|��d�|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�d|d<|�|��d�dS)	Nr*r;r^.rr3rZr�)	rr�rMr+rrUrr�r�)rrr�rXr;r;r<�test_ndarray_index_scalar�s"z,TestBufferProtocol.test_ndarray_index_scalarcCsRtttd��ddgtd�}t|td�}|�t|jd�|�t|jtddd��dS)	Nr3rr�r^rHr*rr�)	rr�rbr�rerUr5r�r�)rr/rr;r;r<�test_ndarray_index_null_strides�sz2TestBufferProtocol.test_ndarray_index_null_stridescCstd�D]�\}}}t|dg|d�}tdd�D]}|�||||�q,|�t|jd�|�t|jd�t|�rt|�}|�||�tdd�D]}|�||||�q�|�t|jd�|�t|jd�qtd�D]�\}}}t|dgt	|d�}t|t
tBd�}tdd�D]}|�||||��qt|�r�|��}|�
|�|�t�tdd�D]}|�||||��qNq�gd�}t|dgd�}t|td�}tdd�D]}|�||||��q�gd�}t|dgd�}t|td�}tdd�D]}|�||||��q�dS)	Nr�r!r����r'rHrxr)rwrrbr+rUr�r�rzrMr�rerTr�r*�__eq__�NotImplementedrfr_)rr8rormrrr�r/r;r;r<�!test_ndarray_index_getitem_single�sBz4TestBufferProtocol.test_ndarray_index_getitem_singlecCs�td�D]�\}}}t|dg|td�}td�D]}|||<|||<q,|�|��|�|�t|jd|�|�t|jd|�t	|�s�qt|dg|td�}t
|�}|�||�td�D]}|||<|||<q�|�|��|�|�t|jd|�|�t|jd|�qtd�D]�\}}}t|dg|td�}tdd�D]&}||d||<||d||<�q(|�|��|�t	|��sn�qt|dg|td�}t
|�}|�||�tdd�D]&}||d||<||d||<�q�|�|��|��qdS)Nr�r r�r�r�r*)rwrr�rbr+rrUr�r�rzrM)rr8roZsingle_itemrrr�r;r;r<�!test_ndarray_index_setitem_single�sD


z4TestBufferProtocol.test_ndarray_index_setitem_singlec

Cs�d}t|�}t|�D�]�}t|�\}}}dtfD�]�}t||||d�}t||�}	t|d|d�D]�}
|�|	|
||
���t|d|d�D]b}|�|	|
|||
|���t|d|d�D](}|�|	|
||||
||�q�q�qdt||||t	Bd�}t
||�}	t|d|d�D]�}
|�|	|
||
���t|d|d�D]d}|�|	|
|||
|���t|d|d�D]*}|�|	|
||||
||��q��q\�q,q0qdS)N�rrr�rr r*r)r�rrrrgrr�rbr+rr9r�)
rr�rur�r8rormr�rrcrr��kr;r;r<�#test_ndarray_index_getitem_multidims.
 *�
 z6TestBufferProtocol.test_ndarray_index_getitem_multidimcCs�tddd�}|�ttdt��t|�}|�||�|�ttdt��td�D]�\}}}t|dg|d�}t|�D]&\}}|�|||�|�	||v�qnt
|�rLt|�}t|�D]&\}}|�|||�|�	||v�q�qLdS)Nr*r;rz1 in ndz1 in mvr�r!)rrUr�eval�localsrMr+rwr�r<rz)rrr�r8rormrr�r;r;r<�test_ndarray_sequence9sz(TestBufferProtocol.test_ndarray_sequencec	Cs�gd�}t|dgtd�}t|�}|�t|jtddd�|�|�t|jtddd�|�t|dgtd�}t|dgtd�}t|td�}|�t|jtddd�|�t|dgdtd�}t|�}|�t	|j
tddd��|�t	|j
tddd��t|d	d
gdtd�}t|�}|�t	|j
tddd�tddd�f�|�t	|j
tddd�tddd�f�|�t|j
d�|�t|j
dtddd�f�|�t|j
tddd�if�|�t|j
tddd�tddd�f�|�t|j
d�t|dgdtd�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|dgdtd�}t|dgdd�}	t|�}t|�}|�t	|jtddd�|dd��|�|�
�|�|�t	|jtddd�|dd��|�|�
�|�t|d	d
gd
td�}t|dgd
d�}t|�}t|�}|�t	|jtddd�|dd��|�|�
�gd�gd�g�|�t|jtddd�|dd��t|dgd
td�}t|dgd
d�}t|�}t|�}|�t	|jtdd	d�|dd��|�|�
�|�|�t	|jtdd	d�|dd��|�|�
�|�|�tttddd	�i�|�ttdd�|�t	ttddd�d
�t|dgd
td�}
|�t|
j�t|dgdd�}t|td�}
|�t|
j�dS)Nr�r3r^rr*rHrr rr�z@%$rrr!r4ry)r�r�r4r3z###########)rr�rMrUrr�r�rSr5r�r�r
r+rr�rg�add_suboffsetsr_)rro�xl�mlr/�xrrr��mr�yrrXr;r;r<�test_ndarray_slice_invalidLs�
�
�
�"""""
�""z-TestBufferProtocol.test_ndarray_slice_invalidcCsgd�}t|dgdtd�}t|dgdd�}|dd�|dd�<|�|��|�t|�}t|�}|�||�|�||�|dd�|dd�<|�|��|�t|ddgdtd�}t|ddgdd�}|d	d
�dd�f|d	d
�d
d
�f<|�|��t|ddg��dS)NrYrXrr r!rZr�rr*r)rr�r+rrMr�)rrorXrCr�r�r;r;r<�test_ndarray_slice_zero_shape�s$z0TestBufferProtocol.test_ndarray_slice_zero_shapec
Csd}t|�}t|�}t|�D]�}t|�\}}}t�|�}dtfD]�}	t||||	d�}
t||�}t	||�D]�}d}
zt
||�}Wn*ty�}z|j}
WYd}~n
d}~00d}z|
|}Wn*ty�}z|j}WYd}~n
d}~00|s�|
r�|�
||
�qh|�|��|�qhq@qdS�Nr�rr )r]r�rrrr5rhrgrr�rr��	Exception�	__class__r*r+r)rr�r�rur�r8rormr�r�rrcr��listerrr�e�nderr�ndslicedr;r;r<�test_ndarray_slice_multidim�s.

z.TestBufferProtocol.test_ndarray_slice_multidimcCs2d}t|�}t|�}t|�D�]}t|�\}}}t�|�}t|||d�}	|	��t|||d�}
|
��t|
�}t	||�}t
||�D]�}
d}zt||
�}Wn*ty�}z|j
}WYd}~n
d}~00d}z|	|
}Wn*ty�}z|j
}WYd}~n
d}~00|�s|�r|�||�q�|�|��|�q�qdS)N)rrr�rr!)r]r�rrrr5rhrr�rMr�rr�r�r�r*r+r)rr�r�rur�r8rormr�rr/r�rcr�r�rr�r�r�r;r;r<�'test_ndarray_slice_redundant_suboffsets�s4

z:TestBufferProtocol.test_ndarray_slice_redundant_suboffsetscCstd�D�]\}}}td�D�]�}td�D�]�}dtfD�]�}|tB}t|dg||d�}t|dg||d�}	t|	�}
d}d}|dd�}
z0|
|}|
|}|
||
|<t|�t|�k}Wn*ty�}z|j}WYd}~n
d}~00d}z||||<Wn,t�y"}z|j}WYd}~n
d}~00|�r8|�	|t
�n|�|��|
�|�	||�t
|��s`q8d}z|
||
|<Wn,t�y�}z|j}WYd}~n
d}~00|�r�|�	|t
�q8|�|
��|
�|�|
|�|�	||�|j|
|	|j|d|j|j|j|��d�	q8q*qqdS)Nr�rr Fr�)rwr�rgr�rrMr]r�r�r*r�r+rrzrDr�r�r�r�)rr8rorm�lslicerr�rrr/r�ZlsterrZdiff_structurercZlvalZrvalr�r�Zmverrr;r;r<� test_ndarray_slice_assign_single�sX
�z3TestBufferProtocol.test_ndarray_slice_assign_singlec
Cs*d}t|�}t|�}t|�D�]}t|�\}}}dtfD]�}tt�D]�}t||�\}	}
t||||t	Bd�}t
||�}d}
zt|||	|
�}Wn*ty�}z|j
}
WYd}~n
d}~00d}z||
||	<Wn*ty�}z|j
}WYd}~n
d}~00|�s|
�r|�||
�qD|�|��|�qDq8qdSr�)r]r�rrrrgrb�
ITERATIONSr�rr�r�r�r�r�r*r+r)rr�r�rur�r8rormr�r�r�rrcr�r1r�r�r;r;r<�"test_ndarray_slice_assign_multidim2s2�
z5TestBufferProtocol.test_ndarray_slice_assign_multidimc
Cs8tt�D�](}tdD�]}t�|�}t|dttd�}|�t	|��t
||�}t|||�}|��}t
|�}t|�r�|��}	|�|	|�|ddkr�t|||td�}
|
��}|�||�t
|
�}t|�r�|�||
�|��}	|�|	|�tr|d}d|vr�qt|||�}
|j|d|
j|d|
j|
j|
j|
��d	�	qqdS)
Nr?T�r�r�rrrrrFr�)rbr�rQr5rhr��MAXDIM�MAXSHAPEr<r�r�r�rrMrzr+rgr�r�rDr�r�r�r�)rrmr8r�rvrorXZxlistr�ZmvlistrCZylistr��zr;r;r<�test_ndarray_randomSsB
�
�z&TestBufferProtocol.test_ndarray_randomcCs�tt�D]�}tdD]�}t�|�}t|dttd�}|�t	|��t
||�}d}zt|||�}Wn*ty�}z|j
}WYd}~n
d}~00|�|�trd}	zt|||�}
Wqty�}z|j
}	WYd}~qd}~00qqdS)Nr?Fr�)rbr�rQr5rhr�r�r��assertFalser�r�r�r�r�r<r�r�)rrmr8r�rvror�rXr�Z	numpy_errrCr;r;r<�test_ndarray_random_invalid|s*
�

z.TestBufferProtocol.test_ndarray_random_invalidc
Cs2tt�D�]"}tdD�]}t�|�}tttd�\}}}}t|d|d�}t|d|d�}	|�	t
|��|�	t
|	��t||�}
t||	�}t|
||�}t|||	�}
|
|||<|�
�}|
�
�}t|�}t|
�}|�|�
�|�|�|�
�|�|ddk�r�|	ddk�r�t|
||td�}t|||	td�}||||<|�
�}|�
�}|�||�|�||�t|�}t|�}|�|�
�|�|�|�
�|�trd|vsd|v�r�qt|
||�}t|||	�}||||<t|��st|	��s|j|d|j|d|j|j|j|�
�d	�	|j|
d|j|d|j|j|j|�
�d	�	qqdS)
Nr?r�TrrrrrFr�)rbr�rQr5rhr�r�r�r�r<r�r�r�rrMr+rgr�r�r�rDr�r�r�r�)rrmr8r�r�r�r�r��tl�trZlitemsZritemsr�r�ZxllistZxrlistr�r�Zylr�ZyllistZyrlistZzlZzrr;r;r<� test_ndarray_random_slice_assign�sb

�



�
�z3TestBufferProtocol.test_ndarray_random_slice_assigncCsvgd�}t|ddgtd�}t|�}|�|jt@�|�|j|�|�|jd�|�|j	�|�|j
�|�|j�dS)NrYrr�r^)rr�)rrgr<r�r*rWr+rr�rLrNrP)rrorr/r;r;r<�test_ndarray_re_export�sz)TestBufferProtocol.test_ndarray_re_exportc	Cs�dtfD]�}tgd�dg|d�}t|�}|�||�|�|��g�|�|��g�tgd�gd�|d�}|�|��g�tgd�gd�|d�}|�|��gggg�tgd�gd�|d�}|�|��ggggggggggggg�qdS)Nrrtr^�rrr�rrr)rrr�rgrrMr+r�rr�rr�r;r;r<�test_ndarray_zero_shape�s
�z*TestBufferProtocol.test_ndarray_zero_shapecCsddtfD]V}tdgdgdg|d�}t|�}|�||�|�|��gd��|�|��gd��qdS)Nrr*r�rv)r*r*r*r*r*r�r�r;r;r<�test_ndarray_zero_strides�sz,TestBufferProtocol.test_ndarray_zero_stridescCs>tttd��dgdd�}|�|jd�|�|��gd��dS)N�rr4ru)r4r3rZ)rr�rbr+r�r�rrr;r;r<�test_ndarray_offset�sz&TestBufferProtocol.test_ndarray_offsetcCs>dtfD]0}tttd��dg|d�}|��}|�||�qdS�Nrrr^)rgrr�rbr�r+)rr�rrDr;r;r<�#test_ndarray_memoryview_from_buffersz6TestBufferProtocol.test_ndarray_memoryview_from_buffercCsPdtfD]B}tttd��dg|d�}td�D]}|�||t||g��q,qdSr�)rgrr�rbr+r3)rr�rrr;r;r<�test_ndarray_get_pointer
sz+TestBufferProtocol.test_ndarray_get_pointercCs\tttd��gd�d�}t|ttBd�}|�|��|���t|�}|�|��|���dS)Nr�)rrr�rrH)rr�rbrSrTr+rrM)rr/rrDr;r;r<� test_ndarray_tolist_null_stridess
z3TestBufferProtocol.test_ndarray_tolist_null_stridescCs�|�tdd��tttd��ddgd�}tttd��ddgd�}|�t||��tdgdgdd	�}|�t|d
��|�td
|��dS)Nr}s456rXrr�rr*rr!rP)r�r=rr�rbr<)rrXrCr;r;r<�test_ndarray_cmp_contigsz*TestBufferProtocol.test_ndarray_cmp_contigcCs�t�dgd��}t|�}|�tt|�tttd���}tttd��dgd�}|�t|�t|��tttd��ddgd�}|�t|�t|��tttd��gd�d�}|�t|�t|��tt	ttd��ddgd��}tttd��ddgt
d�}|�t|�t|��tt	ttd��gd	�d��}tttd��gd	�t
d�}|�t|�t|��tttd���}tttd��gd
�td�}|�t|�t|��tttd��gd
�dd�}|�t|�t|����dS)NrrtrXrrr�)rrrr^�rrr�rrrr!)
rKrrUr��hashrRr�rbr+r�r9rgr�)rrFrrr;r;r<�test_ndarray_hash%s*z$TestBufferProtocol.test_ndarray_hashc
CsTtttttttttt	t
tf}|�t
tidt�tdddtd�}dD]*}|D] }t|||�}|�||���qJqBtdgdgdtd�}dD]&}|D]}t|||�}|�|d	�q�q�tttd
��gd�dtd�}dD]&}|D]}t|||�}|�|d	�q�q�dtfD]�}tdgdgd|tBd�}|��}dD]*}|D]}t|||�}|�||��q.�q&tgd
�dgd|tBd�}|��}dD]*}|D]}t|||�}|�||��q��qxq�tgd
�dgdgtd�}|��}dD].}ttfD]}t|||�}|�||��q֐q�|ddd�}|��}dD]J}|D]>}zt|||�}Wnt�yJY�qYn0|�||��q�qttd��}dtfD�]�}t|ddg|tBd�}t�r�tt|�ddgd|dk�r�dndd�}	|tk�r�tt|ddg�ddgtd�}
|
��}n|��}|D]�}zt|d|�}Wnt�y&Y�q�Yn0|�||�tdd�|D�ddgtd�}|�t|�t|��t�r�|�||	jdd���q�|dk�r�tt|ddg�ddgtd�}
nt|ddgtd�}
|
��}tttttfD]�}zt|d|�}Wnt�yY�q�Yn0|�||�tdd�|D�ddgttBd�}|�t|�t|��t�r�|�||	jdd���q�|tk�r�t|ddgtd�}
|
��}n|��}tttttfD]�}zt|d|�}Wnt�y�Y�q�Yn0|�||�tdd�|D�ddg|tBd�}|�t|�t|��t�r�|�||	jdd���q��qttttd��ddgttBd�}t|dt�}|�||���tdd�|D�ddgtd�}|�t|�t|��t|dt�}tt|ddg�ddgtd�}
|�||
���td d�|D�ddgttBd�}|�t|�t|��t|dt�}|�||���td!d�|D�ddgtd�}|�t|�t|��dS)"NrrZr;rr rr*rr~r3�rrr4rrtrrrrvr�rXr�r^rr�)r�r�r�r)cSsg|]}|�qSr;r;r�r;r;r<r}�r~zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>r(cSsg|]}|�qSr;r;r�r;r;r<r}	r~rcSsg|]}|�qSr;r;r�r;r;r<r}	r~cSsg|]}|�qSr;r;r�r;r;r<r}*	r~cSsg|]}|�qSr;r;r�r;r;r<r}1	r~cSsg|]}|�qSr;r;r�r;r;r<r}7	r~)rQrRrSr_r`r?rarbrcrdrerfrUrr>rr�r+r�r�rbr9r5r�r�r�rMZtostringrg)
rrjrr)ZrequestrrZndbytesrcZnarXrArCr;r;r<�test_py_buffer_to_contiguousJs����B�
�

�� 

�  z/TestBufferProtocol.test_py_buffer_to_contiguouscCs|dgfgd�dgfttd��gd�fg}|D�]H\}}t||d�}t|�}|�|j�|�|j�t|�}t||dd�}t	||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	t|ttBd�}
|�
|
jd
�|
��}|j
|ddd	d
||||d�	t|td�}
|�
|
jd�|�
|
jd
�|�
|
jd
�|
��}|dk�rR|gn|}|j
|ddd	d
d|jgd|d�	q,|D]�\}}t||td�}t|�}|�|j�|�|j�t|�}t||dd�}t||�}|j
||dd	d
||||d�	t|�}	|j
|	|dd	d
||||d�	�q||dd�D]v\}}t||td�}t|�}t|�}t	||�}|j
||dd	d
|||j|d�	t|�}	|j
|	|dd	d
|||j|d�	�q"|�ttdd�|�tti�tgd�dgd�}t|td�}
|�tt|
�t|ttBd�}
|�tt|
�tdgddgddd�}
|�tt|
�|�t|
j�|�tt|
td�|�tt|
td�|�tt|
ddd�td�dS)NrZrtrr�r�rr*r�rTr�rHr;r>r�r*r^r�9rXr"rr!r�)r�rbrrMr<rLrPr]r�r�rDrfrTr+r�r�r_r�r�r�r9rNr�rgrUrr5r�r:r;)rZitems_shaperor�r/rDr�r�rcrnrr;r;r<�test_memoryview_construction:	s�(
���
�
��

��
z/TestBufferProtocol.test_memoryview_constructioncCs�gd�}gd�gd�gd�fD]4}t||d�}|�|j�t|�}|�t|jd�qtdd�D]<\}}}td�}|�|�}|�|�	�d�|�|�
�g�q^dS)	Nrtr�r�rr
r*rMr~)rr<rLrMrUrrrwr+r�r)rror�r/�msrcr8rmrDr;r;r<�test_memoryview_cast_zero_shape�	s
z2TestBufferProtocol.test_memoryview_cast_zero_shapecCs�|j}tj}d}d}ttd��}|td�||d|��t|ddgdd	�}|t|�||d|��t|gd
�dd	�}|t|�||d|��dS)NzPnin 2P2n2i5P PZ3nr3r~r*rr�rr!)rrrr)�check_sizeofrZcalcvobjsizer�rbrMr)r�checkZvsizeZbase_structZper_dimrorFr;r;r<�test_memoryview_sizeof�	sz)TestBufferProtocol.test_memoryview_sizeofcCs�Gdd�dt�}Gdd�dt�}dd�}|d�|d�dtd	�d
tdd�gd
�hd�ddidddddtddtd�td�dddd|dd�g}tdd�D�]6\}}}t|dg|td�}t|dg|td�}	t|�}
t	�
||	d|�||
d<|�|
d|	d�t	�|�}d|v�rq�|D]�}d}
zt	�
||	||�Wnt	j
�yHt	j
}
Yn0d}z||
d <Wn0ttf�y�}z|j}WYd}~n
d}~00|
�s�|�r�|�|
d�|�|d�n|�|
d |	d ��qq�dS)!Nc@seZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTcSs
||_dSrs��val�rr�r;r;r<�__init__�	szFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__cSs|jSrsr�rr;r;r<�__int__�	szETestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__int__N)�__name__�
__module__�__qualname__r�r�r;r;r;r<�INT�	sr�c@seZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXcSs
||_dSrsr�r�r;r;r<r��	szFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__cSs|jSrsr�rr;r;r<�	__index__�	szGTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__index__N)r�r�r�r�r�r;r;r;r<�IDX�	sr�cSsdS)Nr4r;r;r;r;r<r�	r~z;TestBufferProtocol.test_memoryview_struct_module.<locals>.frZy������@@z-21.1gffffff(@r�rrt>r�r�r�r4r3r;�rZTF�asabcrF�abccSs|Srsr;)rXr;r;r<�<lambda>�	r~zBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>rfrMr rrr*)�objectrr	�Ellipsisr�rwrr�rMr5r�r+rhr7rr�r�ZassertIsNot)rr�r�r�valuesr8rorpr/rrDr�r�Z
struct_errZmv_errr�r;r;r<�test_memoryview_struct_module�	sH�

z0TestBufferProtocol.test_memoryview_struct_modulecCs>tgd�dgdgd�}|�|j�t|�}|�t|jd�dS)Nrtrrr�r
)rr�rLrMrUrr)rr/r�r;r;r<�!test_memoryview_cast_zero_strides
sz4TestBufferProtocol.test_memoryview_cast_zero_stridesc	Cs0tD]�}td�rd|n|}t�|�}tD]^}td�r>d|n|}t�|�}tttd��d|g|d�}t|�}|�t	|j
|d|g�q*qtd�D]�\}}	}
t|	dg|d�}t|�}td�D]T\}}
}
t|�s�|�t
|j
|d|g�q�t|�s�t|�s�|�t	|j
|d|g�q�q�t�d�}t�d�}tttd|��dd|gdd�}t|�}|jt	|j
dd|gdd�tttd	��gd
�d�}t|�}
|�t	|
j
�|�t	|
j
ddd�|�t	|
j
i�|�t
|
j
d
�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�|�t
|
j
d�tddgdgdd�}t|�}
|�t|
jd�|�t|
jdd�|�t|
j�tttd	��gd
�d�}t|�}
|jt	|
j
did�tttd	��d	gd�}t|�}
|jt|
j
ddgd�|jt
|
j
ddgd�|jt
|
j
dgd�d�|jt
|
j
dgd�d�|jt	|
j
dgd �d�ttd!d"�td#�D��gd$�d�}t|�}
|jt	|
j
d%gd&�d�tttd'��d'gd%d�}t|�}
|�t
|
j
d%dgd'�ttd(d"�td#�D��d#gd�}t|�}
|jt	|
j
d%gd&�d�ttd)d"�td#�D��d#gd�}t|�}
|jt	|
j
dgd&�d�tttd'��d'gd%d�}t|�}tttd'��d'gdd�}t|�}tjd*k�r�|�t	|j
dgd+��|�t
|j
dgd,��|�t
|j
d%gd-��nB|�t	|j
ddd.g�|�t
|j
dgd/��|�t
|j
d%gd0��dS)1Nrr?r/r!r*rrr��xrxrr�Xz@Xz@XYz=Bz!Lz<Pz>lZBIZxBIr�rsZIIrr3rr)r�)rrr�r�r�r4r�)rrr�r�r�r4r)rrr�r�r�r4rXcSsg|]}d�qSr�r;r�r;r;r<r}]
r~zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>i�)rr�r4r[r)rrr�r�r"cSsg|]}d�qSr�r;r�r;r;r<r}g
r~cSsg|]}d�qSr�r;r�r;r;r<r}l
r~l����)r4r4�Ir,iQiAji��	)�r��rr3)r�r�rrr��)rrr/r/r)rrr/r3r)�NON_BYTE_FORMATrr5rhrr�rbrMrUrrrwrzr�rxr
r�r�rr�r�maxsize)rZsfmtZsformatZssizeZdfmtZdformatZdsizer/r�ZsitemsrmZsize_hZsize_drDrrmrnr;r;r<�test_memoryview_cast_invalid
s�

��

 "  ������z/TestBufferProtocol.test_memoryview_cast_invalidcslddd�fddd�fddd�ff���fdd	�}t�d
�}tdgd
d�}t|dd
�\}}t|�}|�d�}�j||d
ddd
|d|dd�
t�d
�}tdg||gdd�}t|d
|gd�\}}t|�}|jd
gd�}�j|||d
dddd|dd�
tdd�D],\}	}
}t�|	|
�}t|�}||||
|	�q�tdd�D]4\}	}
}t|
dg|	t	d�}t|�}||||
|	��q2dS)NrcSst|���Srs�r�r��r/r;r;r<r��
r~z9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>rcSsdd�t|���D�S)NcSs g|]}|dkr|dn|�qS)r,r!r;rWr;r;r<r}�
r~�MTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>rrr;r;r<r��
r~r
cSsdd�t|���D�S)NcSsg|]}tt|�d��qS)zlatin-1)rR�chrrWr;r;r<r}�
r~rrrr;r;r<r��
r~c

s�t�|�}�D]~\}}|�|�}||�}�j||d|ddd|gd|dd�
|�|�}	��|	|�|��}�j|	|||dddg|f|dd�
qdS)Nr*Fr0r�T�	rWr�r8r,r�r�r�rcr)r5rhrrDr+r)
r/rDror8�srcsizerNZto_bytelistrnrc�m3�Zbytespecrr;r<�iter_roundtrip�
s"

�

�z?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtriprrZr!r*Tr�r	rrr;r0rKrMr )
r5rhrr�rMrrDrwrKr�)rr
r
r/Z	destitemsZ	destshaperDrnZdestsizer8rormr;rr<�test_memoryview_cast�
sB


�

�
�z'TestBufferProtocol.test_memoryview_castcCs�t�D�]�}tdD�]�}|dkr$qdtd�|}t�|�}t|�|}t|�rVdnd}t||�D�]:\}}}	t�|�}
|dkr�|gng}||
g}t|||d�}
t	|
�}t
|
|||d	�\}}|dur�|�t|j
||�qd|d
kr�qdt|||d�}|j
||d	�}t|�}|j}|��}|j||
||d||||dd�
|�
|�}|j
||d	�}t|�}|
j}|
��}|j||
|
|d||||dd�
|j||
|
|d||||dd�
qdqqt�r�Gd
d�dtj�}|dd�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�t�d�}t	|�}|�
d�}|�|j|�|�|jd�|�|jd�|�|jd�|�|j|jf�|�|jd�|�|jd�dS)Nr?r)r>r?rrMrNrr!rr�Tr	c@s eZdZdejfdejfgZdS)z>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointrXrCN)r�r�r��ctypes�c_long�c_double�_fields_r;r;r;r<�BEPoint�
srr�g33333i@rr*Fr�r;�333333�?r
)r�rQrr5rhr�rxrwrrMr�rUrrr]r�rrDr�BigEndianStructurer+rWr�r*r,r�r�r�rr)rZ_tshaperVZtfmtZtsizerrWr8rorm�sizer�Ztshaper/rDZtitemsrrnr�r�rcrZm4r�pointrmrXr;r;r<�test_memoryview_cast_1D_ND�
s�


�
��



z-TestBufferProtocol.test_memoryview_cast_1D_NDcCs2t�dttdd���}t|�}|�||�|�|��|���|ddd�}|ddd�}|�||�|�|��|���tttd��gd�dd	�}t|�}|�|��|���td
dgdgdd	�}t|�}|�t|j�td
gdgdd	�}t|�}|�t|j�tgd�ddgdd	�}t|�}|�t|j�dS)Nrr�r�rri	)r[rr4rr�rr!)rr�)r4r[r9�12345r*r�)r��b�c�d�e�f)	rKr�rbrMr+rrrUr
)rrFrDr/r;r;r<�test_memoryview_tolists(z)TestBufferProtocol.test_memoryview_tolistcCsHttd��}|��}|�|�d��|��|��}|�|�d��dS)NrZz<memoryz	<released)rMr��__repr__r<�
startswithr�)rrDr�r;r;r<�test_memoryview_repr2sz'TestBufferProtocol.test_memoryview_reprcCs|dD]J}td�}t�|d|dg�}t|�}|�d|�|�d|�|�d|�qtdgdd�}t|�}|�ttdt��dS)	N)rrg���?g@g"@rr|z9.0 in m)	�floatrKrMZassertInrrUrr�r�)rr8�infr/rDr;r;r<�test_memoryview_sequence;sz+TestBufferProtocol.test_memoryview_sequenceccsL|�t��}dVWd�n1s&0Y|�t|j�d|f�dS)Nz#index out of bounds on dimension %d)rUr�r+�str�	exception)r�dim�cmr;r;r<�assert_out_of_bounds_errorIs
$�z-TestBufferProtocol.assert_out_of_bounds_errorc	CsNtdgdd�}t|�}|�|dd�|�|d|�|�|d|�|�t|jd�tdgdd�}t|�}|�t|jd�tttd	��d	gt	d
�}t|�}|�t
|jd�|�t|jd�|�t|jd
�|�t
|jd�|�t
|jd�tttd��ddgt	d
�}t|�}|�|dd�|�|dd�|�|dd�|�|dd�|�|dd�dD]@}|jdd��||dfWd�n1�s�0Y�qbdD]@}|jdd��|d|fWd�n1�s�0Y�q�|�t
|jd�|�t
|jd�|�t|jd �|�t|jd!�|�t|jd�|�t|jd�dS)"N�)@rr!r;.rrtZiiir4r^r)�@����r3rXrr��rr)rrrwr[�r�r�)r{r]�rr]r*�r)�r�r�r�r)rr(�rrr�r.r.)rrMr+rUrr�r
r�rbr�r�r+)rr/rD�indexr;r;r<�test_memoryview_indexPsF00z(TestBufferProtocol.test_memoryview_indexc	Cs�tdgdtd�}t|�}d|d<|�|dd�d|d<|�|dd�|�t|jdd	�tttd
��d
gd�}t|�}|�t|jdd
�tttd
��d
gtd�}t|�}|�t	|jdd�|�t|jdd
�|�t|jdd�|�t	|jdd�|�t	|jdd�t
dD]r}|dk�s|dk�r(�qtgd�dg|td�}t|�}tdd�}d||<|�||d�|�||||��qtgd�dgdtd�}t|�}d|d<|�|dd�tgd �dgdtd�}t|�}d!|d"<|�|d"d!�td#gd"gdtd�}t|�}|�t|jdd$�tttd%��gd&�td�}t|�}t
d�
�D]�\}}|dk�r^�qH|dk�rl�qH|�|�}|\}	}
|d'k�s�|dk�r�dd(dd(}	}
|d)k�r�|�t|jd|	d"�|�t|jdd*�|�t|jd|
��qH|�d�}|�t|jdd+�tttd"��d"gd,td�}t|�}|�t|jdd"�td-gd"gd.td�}t|�}|�t|jdd"�tttd/��dd0gtd�}t|�}d1|d2<|�|dd"d1�d3|d4<|�|ddd3�d5D]@}|jd"d6��d||df<Wd�n1�s�0Y�q�d7D]@}|jdd6��d|d|f<Wd�n1�sD0Y�q|�t	|jd8d�|�t	|jd9d�|�t|jd:d�|�t|jd;d�|�t|jdddg�dS)<Nr,rr g�6@r;g�7@.rg33333�8@r4rrrfr^r)rZr-r.r[r/r�r3�r?r
rrtrr{)�1�2�3r�)TFTTr*�xr�r�rxrrrr~s��ZxLrr�rXr��*)rr*�+r1r2r3r4r5r(r6r7)rr�rMr+rUrr�r�rbr�rQrr*rorr�r
r+)rr/rDr8rrrmZ_rangern�lo�hir8r;r;r<�test_memoryview_assign�s�
��




00z)TestBufferProtocol.test_memoryview_assignc	Cs�tttd��dgtd�}t|�}|�t|jtddd��|�t|j	tddd�t
ddg��|�t|jd�tttd��dgtd�}t|�}|�t|jtddd�tddd�f�|�t|j	tddd�tddd�ft
ddg��|�t|jtddd�if�|�t|j	tddd�ift
ddg��|�t|j	tddd�dg�dt
fD�]l}tttd��dgdgdt|Bd	�}tttd
��dgdg|d�}t|�}t|�}|dd�|dd�<|dd�|dd�<|�||�|�||�|dd�ddd�|dd
�ddd�<|dd�ddd�|dd
�ddd�<|�||�|�||�|ddd�ddd�|ddd�ddd�<|ddd�ddd�|ddd�ddd�<|�||�|�||��qBdS)NrXr^rrr*r;r�r[)r�r�r�r��rvr�rr�r\)rr�rbr�rMrUr�r�r�r�r�r
rrgr+)rr/rDr�rkrlrmrnr;r;r<�test_memoryview_slice�sN
�
�
 �
��((,,z(TestBufferProtocol.test_memoryview_slicecCs�dd�}tdd�D�]�}t|d�D�]�\}}}t|�D�]�}t|�D�]�}t�||�}t�||�}	t|	�}
|�|
|�|�|
��|���|�|
��|���|�t|
�t|��||||	|
|�d}d}z0||}
||}||||<t|
�t|�k}Wn,t	�y&}z|j
}WYd}~n
d}~00d}z|
||
|<Wn,t	�yh}z|j
}WYd}~n
d}~00|�r~|�|t�qD|�s�|�r�|�||�qD|�|
|�|�|
��|���|�|
��|���||||	|
|�qDq6q"qdS)Nc	Ss�t|�D]�\}}||}||}|�||�|||<||krV|�||�|�||�n|�||�|�||�|||<|�||�|�||�|||<|||<qdSrs)r�r+�assertNotEqual)	ZtestcaserFrrD�
singleitemrrmZai�mir;r;r<�cmptest,sz9TestBufferProtocol.test_memoryview_array.<locals>.cmptestr*r�rK)
rbrwr�rKrMr+rr�r]r�r�r*r�)rrIrr8rorGr�rrFrrDZ	array_errZhave_resizeZal�arr�Zm_errr;r;r<�test_memoryview_array*sFz(TestBufferProtocol.test_memoryview_arrayc	Cs�t�dgd��}t�dgd��}t|�}t|�}dD]0}|�t||�|�t�|�t||�|�t�q4t|�}|��|�||�|�||�|�||�t|�}t|�}|��|�||�|�||�t|�}|�|gd��tdgdgdt	d�}d	t
d
�f|d<|�t|�|�t�dd
�}t|�}|�||�|�||�t�r�Gdd�dtj�}|dd�}t|�}t|�}|�||�|�||�|�||�|�
t|j�dS)Nrrt)r*rr4)�__lt__�__le__�__gt__�__ge__r0r*zl x d xr r�r�r�ur~c@s eZdZdejfdejfgZdS)zITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointrXrCN�r�r�r�rrrr;r;r;r<r�srr�r�)rKrMr*�getattrr�r�r+rFrr�r$rrrUr
r)	rrFrr��w�attrrrrr;r;r<�%test_memoryview_compare_special_caseshsF
z8TestBufferProtocol.test_memoryview_compare_special_casescCsntdgdd�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��d|d<|�||�|�||�|�||�|�||�|�||�|�||�|�|�|��|�|�|��ttt	d��dgtt
Bd	�}ttt	d��dgtt
Bd	�}t|�}|�||�d
|d<|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�tdgd
d�}tdgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�||�|�||�|�||�dS)N��@Lr!rr i�r;rXr^r�rZ)rVrrZLf5sZhf5s)i?���rr)rr�rMr+r��__ne__rFr�r�rbrg)r�nd1�nd2r�rSrr/rDr;r;r<�!test_memoryview_compare_ndim_zero�sj��z4TestBufferProtocol.test_memoryview_compare_ndim_zerocCsXtgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�dgdd�}tgd�dgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tgd�d	gdd�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gd
d�}tgd�dgdd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��tgd�d	gdd�}tgd�dgdtd�}t|�}t|�}|�||ddd
��|�|ddd
�|�|�||ddd
��|�|ddd�|ddd��dS)N�����@�����'���r��@hr!)r]r^r_r`i�z<iz>h)r]r_rarrr�r\z!hz<lr zh  0cz>  h)rrMr+rFrg�rrYrZr�rSr;r;r<� test_memoryview_compare_ndim_one�sl  � �z3TestBufferProtocol.test_memoryview_compare_ndim_onecCs�tddgdgdd�}tddgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tddgdgdd�}tddgdgd	d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)
N�rrrbr!i|���i?���z= h0cz@   i�rrMr+rcr;r;r<�"test_memoryview_compare_zero_shape$
s$z5TestBufferProtocol.test_memoryview_compare_zero_shapecCs�tgd�dgdd�}tdgdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�td	gddgd
d�}td	gdgdgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N)rerererer�rWr!rerrrz)rerez@ Liz!L  hrfrcr;r;r<�$test_memoryview_compare_zero_strides>
s$z7TestBufferProtocol.test_memoryview_compare_zero_stridesc
Cs�d}tdD]n}t|dd|�\}}}dtfD]L}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�q,qd}td�D]h}	t|�\}}}dtfD]L}t||g||d�}t|�}|�||�|ddd�}t|�}|�||�q�q�dS)	NrfrErMr?rr r{r�)rQrrrgrrMr+rb)
rrrVr8rorGr�rrDrmr;r;r<�&test_memoryview_compare_random_formatsX
s(z9TestBufferProtocol.test_memoryview_compare_random_formatscCs�tttdd��gd�dd�}tttdd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�d	d�}td
gdgd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�d
d�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}tdgdddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�d
d�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)N��r2�rrr�rbr!rr��rr*rz=f q xxL)g333333�r*rz< f 2Qr�r�rr4z! b B xLz
= Qx l xxLr�rr�rbrMr+rFrcr;r;r<�"test_memoryview_compare_multidim_ct
sZz5TestBufferProtocol.test_memoryview_compare_multidim_ccCs�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	d
dgdtd�}td
gd	d
dgdtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttdd��gd�dtd�}tttdd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}tttd��gd�dtd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nrjr2)r�rrrbr rr��rr�r�rr�=Qq)r�rz=qQr�rrkZ0llrG)rr�rbr9rMr+rFrcr;r;r<�(test_memoryview_compare_multidim_fortran�
s�����������z;TestBufferProtocol.test_memoryview_compare_multidim_fortranc	CsPttdd��}t|gd��}t|gd�dd�}t|gd�dtd�}t|�}t|�}|�||�|�||�|�||�dgd	}d
|d<t|gd��}t|gd�dd�}t|gd�d
td�}t|�}t|�}|�||�|�||�|�||�tttd��ddgdd�}|ddd�ddd�f}tttd��ddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgdd�}|ddd�ddd�f}tdgdddgdd�}|ddd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd	��gd�dd�}|dd�ddd�f}tttd	��gd�dd�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgd	gd �d!d�}|dd�ddd�f}tdgd	gd �d"d�}|dd�ddd�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)#Nrjr2rk�@lr!rr )gffffff
����r>r�)g�������rtr>r�zd b czd h c�(r3�@Irr*r�r\r)rr$�r[rz=iiz>iir�rr)rr}�r�rrZb3sZi3s)r�rbr�rr9rMr+rF)	r�lst1�lst2rYrZr�rSrkrlr;r;r<�&test_memoryview_compare_multidim_mixed�
s�
z9TestBufferProtocol.test_memoryview_compare_multidim_mixedcCstttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dd�}tttd��gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nr�)rrrrr!)r�rrz@irnrcr;r;r<�+test_memoryview_compare_multidim_zero_shape[s$z>TestBufferProtocol.test_memoryview_compare_multidim_zero_shapecCstdgdgd�dd�}tdggd�gd�dd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�|�|��|���td	gd
ddgd
d�}td	gddgddgdd�}t|�}t|�}|�||�|�||�|�||�|�||�|�||�dS)Nrer�)r�r�r�rWr!r6rrzr�rfrr�z=lQrz<lQ)rrMr+rrcr;r;r<�-test_memoryview_compare_multidim_zero_stridesus&z@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesc	Cs^tttd��ddgdd�}|ddd�ddd	�f}tttd��ddgd
td�}|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdddgd
td�}d|dd<|ddd�ddd	�f}tdgdddgdttBd�}d|dd<|ddd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}|dd�ddd	�f}tdgdgd�dd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tttd��gd�dtd�}|dd�ddd	�f}tttd��gd�dtd�}|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}tdgdgd�dttBd�}d|ddd<|dd�ddd	�f}t|�}t|�}|�||�|�||�|�||�|�||�|�||�ttdd ��}t|gd��}t|gd�d!td�}t|gd�d"t	tBd�}t|�}t|�}|�||�|�||�|�||�d#gd}d$|d%<t|gd��}t|gd�d&td�}t|gd�d't	tBd�}t|�}t|�}|�||�|�||�|�||�dS)(Nrur�r3rvr!rr*r�r\rr rprq)r*r\rr4z>Qqr�r�rrk)r�r�ZBbrxr)shellor~r*�)rrrZ5s0sP)ssushir~r*rjr2rsr)ssashimisslicedg�����4@)sramensspicygfffff�"@r[z
< 10p 9p dz
> 10p 9p d)
rr�rbrgrMr+rFr�r�r9)	rrkrYrlrZr�rSryrzr;r;r<�+test_memoryview_compare_multidim_suboffsets�s�������
�z>TestBufferProtocol.test_memoryview_compare_multidim_suboffsetscCsTdD�]H}tdgdgd�|dd�}tdgdgd�|dttBd�}d|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�tdgdgd�|dd�}tdgdgd�|dttBd�}d
|d	d
ddd<t|�}t|�}|�||�|�||�|�||�|�||�|�||�qdS)N)rBr@rArCr'r�)rr�rrrrr!r r*rr)r'r%r#ZQLH)r*r*r*)rr�r9rMr+rF)r�	byteorderrXrCrFrr;r;r<�!test_memoryview_compare_not_equals6
���z4TestBufferProtocol.test_memoryview_compare_not_equalcCst�dgd��}t|�}|��|�tt|�|�t|jd�|�tt|�|�t|j�|�t|j�|�tt	dt
��|�t|jd�|�t|jdd�dD]}|�t|j
|�q�t�dgd��}t|�}t|�}|�||�|��|�||�|�||�|�||�dS)Nr)g�������?g������@gffffff
@r
z1.0 in mrr*)rWr�r,r�r�r�r�r�rrLrNrP)rKrMr�rUr�rrrr�r�r�r�r��__getattribute__r+rF)rrFrDrTrrmrnr;r;r<�test_memoryview_check_released.s*z1TestBufferProtocol.test_memoryview_check_releasedcsPd�t�dgdd�}t|�}|�||�|�|��|���t�gdgdd�}t|�}|�||�|�|��|���t�fdd�td	�D�gd
�dd�}t|�}|�||�|�|��|���t�fdd�td
�D�gd�dd�}t|�}|�||�|�|��|���t�rLGdd�dtj�}|dd�}t|�}|�|��t|��dS)Nr\r�rbr!r*z>hQiLlcsg|]}��qSr;r;r��rvr;r<r}er~z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>rXr�z=hQiLlcsg|]}��qSr;r;r�r�r;r<r}jr~r�)r�rrrrz<hQiLlc@s eZdZdejfdejfgZdS)z;TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointrXrCNrQr;r;r;r<rssrr�r�)rrMr+r�rbrrrR)rrrDrrrFr;r�r<�test_memoryview_tobytesVs0$�
z*TestBufferProtocol.test_memoryview_tobytescCs�|�ttitd�|�ttdtd�tgd�dgdgd�}|�tt|td�tdd	d
d�}dD],}t|t|�}|�||�|�|d	d�q^tdd	d
td
�}dD],}t|t|�}|�||�|�|d	d�q�dD]\}d|d	<t|t|�}|�||�|�|d	d�d|d	<|�|d	d�|�|d	d�q�tdgdgd
td
�}dD]>}t|t|�}|�t	|j
d�|�||�|�|��g��qHttt
d��gd�d
td
�}dD]*}t|t|�}|�t|���ggg��q�tdgdgdtd
�}dD]2}t|t|�}|�||�|�|��|����q�tgd�dgdtd
�}dD]2}t|t|�}|�||�|�|��|����q:tgd�dgdgtd�}dD]d}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��q�|ddd�}dD]d}t|t|�}|�||�|�|��|���|�t|jdd�|�|dd�|�|dd��qttt
d��ddgtd�}dD]*}t|t|�}|�t|���|����q�|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]*}t|t|�}|�t|���|����q
|�tt|td�t|t|�}|�t|���|���ttt
d��ddgttBd�}dD]<}|�tt|t|�t|t|�}|�t|���|����q�tgd�dgdgd�}t|td�}|�|j�dS)Nrr>r�rtrr�rrZr;rr!rr rfr*rr3r�rrrrvr�r�rXr�r^)r�r)rrrx)rUrr:r;r5ZPyBUF_WRITErr+r�r�r�rr�rbr�r9rgr<rL)rrr)rDr;r;r<�test_memoryview_get_contiguousys����z1TestBufferProtocol.test_memoryview_get_contiguouscCs�t�d�}t�dgd��}t|�}t�|�}td|�}|�|�|�|�	�|�t�d�}t
ttd��gd�dd�}t|�}t�|�}td|�}|�|�|�|�	�|�dS)Nrrxr�rrXr�r!)
r5rhrKrM�io�BytesIOr��readintor+r�rr�rb)rrrFrDr�rrr;r;r<�test_memoryview_serializing�s





z.TestBufferProtocol.test_memoryview_serializingc	Cs�tttd���}t|�}|�t|�t|��|jdddgd�}|�t|�t|��|ddd�}tttd��ddd��}|�t|�t|��tttd��gd�td	�}t|�}|�t|�t|��tttd��gd�d�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��gd�t	d	�}|ddd
�dd�ddd�f}t|�}|�t|�t|��tttd��dgd
d�}t|�}tttd��dgdd�}t|�}|�||�|�t|�t|��tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�tttd��gd�dd�}t|�}|�
t|j�tttdd��gd�dd�}t|�}|�
t|j�dS)NrXr
rr�rr\r�rkr^rr�)rr�rrr!rr�rr�r�rz= Lz< h)
rRr�rbrMr+r�rrr9rgrUr��__hash__)	rrrDZmcZmxrrXrFrCr;r;r<�test_memoryview_hashsJz'TestBufferProtocol.test_memoryview_hashcCs|tgd��}t|�}t|�}|�t|j�~|��tgd��}t|�}t|ttd�}t|ttd�}|�|j	|�|�t|j�~~|��tgd��}t|�}t|�}t|�}|��|�t|j�~|��tgd��}t|�}t|�}t|ttd�}t|ttd�}|�|j	|�|��|�t|j�~~|��tgd�dgt
d�}t|�}|jgd�dgd�t|�}t|�}|�|�
�|�
��t|�}	|�|	�
�|�
��|�|	�
�|�
��|��|	��|��|�|�
�|�
��~|��|��dd	�}
td
�}t|��,}|
|�|�|dtd��Wd�n1�sF0Ytttd
��gd�dd�}t|ttd�}	t|	ttd�}|�|j	|�t|��>}|
|�|�|dd��
�gd�gd�gg�Wd�n1�s�0YdtfD�]
}td
�}t|���}~t|t|d�}	t|	���}~	t|t|d�}t|��h}
~|
|
�|
|�|
|�|�|dtd��|�|dtd��|�|
dtd��~
Wd�n1�s�0Y~Wd�n1�s�0Y~Wd�n1�s�0Ytd
�}t|���}~t|t|d�}	t|	���}~	t|t|d�}t|��l}
~|
|�|
|�|
|
�|�|dtd��|�|dtd��|�|
dtd��~~~
Wd�n1�s�0YWd�n1�s�0YWd�n1�s�0Y�q�td
�}|�t��Rt|��(}t|�}|dtd�kWd�n1�sN0YWd�n1�sn0YdS)Nrt�rIr�rr^)r�r�r�r4r3r�rcSs,t|��}Wd�n1s0YdSrs)rM)rrnr;r;r<�catch22�s
z;TestBufferProtocol.test_memoryview_release.<locals>.catch22r}rr;rXr�rr!r*rl)rr�r�r<rr=)r�rMrrUr5r�r?�ND_REDIRECTr*rWr�r�r+rr��ordr�rb)rrFrDrrYrZrmrnrXrCr�r�r�rr/r;r;r<�test_memoryview_releaseHs�
4
F


"""


j
z*TestBufferProtocol.test_memoryview_releasecCs0tdd�td�D�dgdd�}t�ddd�td�D��}||fD]�}t|ttd�}t|ttd�}t|�}|�|j|�|�|j|�|�|j|�|�||�|�||�|�||�|�|dd	�|dd	��|�|dd	�|dd	��|�|dd	�|dd	��~~|�|dd	�|dd	��q@dS)
NcSsg|]}d|�qS�r#r;rWr;r;r<r}�r~z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>rXrr!cSsg|]}d|�qSr�r;rWr;r;r<r}�r~r�r*r)	rrbrKr?r�rMr*rWr+)rrrFrXrCr�rDr;r;r<�test_memoryview_redirect�s"z+TestBufferProtocol.test_memoryview_redirectcCs�d}gd�}|�ttddd�t�}t|�}|j||d|dddgdg|d�	td�D]}|�|||�qT~~t�}t|�}~~t�}t|td	�}t|td	�}t|�}|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~t�}t|ttd
�}t|ttd
�}t|�}|�	|j
|�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|�}|j|dd|dddgdg|d�	td�D]}|�|||��q�~~tdd�}t|�}~~tdd�}t|td	�}t|td	�}t|�}|�	|j
d�|�	|j
|�|j||d|dddgdg|d�	~~~~tdd�}t|ttd
�}t|ttd
�}t|�}|�	|j
d�|�	|j
|�|�	|j
|�|j||d|dddgdg|d�	~~~~dS)Nr)rr*rrr�r�r�r4r3rZrfr[r*rrTrXr�rHr�)Zlegacy_mode)rUrZstaticarrayrMrDrbr+rr?r*rWr�)rr8rcrXrCrr�rDr;r;r<�$test_memoryview_from_static_exporter�s�
�
�
�

�


�

�z7TestBufferProtocol.test_memoryview_from_static_exportercCs*tgd�dgttBd�}|�tt|�dS)Nrtrrr)rriZND_GETBUF_UNDEFINEDrUr5rMr�r;r;r<�#test_memoryview_getbuffer_undefined>sz6TestBufferProtocol.test_memoryview_getbuffer_undefinedcCs&tgd�dgtd�}|�tt|�dS)Nrtrr^)rrirUr5rM)rrXr;r;r<�test_issue_7385Dsz"TestBufferProtocol.test_issue_7385cCs&dD]}|�t�|�t�|��qdS)N)r>�iiZ3s)r+�	_testcapiZPyBuffer_SizeFromFormatr5rh)rr�r;r;r<�test_pybuffer_size_from_formatHs�z1TestBufferProtocol.test_pybuffer_size_from_formatN)F)Ur�r�r�rrDrVrqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�rrrrr"r&�
contextlib�contextmanagerr+r9rCrErKrUr[rdrgrhrirorrr{r|r}rr�r�r�r�r�r�r�r�r�r�r�Zcpython_onlyr�r;r;r;r<r�s��K
0i
-'	0.Y #6!)>
		%qu
8	s<T	
5m8>5?H>Ha(#u<^r�__main__)rNN)r)r)r�r1r;)r�r1)r)N)F)F)r�)N)gr�Zunittest�testr�	itertoolsrr�randomrrr�warningsrrKr��osZdecimalrZ	fractionsr	Z_testbuffer�ImportErrorrr5rZEnvironmentVarGuard�environ�catch_warningsrLr�r�Z
SHORT_TESTZNATIVEr6r7ZSTANDARDr=rQr8�copyryZARRAYr�ZBYTEFMTrhrjrgrYr`rdrqrrrtrwrxrzrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrr�rr	rr�r�r�Z
skipUnlessZTestCaserr��mainr;r;r;r<�<module>sf 


�P

	��
�	





�	



	


?

+

!





o


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists