Your IP : 216.73.216.52


Current Path : /opt/alt/python35/lib64/python3.5/test/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/test/__pycache__/test_buffer.cpython-35.opt-1.pyc



��YfP{�K@s�ddlZddlZddlmZddlmZmZddlmZm	Z	m
Z
ddlmZddl
Z
ddlZddlZddlZddlmZddlmZyddlTWnek
r�dZYnXyddlZWnek
r
dZYnXyddlZWnek
r8dZYnXy(e
j��dd	lmZWdQRXWnek
r{dZYnXd
Zddddd
dddddddddddddddddddddddddiZer�ed=ed=erDy0ejdddd�ded<ded<Wnej k
rCYnXdddfdddd>fd
dd >dd >fdddd>fddd!>dd!>fdddd">fddd#>dd#>fdddd$>fddd#>dd#>fdddd$>fddd%>dd%>fdddd>fddd%>dd%>fddd&>dd&>fiZ!d'd(�Z"d)ed*ed+e!d,e!d-e!d.e!iZ#er�x&e#d*D]Z$e"e$�e#d*e$<q�Wej%�Z&ej%�Z'x"eD]Z(e(d/kr�e'e(=q�Wej%�Z)x"eD]Z(e(d0kre)e(=q�We&e#d1<e&e#d2<e'e#d3<e)e#d
<e)e#d4<dZ*dZ+d5d)d*d+d,d-d.gd)d6d7d8gfd9d3gd)gfd:d)gd)gfd;d2d1gd)gfd<d4d
gd)gfiZ,d=d>�Z-d?d@�Z.dAdB�Z/dCdD�Z0d5dddEdF�Z1d5dGdH�Z2d5dIdJ�Z3dKdL�Z4dMdN�Z5dOdP�e#d*D�Z6dQdR�Z7dSdT�Z8dUdV�Z9dWdX�Z:dYdZ�Z;d[d\�Z<d]d^�Z=d_d`�Z>dadb�Z?dcdd�Z@dedf�ZAdgdh�ZBdidj�ZCdkdl�ZDdmdn�ZEdodp�ZFdqdr�ZGdsdt�ZHdudv�ZIdwdx�ZJdydz�ZKd{d|�ZLd}d"fd~d�ZMd�d��ZNd�d��ZOd}d"d�d��ZPd�d��ZQdd�d��ZRd�d��ZSdd�d��ZTd�d��ZUd�d��ZVd�d��ZWd�d�d��ZXd�d�d��ZYd}d�d��ZZdd�d��Z[d�d��Z\d�Z]d}Z^d�Z_er�d�Z]d�Z^d�Z_eYZVeZZWe[Zej`ed��ej`ed��Gd�d��d�eja���Zbecd�kr�ejd�dS)��N)�support)�permutations�product)�	randrange�sample�choice)�get_config_var)�Decimal)�Fraction)�*)�ndarrayT�?�c�b�B�h�H�i�I�l�L�n�N�f�d�P�Q��@��q������ �?i�cCs�|dkrd}n�|dkr*d}n�|dkr?d}n�|d	krTd}nuxCdD];}ytj|d|>d�PWq[tjk
r�Yq[Xq[W|d@r�d|>d|>fn
dd|>f}|S)zReturn range of a native type.rr�r
rrrr'ri���rr&r%r$r#r!r")rr()rrl����)r+r,lE����E)r-r.)
r)r*rr'r&r%r$r#r!r")�struct�pack�error)�fmt�lhZexp�r4�5/opt/alt/python35/lib64/python3.5/test/test_buffer.py�native_type_rangeWs 				
	/r6��@�<�>�=�!Z
bBhHiIlLfdZBbc�mz@m�az@br�1�2�3�array�numpy�
memoryview�bytefmtcCs�tt||�}|dkrMt|g�}|dkrM|dkrMd}|dkret|�}|dks}|dkr�tj||�}tj||�d}|S)	zWReturn random item for a type specified by a mode and a single
       format character.rrCssr
rrr)r�fmtdict�bytes�boolr/r0�unpack)�mode�char�obj�xr4r4r5�
randrange_fmt�srNcCsi|jd�\}}g}x'|D]}|jt|||��q"Wt|�dkr_|dSt|�S)zReturn single random item.�#rr)�split�appendrN�len�tuple)r2rLrJ�charsrMrr4r4r5�gen_item�s

rUcCsT|dkrt||�Sdg|}x't|�D]}t||�||<q3W|S)z,Return a list of random items (or a scalar).r)rU�range)rr2rL�lstrr4r4r5�	gen_items�s

rXcCs�tt|t�}|d}|jd�}tdd�}xlt|�D]^}ttt|��}tt|t�}||t	|r�|nd�7}|||7}qIWt
|||�}	t||�}
||	|
fS)NrO�ambr�
r)r�cap�MODE�striprrVrSrF�MULT�intrXrU)rrLrJZxfmtr2�nmemb�_rK�
multiplier�items�itemr4r4r5�struct_items�s
 recCs�|dkr tt|t�}|dkrBttt|��}tt|t�}|d|t|ro|nd�}t|||�}t||�}|j	d�||}|||fS)z"Return random format, items, item.NrOrrY)
rr[r\rSrFr^r_rXrUr])rrLrJrKrbr2rcrdr4r4r5�	randitems�s$rfccsFx?t|tD]/}x&t|D]}t||||�Vq WqWdS)z1Iterate through supported mode/char combinations.N)r[r\rFrf)rrLrJrKr4r4r5�	iter_mode�srgccsAxt||�D]}|VqW|dkr/dSt||�VdS)zwYield (format, items, item) for all possible modes and format
       characters plus one random compound format string.rN)rgre)�nitemsZtestobj�tr4r4r5�iter_format�s
	rjcCs"d|kp!d|kp!d|kS)Nrrrr4)r2r4r4r5�is_byte_format�srkcCsFt|�}|dks4|dkoE|ddkoE||dtkS)zformat suitable for memoryviewrrrr8)rR�
MEMORYVIEW)r2rMr4r4r5�is_memoryview_format�s(rmcCs"g|]}t|�s|�qSr4)rk)�.0rr4r4r5�
<listcomp>�s	rocCst|t�S)z9Tuple items (representing structs) are regarded as atoms.)�
isinstance�list)rWr4r4r5�atomp�srrcCs
t|t�S)N)rprq)rWr4r4r5�listp�srscCsIt|�dkrdS|d}x"|dd�D]}||9}q1W|S)zProduct of list elements.rrN)rR)rWrM�vr4r4r5�prod�s
rucCs�|dkrfS|dkrst|dd��|g}x�t|ddd�D]}||||d9<qPWnM|gt|dd��}x-td|�D]}||||d9<q�W|S)	zOCalculate strides of a contiguous array. Layout is 'C' or
       'F' (Fortran).r�CrNr���rwrw)rqrV)�ndim�shape�itemsizeZlayout�stridesrr4r4r5�strides_from_shapesr|cCs�t|�r|St|�dkr*|dSdg|d}|drYt|�|dnd}xMt|d�D];}||}t||||�|dd��||<qpW|S)zmConvert flat item list to the nested list representation of a
       multidimensional C array with shape 's'.rrN)rrrRrV�_ca)rc�srW�strider�startr4r4r5r}s$
/r}cCs�t|�r|St|�dkr*|dSdg|d}|d}xBt|d�D]0}t||d|�|dd��||<qVW|S)zsConvert flat item list to the nested list representation of a
       multidimensional Fortran array with shape 's'.rNr)rrrRrV�_fa)rcr~rWrrr4r4r5r�s
.r�cCsIt|�r<d|kr<t|�t|�kr<td��t||�S)Nrzprod(shape) != len(items))rsrurR�
ValueErrorr})rcryr4r4r5�carray*s0r�cCsIt|�r<d|kr<t|�t|�kr<td��t||�S)Nrzprod(shape) != len(items))rsrurRr�r�)rcryr4r4r5�farray/s0r�cCsdd�|D�}t|�S)z(Generate all possible tuples of indices.cSsg|]}t|��qSr4)rV)rnrtr4r4r5ro6s	zindices.<locals>.<listcomp>)r)ry�	iterablesr4r4r5�indices4sr�cCs7d}x*t|�D]}|||||7}qW|S)zAConvert multi-dimensional index to the position in the flat list.r)rV)rx�indr{Zretrr4r4r5�getindex9sr�c	Cs�|s
|St|�}t||dd�}t||ddd�dd�}dgt|�}xSt|�D]E}t|||�}t||ddd�|�}||||<qmW|S)z�Transpose flat item list that is regarded as a multi-dimensional
       matrix defined by shape: dest...[k][j][i] = src[i][j][k]...  rrvNrrwrw)rRr|r�r�)	�srcryrxZsstridesZdstrides�destr�ZfrZtor4r4r5�	transpose@s"r�cCsE|gkr|St|�r#|gSt|d�t|dd��S)zflatten listrrN)rr�_flatten)rWr4r4r5r�Os
r�cCst|�r|St|�S)zflatten list or return scalar)rrr�)rWr4r4r5�flattenWsr�cCs@t|�rgSt||d�gt|d|dd��S)zMGet the shape of lst after slicing: slices is a list of slice
       objects.rrN)rrrR�slice_shape)rW�slicesr4r4r5r�]sr�cs/t|�r|S�fdd�|�dD�S)z=Multi-dimensional slicing: slices is a list of slice objects.cs)g|]}t|�dd���qS)rN)�
multislice)rnZsublst)r�r4r5rohs	zmultislice.<locals>.<listcomp>r)rr)rWr�r4)r�r5r�dsr�csWt|�r|S��fdd�t|�d|�d�D�}||�d<|S)a�Multi-dimensional slice assignment: llst and rlst are the operands,
       lslices and rslices are lists of slice objects. llst and rlst must
       have the same structure.

       For a two-dimensional example, this is not implemented in Python:

         llst[0:3:2, 0:3:2] = rlst[1:3:1, 1:3:1]

       Instead we write:

         lslices = [slice(0,3,2), slice(0,3,2)]
         rslices = [slice(1,3,1), slice(1,3,1)]
         multislice_assign(llst, rlst, lslices, rslices)
    c	s?g|]5\}}t||�dd��dd���qS)rN)�m_assign)rnr�r)�lslices�rslicesr4r5ro{s	zm_assign.<locals>.<listcomp>r)rr�zip)�llst�rlstr�r�r4)r�r�r5r�js#r�cCs�t||�}t||�}t|�t|�kr:dSxFtt|��D]2}||||krkdS||dkrMdSqMWdS)z9Compare the structure of llst[lslices] and rlst[rslices].rrrwrw)r�rRrV)r�r�r�r��lshape�rshaperr4r4r5�
cmp_structure�sr�cCs:t||||�dkr'td��t||||�S)z:Return llst after assigning: llst[lslices] = rlst[rslices]rz+lvalue and rvalue have different structures)r�r�r�)r�r�r�r�r4r4r5�multislice_assign�sr�cs�|�rdS|dks*|�|kr.dSt�fdd��D��rQdS|dkru|dkot�ot�Sd�kr�dSt��fdd�t|�D��}t��fdd�t|�D��}d||ko�||�|kS)z�Verify that the parameters represent a valid array within
       the bounds of the allocated memory:
           char *mem: start of the physical memory block
           memlen: length of the physical memory block
           offset: (char *)buf - mem
    Frc3s|]}|�VqdS)Nr4)rnrt)rzr4r5�	<genexpr>�sz#verify_structure.<locals>.<genexpr>Tc3s5|]+}�|dkr�|�|dVqdS)rrNr4)rn�j)ryr{r4r5r��sc3s5|]+}�|dkr�|�|dVqdS)rrNr4)rnr�)ryr{r4r5r��s)�any�sumrV)�memlenrzrxryr{�offset�imin�imaxr4)rzryr{r5�verify_structure�s
((r�cCsx|D]}||}qW|S)Nr4)rWr�rr4r4r5�get_item�s
r�c
CsO|\}}}}}}|}x*t|�D]}	|||	||	7}q+W|S)z-Location of an item in the underlying memory.)rV)
r�rir�rzrxryr{r��prr4r4r5�memory_index�s
r�cCsn|\}}}}}}d|>}xEt|�D]7}t||�}	d|	>}
||
@r\dS||
O}q/WdS)z�The structure 't' is overlapping if at least one memory location
       is visited twice while iterating through all possible tuples of
       indices.rTF)r�r�)rir�rzrxryr{r�Zvisitedr�rZbitr4r4r5�is_overlapping�s


r��cs�s	t|d�}|dkr�|r>|||ffdfStdd�}||}td�dkrp|n|}|||ff|fSd}	td�}
|
dkr�|r�d}	n|
dkr�d}	dg|�x:t|�D]}t|	|d��|<q�Wnt��}d}td�}
|
dkrC|
d@rCd	nd
}
dg|�|t||d��|d<|
r��|ddkr�|�|d<x�t|ddd�D]z}|�|dr��|dnd9}|
r|t||d��|<q�dtd�|td|d��|<q�Wd}}d�kr�t��fdd�t|�D��}t��fd
d�t|�D��}||}|r�||}||d|}n2|||}td�dkr�||n|}|||��|fS)z�Return random structure:
           (memlen, itemsize, ndim, shape, strides, offset)
       If 'valid' is true, the returned structure is valid, otherwise invalid.
       If 'shape' is given, use that instead of creating a random shape.
    rrr$r�d�_�Zr�TFc3s5|]+}�|dkr�|�|dVqdS)rrNr4)rnr�)ryr{r4r5r�sz!rand_structure.<locals>.<genexpr>c3s5|]+}�|dkr�|�|dVqdS)rrNr4)rnr�)ryr{r4r5r�s�rwrwrw)rrw)rrVrRr�)rzZvalid�maxdim�maxshaperyrxrhr�r��minshaperrZ	maxstrideZzero_strider�r�r4)ryr{r5�rand_structure�sT
	
"
 &-
((
#r�c
Cs�||}t|d�}|r.|||nd}td|d�}|||}t|||�}t||�\}}}}	|	|kr�t�|S)z=Create a random slice of len slicelen that fits into listlen.r)r�slice�
slice_indices�RuntimeError)
�slicelenZlistlenZmaxstartr�Zmaxstep�step�stopr~raZcontrolr4r4r5�randslice_from_slicelens
r�cCs�dg|}dg|}xit|�D][}||}|dkrVtd|d�nd}t||�||<t||�||<q'Wt|�t|�fS)zxCreate two sets of slices for an array x with shape 'shape'
       such that shapeof(x[lslices]) == shapeof(x[rslices]).rr)rVrr�rS)rxryr�r�rrr�r4r4r5�randslice_from_shape,s


%r�cCs;td|d�}d}td�}|dkr:d}n|dkrLd}td�dkrddnd	}dg|}dg|}dg|}dg|}	x~t|�D]p}t||d�}
t||d�}||
kr�|
|}}
|rot|
|
d�}t|
|
d�}
dtd�td|
d�}t||
|�}t||
�\}}}}n4|
dkr�td|
d�nd}t||
�}t||�}td�dkr�||
||<||<|||	|<||<q�|
|||<||<|||	|<||<q�W||t|�t|	�fS)z�Create (lshape, rshape, tuple(lslices), tuple(rslices)) such that
       shapeof(x[lslices]) == shapeof(y[rslices]), where x is an array
       with shape 'lshape' and y is an array with shape 'rshape'.rrr�r�rr��PTFrw)rrw)rrVr�r�r�rS)r�r�rxr�rZ
all_randomr�r�r�r�ZsmallZbigr�r�r�Zs_smallrar�Zs_bigr4r4r5�rand_aligned_slices8s@	




!%r�cCs0|\}}}}}}t||d|d�S)zMReturn a list of random items for structure 't' with format
       'fmtchar'.rOrC)rX)r2rir�rzrar4r4r5�randitems_from_structurecsr�c

CsD|\}}}}}}	t|d|d|d|d|	dt|B�S)z:Return ndarray from the tuple returned by rand_structure()ryr{�formatr��flags)r�ND_WRITABLE)
rcr2rir�r�rzrxryr{r�r4r4r5�ndarray_from_structureisr�cCs�|\}}}}}}t|�}	x4t|�D]&\}
}tj||	|
||�q1Wtd|	d|d|d|d|�S)z>Return numpy_array from the tuple returned by rand_structure()�bufferryr{�dtyper�)�	bytearray�	enumerater/�	pack_into�numpy_array)rcr2rir�rzrxryr{r��bufr�rtr4r4r5�numpy_array_from_structureosr�csH|j}|r2t|��|kr�d|fSnh|gkrf|jdksY�|kr�d|fSn4t|��\}}|g}|dkr�d|fS|j����fdd�tdt����D�}g}xG|D]?}	tj||	�d}
|
|
krd|fS|j	|
�q�W|gkr:||fS|d|fS)a�Interpret the raw memory of 'exporter' as a list of items with
       size 'itemsize'. If shape=None, the new structure is assumed to
       be 1-D with n * itemsize = bytelen. If shape is given, the usual
       constraint for contiguous arrays prod(shape) * itemsize = bytelen
       applies. On success, return (items, shape). If the constraints
       cannot be met, return (None, None). If a chunk of bytes is interpreted
       as NaN as a result of float conversion, return ('nan', None).Nrcs$g|]}�||���qSr4r4)rnr)rz�memr4r5ro�s	zcast_items.<locals>.<listcomp>�nan)
�nbytesrurx�divmod�tobytesrVrRr/rIrQ)Zexporterr2rzryZbytelenrr�Z	byteitemsrcrtrdr4)rzr�r5�
cast_items}s(	

	
.

r�c#s�xtd�D]}|gVq
Wtdd�}td�dkrFdnd��fdd	�t|�D�Vtdd�}td�dkr�dnd��fd
d	�t|�D�VdS)z Generate shapes to test casting.r&��r�r�rrcsg|]}t�d��qS)r�)r)rnra)r�r4r5ro�s	z!gencastshapes.<locals>.<listcomp>csg|]}t�d��qS)r�)r)rnra)r�r4r5ro�s	N)rVr)rrxr4)r�r5�
gencastshapes�sr�cCs:tt||d�t||d�t||d��S)z4Generate all possible slices for a single dimension.r)rrV)rr4r4r5�	genslices�sr�cs)�fdd�t|�D�}t|�S)z/Generate all possible slice tuples for 'shape'.cs g|]}t�|��qSr4)r�)rnr)ryr4r5ro�s	z"genslices_ndim.<locals>.<listcomp>)rVr)rxryr�r4)ryr5�genslices_ndim�sr�FcCs>|s|dkrdnd}t||d�}t||�S)z�Generate random slice for a single dimension of length n.
       If zero=True, the slices may be empty, otherwise they will
       be non-empty.rr)rr�)r�allow_emptyZminlenr�r4r4r5�rslice�sr�ccs)x"td�D]}t||�Vq
WdS)z.Generate random slices for a single dimension.r�N)rVr�)rr�rar4r4r5r��sr�c#s�x8t|�D]*}t�fdd�t|�D��Vq
Wx8t|�D]*}t�fdd�t|�D��VqHWtdd�t|�D��VdS)z)Generate random slice tuples for 'shape'.c3s|]}t�|�VqdS)N)r�)rnr)ryr4r5r��szrslices_ndim.<locals>.<genexpr>c3s%|]}t�|dd�VqdS)r�TN)r�)rnr)ryr4r5r��scss!|]}tddd�VqdS)rrN)r�)rnrar4r4r5r��sN)rVrS)rxryZ
iterationsrar4)ryr5�rslices_ndim�s
((r�ccsBt|�}|dkr$t|�n|}tt||��VdS)N)rSrRr)�iterabler�Zpoolr4r4r5�rpermutation�sr�cCs�y|j�}Wn$ttfk
r6|j�}YnXt|t�r[|j}|j}nd}d}td||j	|j
|j||j|j
|f�tjj�dS)zPrint ndarray for debugging.�unknownz_ndarray(%s, shape=%s, strides=%s, suboffsets=%s, offset=%s, format='%s', itemsize=%s, flags=%s)N)�tolist�	TypeError�NotImplementedErrorr�rprr�r��printryr{�
suboffsetsr�rz�sys�stdout�flush)�ndrMr�r�r4r4r5�
ndarray_print�s	r�r�rZ�r�z%struct module required for this test.z%ndarray object required for this testc@s�eZdZdd�Zd�dhd�dhdhd�d�d�dddd�
Zddd�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��ZRd�S)��TestBufferProtocolcCst�|_dS)N)Zget_sizeof_void_p�
sizeof_void_p)�selfr4r4r5�setUp�szTestBufferProtocol.setUprFc%s[|rt|��}n�s.t|	�}n�}f}
|jr|j|d�d}xStd|�D]B}||dkr�P||dkri|||||d7}qiW|gdd�t|d�D�}
|j}|ddkr�|}|gt|dd��}|j|j|�|j	|j
|�|j	|j��|j	|j��|j	|j
|�|j	|j|�|j	|jt|��|
o�|
s�|j	|jt|��|j	|jt|
��t|t�s�t��r"�r|j�n	|j�}|j	||	��s,dS|s�t�}d}x�t|�D]�}yet||�}t|	|�}t|t�r�tj�|�}ntj�|�}|j|�Wntk
r�d}PYnX|j	||�qNW|s�|j	|j�|�t|�}dj dd�|D��}|j	|j!�|��rO�nd	}t"|	�}xed
ddgD]T}|}|dkr�t#|d�s�t#|d
�rt$||�}t|d
|d|dt%�}nCt#|d�st#|d�r|d
krt|d
|d|�}t&|t'|��|j	�j�|�|j(t)�|��|dkrhqqt|�}|r�dnt*} t+|d
t,��|j	t��|�����fdd�t|�D�}!t|!d�dkrdd�|!D�}!t|!d
|d| d��}"|j	t|"�t|��t+|dt,��|j	t��|�����fdd�t|�D�}!t|!d�dkr�dd�|!D�}!t|!d
|d| t%Bd��}"|j	t|"�t|��t+|dt,��|j	t��|�����fdd�t|�D�}!t|!d�dkrldd�|!D�}!t#|d�r�t%nd}#t|!d
|d|#| Bd��}"|j	t|"�t|��qqWt��rWyt|�}Wntk
r�dSYnXt|t�r|jn|}$|j|j|$�|j	|j
|�|j	|j��|j	|j��|j	|j
|�|j	|j|�|j	|jt|��|
o�|
s�|j	|jt|��|j	|jt|
��|dkr�dn	t|	�}|j	t|�|��r+|j�n	|j�}|j	||	�|j	||�dS)NrrcSsg|]}d�qS)rrwr4)rnrtr4r4r5ros	z-TestBufferProtocol.verify.<locals>.<listcomp>Tr7css|]}d|VqdS)z%02xNr4)rnrr4r4r5r�Nsz,TestBufferProtocol.verify.<locals>.<genexpr>rrv�F�Aryr�r�cs)g|]}tj��|���qSr4)r/�unpack_from)rnr)�contigr2rzr4r5roys	cSsg|]}|d�qS)rr4)rnrtr4r4r5ro|s	cs)g|]}tj��|���qSr4)r/r�)rnr)r�r2rzr4r5ro�s	cSsg|]}|d�qS)rr4)rnrtr4r4r5ro�s	cs)g|]}tj��|���qSr4)r/r�)rnr)r�r2rzr4r5ro�s	cSsg|]}|d�qS)rr4)rnrtr4r4r5ro�s	)-rurRr�Z
assertGreaterrVr�rq�assertIsrL�assertEqualr�rzr��readonlyrxryrSr{rprrmr�r�r�r��get_pointerr�r/r0�extend�BufferErrorrD�join�hexr��
is_contiguousr��
ND_FORTRAN�get_contiguous�
PyBUF_READ�
assertTrue�
cmp_contigr��py_buffer_to_contiguous�
PyBUF_FULL_RO)%r��resultrLrzr2r�rxryr{rW�sliced�castZexpected_lenr�Z
suboffset0rZstride0ZreprZbuf_errr�Zitem1Zitem2rMr=rZffZ	flattened�order�expectedZtransr`�roZinitlst�yr�exr4)r�r2rzr5�verify�s�	$		
	" 
	zTestBufferProtocol.verifycCs9dd�}dd�}|jr0||t�s�||t�rI|js�||t�rb|js�||t�r{|js�||t�r�|j	s�||t
�r�|js�||t�r�||t�r�|j
tt|d|�dSt|t�st|j�r|j�}nt|dt�}|j�}||t�rJdn|j}	|j}
|j}|j}||t�s�d}
|j�}||t�s�d}||t�r�|jnf}
||t
�r�|jnf}t|d|�}|j|d	|d
|d|
d|	d
|d|
d|d|d|�	dS)NcSs|jdkp|jdkS)Nr7r)r�)rr4r4r5�
simple_fmt�sz4TestBufferProtocol.verify_getbuf.<locals>.simple_fmtcSs||@|kS)Nr4)�reqZflagr4r4r5�match�sz/TestBufferProtocol.verify_getbuf.<locals>.match�getbufrr7rrLrzr2r�rxryr{rWr�)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�assertRaisesr�rrprmr�r�r�rzrxr�ryr{r)r�Zorig_exrrr�rrrWr�rr2rzrxryr{r4r4r5�
verify_getbuf�s>			z TestBufferProtocol.verify_getbufcs�tttttttttt	t
ttt
tf}dd�td�D�dfddddd	d
ddd
dddgdfddddd	d
ddd
dddgdfdd�td�D�dff}ggdfdddggdfdggdfdgd gdfd
gdgdfd
gd!gdfddggdfddgd"d#gdfddgddgdfddgd$d%gdff
}dttttBtttBf}dttttBf}x|D]\}}tj|��x�|D]�\}}	}
�fdd�|	D�}	|
�9}
x�|D]�}|	rB|t@rBq)|rV|t@rVq)|rb|n|d}t|d|d|d|d|	d|
�}
|r�|
ddd&�nd}t|
�}|r�t|�}|
jdks�|
jdkr
|r
|	r
|j||
�|r>|jdkr>|r>|	r>|j||�x�|D]�}x||D]t}|j|
|
||B�|j|
|||B�|rR|j||||Bdd�|j||||Bdd�qRWqEWq)Wq�Wq�Wddddd	d
ddd
dddg}t|ddgdt�}|jtt|�td
gdg�}t|dt�}|jtt|dt�|jtt|dt�|jtt|dt�|jtt|dt�|jtt|dt�|jtt|dt�t|dt�}x�dddgdddgfD]�}x�dtfD]�}t|d|d|tB�}|jt |d��|jt |d��xL|D]D}t|d|�}|jt |d��|jt |d��q�Wq3Wq WdS)'NcSs&g|]}|drdnd�qS)rTFr4)rnrMr4r4r5ro�s	z:TestBufferProtocol.test_ndarray_getbuf.<locals>.<listcomp>�r
rrr�r�r�r�r"r!�	rZ�rrcSs.g|]$}|dr d|nd|�qS)rr%lli�r4)rnrMr4r4r5ro�s	rrcsg|]}|��qSr4r4)rnrt)rzr4r5ros	r�r�ryr{r�r�Tr	r�rvrw������rwrrwr)!rrr�PyBUF_SIMPLErr
r�
PyBUF_FULLr��
PyBUF_RECORDS�PyBUF_RECORDS_RO�
PyBUF_STRIDED�PyBUF_STRIDED_RO�PyBUF_CONTIG�PyBUF_CONTIG_ROrVr�r��ND_PILr
rr/�calcsizerrDrxr�r�ND_GETBUF_FAILrr�r�r�)r��requestsZ	items_fmtZ	structureZndflagsZ
real_flagsrcr2ryr{r�r�Z_items�ex1�ex2�m1�m2r�bitsr�baser�rr4)rzr5�test_ndarray_getbuf�s�	--"	


*!

*%
z&TestBufferProtocol.test_ndarray_getbufc
CsU
tdgdg�}tdgdgdt�}xHt|j|jfD]1}|jt|dddh�|jt|dddg�|jt|ddd)g�|jt|dddgddh�|jt|dddgddgd	dh�|jt|dddgddgd
g�|jt|dgddgdi�|jt|dgddgdi�|jt|dgddgdi�|jt|dgddgd	dgdt�|jt|dgdgdt�|jt|gddg�|jt|d
gddgdd�|jtj	|dgddgdd�|jt|dd*gddgdd�|jt|dddgddgdd�t
d}|jt|dg|ddg|�|jt|dgdd+g�|jt|dddgddg�|jt|dgdd,g�|jt|dddddgdddgd
d�|jt|dddgddgd	dg�|jt|dgddgd	d-g�|jt|ddgdddgd	dg�|jt|ddddgddgd	dgdd�|jt|dddgddgd
d�|jt|dddgddgd
ddd�|jt|dddgddgdd�|jtj	|d.gddgdd�ddddddddddg
}|jt||dddgd	d/d0gd
d�|jt|t�dd�|jt|dgddgdt
�|jt|dg�qFW|jttddt�tdgdgdt�}|jt|jdgdgdt�td�}|jt|jdgdg�|jt|j�tdgdg�}|jdgdg�t|�}|jt|jdgdg�|jt|j�|j�|j�|jt|j�~|jttidddg�|jttdi�tttd��ddgd�}|jtt|dg�tttd��dddg�}|jtt|dddg�|jtt|ddg�|jtt|d1dg�|jtt|d2dg�tdddgddgdd�}t|dt�}|jt|j�tdddgddgdd�}t|�}	t|	�}|jt|j�td3d gddgddd �}|jt|j�t
}ttt|��ddg|�}|jt|j�tdgddg�}|jttddddd�|jtt|d!d"�|jtt|d4d"�|jtt|td#�|jtt|td$�|jtt|td%�|jtt|d&d'�tdgddg�}|jttddddd�|jtti|�|jtt|i�tdgddg�}|jttddddd�|jttid'�|jtt|d(�dS)5Nrrr�rr�rAr�ryr{r�r�r	ZXXXri�rZQLr)r�r?r7z@#$r�r"r!rZrs123r�rr���xyzrvi�u �Z�r���)r�r�)rr�rwl	l	)rrr����rr4l)rl)r�ND_VAREXPORT�pushrr�r�r$r�r/r1ZND_MAX_NDIM�
OverflowErrorr�rr�r
�poprD�releaser�rqrVrr��memoryview_from_bufferr�r��UnicodeEncodeErrorr�r�)
r�r�Zndmrrrcr=rr(r)r4r4r5�test_ndarray_exceptionsLs�%.+%%%'"%((+
'%4.
.0+*+!$%%

%$$$&%z*TestBufferProtocol.test_ndarray_exceptionscCs�x�ttd��D]�}dgd}tdddgddgdt�}t|�|d<xFtdd�D]5}|jdddgddg�t|�||<qjWx&td�D]}|||j�q�W|jt|j	�~qWdS)Nr�rrrr�ryr�)
rrVrr5rDr6r9rr�r8)r�Zpermr=r�rr4r4r5�test_ndarray_linked_list�s
$z+TestBufferProtocol.test_ndarray_linked_listcCs�x�td�D]s\}}}tj|�}t|dfd|�}|j|ddd|d|ddd	ddfd
fd|�q
WdS)Nrryr�rLrzr2r�rrxr{rW)rjr/r%rr)r�r2Zscalarrarzr�r4r4r5�test_ndarray_format_scalar�sz-TestBufferProtocol.test_ndarray_format_scalarcCs�tdd�}x�t|�D]�\}}}tj|�}xxdtfD]j}t|d|gd|d|�}|j|ddd|d	|d
dddd|fd|fd
|�qGWqWdS)NrrZrryr�r�rLrzr2r�rxr{rW)rrjr/r%r$rr)r�rhr2rcrarzr�r�r4r4r5�test_ndarray_format_shapes!z,TestBufferProtocol.test_ndarray_format_shapecCs?tdd�}x)t|�D]\}}}tj|�}x�tdd�D]�}|dkr_qJt|dd|��g}||g}|dkr�||dnd}	x�dtfD]z}
t|d|d|d|d|	d	|
�}|j|d
dd|d|d
dddd|d|d|dd|��q�WqJWqWdS)Nr�r�rryr{r�r�r�rLrzr2r�rxrW���)	rrjr/r%rVrRr$rr)r�rhr2rcrarzr�ryr{r�r�r�r4r4r5�test_ndarray_format_stridess 
 z.TestBufferProtocol.test_ndarray_format_stridescCs{ddddddddd	d
ddg}t|d
ddd�}t|dttB�}|j|j�t|d��dS)Nrrr�r�r�r�r"r!rrZrrryr{r	)r�r�)rr�)r�r�)rr
rr�r�r�)r�rcrr�r4r4r5�test_ndarray_fortran%s*z'TestBufferProtocol.test_ndarray_fortrancCsHxAtd�D]3}dd�t|�D�}t|�}xt|�D]�}t|�\}}}tj|�}x�dtfD]�}	|dkr�|	tkr�q|t|d|d|d|	�}
t|||d�}t	||�}|j
|
d	dd
|d|dd
d|d|d|d|�t|�r�t|d|d|�}
t|
dtt
B�}
|j|
jfk�|
j�}|j
|d	dd
|d|dd
d|d|d|d|�t|d|d|d|	tB�}
t|||d�}t||�}|j
|
d	dd
|d|dd
d|d|d|d|�q|WqEWq
WdS)Nr�cSsg|]}tdd��qS)rrZ)r)rnrar4r4r5ro-s	z<TestBufferProtocol.test_ndarray_multidim.<locals>.<listcomp>rryr�r�rvrLrzr2r�rrxr{rWr	r�)rVrurrfr/r%r$rr|r�rrmr#rr�r{r:r�r�)r�rx�shape_trhryr2rcrarzr�r�r{rWr�mvr4r4r5�test_ndarray_multidim+sB
z(TestBufferProtocol.test_ndarray_multidimcCs�tdgddg�}|jt|jdd�t|�}|j||�|jt|jdd�tdgddgdt�}|jt|jd�t|�}|j||�|jt|jd�tdgddgdt�}|jt|j	d�|jt|jdd�t|�}|j||�|jt
|j	d�|jt
|jdd�ddddd	d
ddg}t|dt|�gdd
dt�}|jtj
|jdd�|jt|jdd�t|�}|j||�|jt|jdd�|jt|jdd�dddg}t|dt|�gdddt�}|jt|jdd�|jtj
|jdd�dS)Nrryr!r�rrr�r�r�r�r"r�ri,r�r/ZLQ�1llll)r�r/)r�r/)rr)r�r�)r�r�)rGr/)rrr��__setitem__rDr�r��__delitem__r7�__getitem__�
IndexErrorrRr/r1r�)r�r�rErcr4r4r5�test_ndarray_index_invalidXs:''z-TestBufferProtocol.test_ndarray_index_invalidcCs�tddfdt�}t|�}|j||�|f}|j|d�|d}|j|j�|j��|f}|j|d�|d}|j|j�|j��|jt|jd�|jt|jd�|jt|jdd�|jt|jdd�|j|j�d�|j|j�d�d|f<|j|j�d�d|f<|j|j�d�d|d<|j|j�d�d|d<|j|j�d�dS)	Nrryr�.rr!rr�)	rr�rDr�r�rr�rJrH)r�r�rErMr4r4r5�test_ndarray_index_scalars2







z,TestBufferProtocol.test_ndarray_index_scalarcCsxtttd	��dddgdt�}t|dt�}|jt|jd�|jt|jtddd��dS)
Nrr�ryr�r	rr�r�r!)	rrqrVr�r"rr�rJr�)r�rr�r4r4r5�test_ndarray_index_null_strides�s*z2TestBufferProtocol.test_ndarray_index_null_stridesc	Cs�xtd�D]\}}}t|ddgd|�}x/tdd�D]}|j||||�qGW|jt|jd�|jt|jd�t|�r
t|�}|j||�x/td
d�D]}|j||||�q�W|jt|jd�|jt|jd�q
Wx�td�D]�\}}}t|ddgdt	d|�}t|dt
tB�}x/tdd�D]}|j||||�q�Wt|�r,|j�}|j
|j|�t�x/tdd�D]}|j||||�q�Wq,Wddd	d
dg}t|ddg�}t|dt�}x/tdd�D]}|j||||�qWWddd	d
dg}t|ddg�}t|dt�}x/tdd�D]}|j||||�q�WdS)Nr�ryr�r�r�r	rrr�r�rAi����rAi����rArArArA)rjrrVr�rrKrJrmrDr�r"rr:r��__eq__�NotImplementedr#r)r�r2rcrar�rrErr4r4r5�!test_ndarray_index_getitem_single�sB! z4TestBufferProtocol.test_ndarray_index_getitem_singlec	Cs�xptd�D]b\}}}t|ddgd|dt�}x(td�D]}|||<|||<qJW|j|j�|�|jt|jd|�|jt|jd|�t	|�s�q
t|ddgd|dt�}t
|�}|j||�x(td�D]}|||<|||<q	W|j|j�|�|jt|jd	|�|jt|jd|�q
Wx2td�D]$\}}}t|ddgd|dt�}x;td
d�D]*}||d||<||d||<q�W|j|j�|�t	|�sq�t|ddgd|dt�}t
|�}|j||�x;tdd�D]*}||d||<||d||<q`W|j|j�|�q�WdS)Nr�ryr�r�r�r�ri����i����rArA)rjrr�rVr�r�rrKrHrmrD)r�r2rcZsingle_itemr�rrEr4r4r5�!test_ndarray_index_setitem_single�sD!
!
!!z4TestBufferProtocol.test_ndarray_index_setitem_singlec
Cs`d	}t|�}xGt|�D]9}t|�\}}}xdtfD]
}t|d|d|d|�}t||�}	x�t|d|d�D]�}
|j|	|
||
j��x�t|d|d�D]w}|j|	|
|||
|j��xHt|d|d�D].}|j|	|
||||
||�qWq�Wq�Wt|d|d|d|t	B�}t
||�}	x�t|d|d�D]�}
|j|	|
||
j��x�t|d|d�D]v}|j|	|
|||
|j��xGt|d|d�D].}|j|	|
||||
||�qWq�Wq�WqGWqWdS)
Nrr�r�rryr�r�r)rr�r�)rurrfr$rr�rVr�r�r�r�)
r�rDrhryr2rcrar�r�rWrr��kr4r4r5�#test_ndarray_index_getitem_multidims,&4
&z6TestBufferProtocol.test_ndarray_index_getitem_multidimcCs?tddf�}|jttdt��t|�}|j||�|jttdt��x�td�D]�\}}}t|ddgd|�}xAt|�D]3\}}|j|||�|j	||k�q�Wt
|�rmt|�}xAt|�D]3\}}|j|||�|j	||k�qWqmWdS)Nrryz1 in ndz1 in mvr�r�)rrr��eval�localsrDr�rjr�r�rm)r�r�rEr2rcrarrtr4r4r5�test_ndarray_sequencesz(TestBufferProtocol.test_ndarray_sequencecCs
ddddddddg}t|d	dgd
t�}t|�}|jt|jtddd�|�|jt|jtddd�|�t|d	dgd
t�}t|d	dgd
t�}t|dt�}|jt|jtddd�|�t|d	dgd
dd
t�}t|�}|jt	|j
tddd��|jt	|j
tddd��t|d	ddgd
dd
t�}t|�}|jt	|j
tddd�tddd�f�|jt	|j
tddd�tddd�f�|jt|j
d�|jt|j
dtddd�f�|jt|j
tddd�if�|jt|j
tddd�tddd�f�|jt|j
d�t|d	dgd
dd
t�}t|d	dgd
d�}t|�}t|�}|jt	|jtddd�|dd��|j|j
�|�|jt	|jtddd�|dd��|j|j
�|�t|d	dgd
dd
t�}t|d	dgd
d�}	t|�}t|�}|jt	|jtddd�|dd��|j|j
�|�|jt	|jtddd�|dd��|j|j
�|�t|d	ddgd
dd
t�}t|d	dgd
d�}t|�}t|�}|jt	|jtddd�|dd��|j|j
�ddddgddddgg�|jt|jtddd�|dd��t|d	dgd
dd
t�}t|d	dgd
d�}t|�}t|�}|jt	|jtddd�|dd��|j|j
�|�|jt	|jtddd�|dd��|j|j
�|�|jtttddd�i�|jttdd�|jt	ttddd�d�t|d	dgd
dd
t�}
|jt|
j�t|d	dgd
d�}t|dt�}
|jt|
j�dS)Nrrr�r�r�r�r"r!ryr�rr	r�rz@%$rrz###########)rr�rDrr�rHr�rr�r�rJr�r�r�r�r$�add_suboffsetsr)r�rc�xl�mlr�xrr�rE�mr�yrrMr4r4r5�test_ndarray_slice_invalid2s�%%%!""$%%((%!//!//$/4!//""!z-TestBufferProtocol.test_ndarray_slice_invalidcCs�ddddddddd	d
ddg}t|d
dgdddt�}t|d
dgdd�}|d	d	�|dd�<|j|j�|�t|�}t|�}|j||�|j||�|d	d	�|dd�<|j|j�|�t|d
ddgdddt�}t|d
ddgdd�}|dd�dd�f|dd�dd�f<|j|j�t|ddg��dS)Nrrr�r�r�r�r"r!rrZrrryr�rr�)rr�r�r�rDr�)r�rcrMrrZr\r4r4r5�test_ndarray_slice_zero_shape�s*!$2z0TestBufferProtocol.test_ndarray_slice_zero_shapec"Csd}t|�}t|�}xZt|�D]L}t|�\}}}tj|�}xdtfD]}	t|d|d|d|	�}
t||�}x�t	||�D]�}d}
yt
||�}Wn.tk
r�}z|j}
WYdd}~XnXd}y|
|}Wn.tk
r9}z|j}WYdd}~XnX|sF|
rY|j
||
�q�|j|j�|�q�WqbWq+WdS)	Nrr�r�rryr�r�)rr�r�)rRrurrfr/r%r$rr�r�r��	Exception�	__class__r�r�r�)r�rDrxrhryr2rcrarzr�r�rWr��listerrr��e�nderr�ndslicedr4r4r5�test_ndarray_slice_multidim�s.z.TestBufferProtocol.test_ndarray_slice_multidimc!Cs�d}t|�}t|�}xut|�D]g}t|�\}}}tj|�}t|d|d|�}	|	j�t|d|d|�}
|
j�t|
�}t	||�}x�t
||�D]�}
d}yt||
�}Wn.tk
r}z|j
}WYdd}~XnXd}y|	|
}Wn.tk
rX}z|j
}WYdd}~XnX|se|rx|j||�q�|j|j�|�q�Wq+WdS)Nrr�r�ryr�)rr�r�r)rRrurrfr/r%rrXrDr�r�r�r`rar�r�r�)r�rDrxrhryr2rcrarzr�rrErWr�rbr�rcrdrer4r4r5�'test_ndarray_slice_redundant_suboffsets�s4

z:TestBufferProtocol.test_ndarray_slice_redundant_suboffsetsc@Cs�x�td�D]�\}}}x�td�D]�}x�td�D]~}xudtfD]g}|tB}t|ddgd|d|�}t|ddgd|d|�}	t|	�}
d}d}|dd�}
y>|
|}|
|}|
||
|<t|�t|�k}Wn.tk
r7}z|j}WYdd}~XnXd}y||||<Wn.tk
r�}z|j}WYdd}~XnX|r�|j	|t
�n&|j|j�|
�|j	||�t
|�s�qOd}y|
||
|<Wn.tk
r}z|j}WYdd}~XnX|r1|j	|t
�qO|j|
j�|
�|j|
|�|j	||�|j|
d|	d|jd|d	dd
|jd|jd|jd|j��qOWq<Wq)Wq
WdS)
Nr�rryr�r�rLrzr2r�rxr{rW)rjr�r$r�rrDrRr`rar�r�r�r�rmrrzrxryr{)r�r2rcra�lslicer�r�rr�rrEZlsterrZdiff_structurerWZlvalZrvalrcrdZmverrr4r4r5� test_ndarray_slice_assign_single�sV
!!

z3TestBufferProtocol.test_ndarray_slice_assign_singlec"Cs�d}t|�}t|�}xkt|�D]]}t|�\}}}x?dtfD]1}x(tt�D]}t||�\}	}
t|d|d|d|t	B�}t
||�}d}
yt|||	|
�}Wn.tk
r}z|j
}
WYdd}~XnXd}y||
||	<Wn.tk
rJ}z|j
}WYdd}~XnX|sW|
rj|j||
�qf|j|j�|�qfWqSWq+WdS)	Nrr�r�rryr�r�)rr�r�)rRrurrfr$rV�
ITERATIONSr�rr�r�r�r`rar�r�r�)r�rDrxrhryr2rcrar�r�r�r�rWrbr�rcrdr4r4r5�"test_ndarray_slice_assign_multidims0
z5TestBufferProtocol.test_ndarray_slice_assign_multidimcCs�x�tt�D]�}x�tdD]�}tj|�}t|ddtdt�}|jt	|��t
||�}t|||�}|j�}t
|�}t|�r�|j�}	|j|	|�|ddkrJt|||dt�}
|
j�}|j||�t
|
�}t|�rJ|j||
�|j�}	|j|	|�tr|d}d|kriqt|||�}
|j|d	dd
|
jd|ddd
|
jd|
jd|
jd|
j��qWq
WdS)Nr8Tr�r�rrr�r�rLrzr2r�rxryr{rW)rVrjrFr/r%r��MAXDIM�MAXSHAPEr�r�r�r�r�rDrmr�r$r�r�rrzrxryr{)r�rar2rzrircrMZxlistrEZmvlistrZylistry�zr4r4r5�test_ndarray_random9s>	
z&TestBufferProtocol.test_ndarray_randomc Cs)x"tt�D]}xtdD]�}tj|�}t|ddtdt�}|jt	|��t
||�}d}yt|||�}Wn.tk
r�}z|j
}WYdd}~XnX|j|�trd}	yt|||�}
Wqtk
r}z|j
}	WYdd}~XqXqWq
WdS)Nr8Fr�r�)rVrjrFr/r%r�rlrm�assertFalser�r�r�r`rar�r�r�)r�rar2rzrircrdrMrcZ	numpy_errrr4r4r5�test_ndarray_random_invalidbs(	
z.TestBufferProtocol.test_ndarray_random_invalidcCsAx:tt�D],}x#tdD]}tj|�}tdtdt�\}}}}t|dd|�}t|dd|�}	|j	t
|��|j	t
|	��t||�}
t||	�}t|
||�}t|||	�}
|
|||<|j
�}|
j
�}t|�}t|
�}|j|j
�|�|j|j
�|�|ddkr*|	ddkr*t|
||dt�}t|||	dt�}||||<|j
�}|j
�}|j||�|j||�t|�}t|�}|j|j
�|�|j|j
�|�trd|ksd|krKqt|
||�}t|||	�}||||<t|�r�t|	�r�|j|d	dd
|jd|ddd
|jd|jd|jd|j
��|j|
d	dd
|jd|ddd
|jd|jd|jd|j
��qWq
WdS)Nr8r�r�Tryrrr�rLrzr2r�rxr{rW)rVrjrFr/r%r�rlrmr�r�r�r�r�r�rDr�r$r�r�r�rrzrxryr{)r�rar2rzr�r�r�r�ZtlZtrZlitemsZritemsrYr[ZxllistZxrlistrZr\Zylr]ZyllistZyrlistZzlZzrr4r4r5� test_ndarray_random_slice_assign~s\! z3TestBufferProtocol.test_ndarray_random_slice_assigncCs�ddddddddd	d
ddg}t|d
ddgdt�}t|�}|j|jt@�|j|j|�|j|jd�|j|j	�|j|j
�|j|j�dS)Nrrr�r�r�r�r"r!rrZrrryr�rrw)rrw)rr$r�r�r�rLr�r�rprrr)r�rcr�rr4r4r5�test_ndarray_re_export�s*z)TestBufferProtocol.test_ndarray_re_exportcCstxmdtfD]_}tdddgddgd|�}t|�}|j||�|j|j�g�|j|j�g�tdddgddddgd|�}|j|j�g�tdddgddddgd|�}|j|j�gggg�tdddgddddgd|�}|j|j�ggggggggggggg�q
WdS)Nrrrr�ryr�)r$rrDr�r�)r�r�r�rEr4r4r5�test_ndarray_zero_shape�s$***z*TestBufferProtocol.test_ndarray_zero_shapec	Cs�x�dtfD]�}tdgddgddgd|�}t|�}|j||�|j|j�dddddg�|j|j�dddddg�q
WdS)Nrrryr�r{r�)r$rrDr�r�)r�r�r�rEr4r4r5�test_ndarray_zero_strides�s'%z,TestBufferProtocol.test_ndarray_zero_stridescCs]tttd��ddgdd�}|j|jd�|j|j�dddg�dS)N�ryr�r�r"r!r)rrqrVr�r�r�)r�r�r4r4r5�test_ndarray_offset�s'z&TestBufferProtocol.test_ndarray_offsetcCs^xWdtfD]I}tttd��ddgd|�}|j�}|j||�q
WdS)Nrr�ryr�)r$rrqrVr:r�)r�r�r�r=r4r4r5�#test_ndarray_memoryview_from_buffer�s'z6TestBufferProtocol.test_ndarray_memoryview_from_buffercCsyxrdtfD]d}tttd��ddgd|�}x4td�D]&}|j||t||g��qGWq
WdS)Nrr�ryr�)r$rrqrVr�r�)r�r�r�rr4r4r5�test_ndarray_get_pointer�s'z+TestBufferProtocol.test_ndarray_get_pointercCs�tttd��ddddg�}t|dttB�}|j|j�|j��t|�}|j|j�|j��dS)Nrvryrr�r	)rrqrVrrr�r�rD)r�rr�r=r4r4r5� test_ndarray_tolist_null_strides�s
'z3TestBufferProtocol.test_ndarray_tolist_null_stridescCs�|jtdd��tttd��dddg�}tttd��dddg�}|jt||��tdgddgdd	�}|jt|d
��|jtd
|��dS)Ns123s456rryr�r�rr�rs)rpr�rrqrVr�)r�rMrr4r4r5�test_ndarray_cmp_contig�s$$z*TestBufferProtocol.test_ndarray_cmp_contigcCs�tjddddg�}t|�}|jtt|�tttd���}tttd��ddg�}|jt|�t|��tttd��dddg�}|jt|�t|��tttd��ddddg�}|jt|�t|��tt	ttd��dddg��}tttd��dddgdt
�}|jt|�t|��tt	ttd��ddddg��}tttd��ddddgdt
�}|jt|�t|��tttd���}tttd��ddddgdt�}|jt|�t|��tttd��ddddgd	d�}|jt|�t|j���dS)
Nrrrr�rryr�r�r�)
rBrrr��hashrGrqrVr�r�r�r$r�)r�r>r�rr4r4r5�test_ndarray_hashs*!$'**----z$TestBufferProtocol.test_ndarray_hashc
Cse	tttttttttt	t
tf}|jt
tidt�tddfdddt�}xPdddgD]?}x6|D].}t|||�}|j||j��q~WqqWtd	gdd
gdddt�}xJdddgD]9}x0|D](}t|||�}|j|d�q�Wq�Wtttd��dd
d
dgdddt�}xJdddgD]9}x0|D](}t|||�}|j|d�quWqhWxd
tgD]}td	gdd	gddd|tB�}|j�}xJdddgD]9}x0|D](}t|||�}|j||�q	Wq�Wtd	d
dgddgddd|tB�}|j�}xJdddgD]9}x0|D](}t|||�}|j||�q�Wq�Wq�Wtd	d
dgdd
gdd
gdt�}|j�}xPdddgD]?}x6ttgD](}t|||�}|j||�q Wq
W|ddd �}|j�}xfdddgD]U}xL|D]D}yt|||�}Wntk
r�w�YnX|j||�q�WqWttd��}x�d
tgD]�}t|dddgd|tB�}trdtdt|�dddgddd|d
kr[dnd�}	|tkr�tt|ddg�dddgdt�}
|
j�}n|j�}x�|D]�}yt|d|�}Wntk
r�w�YnX|j||�tdd�|D�dddgdt�}|jt|�t|��tr�|j||	jdd��q�W|d
kr�tt|ddg�dddgdt�}
nt|dddgdt�}
|
j�}x�tttttgD]�}yt|d|�}Wntk
rw�YnX|j||�tdd�|D�dddgdttB�}|jt|�t|��tr�|j||	jdd��q�W|tkr�t|dddgdt�}
|
j�}n|j�}x�tttttgD]�}yt|d|�}Wntk
r/w�YnX|j||�tdd�|D�dddgd|tB�}|jt|�t|��tr�|j||	jdd��q�Wq�Wtttd��dddgdttB�}t|dt�}|j||j��tdd�|D�dddgdt�}|jt|�t|��t|dt�}tt|ddg�dddgdt�}
|j||
j��tdd�|D�dddgdttB�}|jt|�t|��t|dt�}|j||j��tdd�|D�dddgdt�}|jt|�t|��dS)!Nr�rryr�rr�rvr�rr�r!rr"rr�rr{rr�r�r�rrcSsg|]}|�qSr4r4)rnrtr4r4r5ro�s	zCTestBufferProtocol.test_py_buffer_to_contiguous.<locals>.<listcomp>cSsg|]}|�qSr4r4)rnrtr4r4r5ro�s	cSsg|]}|�qSr4r4)rnrtr4r4r5ro	s	cSsg|]}|�qSr4r4)rnrtr4r4r5ro	s	cSsg|]}|�qSr4r4)rnrtr4r4r5ro	s	cSsg|]}|�qSr4r4)rnrtr4r4r5ro	s	rw)rrrrrr�rrr r!r"r#rr�r�rr�r�r�rqrVr�r�r�r�r�rDZtostringr$)
r�r'r�rZrequestrrZndbytesrWZnarMrrr4r4r5�test_py_buffer_to_contiguous0s�
$
*	
(
.
-

B"$	

+ $
/ 
/$.+-/+z/TestBufferProtocol.test_py_buffer_to_contiguouscCs�dgfdddgdgfttd��dddgfg}x/|D]'\}}t|d|�}t|�}|j|j�|j|j�t|�}t||dd�}t	||�}|j
|d|d	dd
dddd
|d|d|d|�t|�}	|j
|	d|d	dd
dddd
|d|d|d|�t|dttB�}
|j
|
jf�|
j�}|j
|ddd	dd
dddd
|d|d|d|�t|dt�}
|j
|
jd�|j
|
jf�|j
|
jf�|
j�}|dkr'|gn|}|j
|ddd	dd
dddd
dd|jgddd|�qIWx|D]\}}t|d|dt�}t|�}|j|j�|j|j�t|�}t||dd�}t||�}|j
|d|d	dd
dddd
|d|d|d|�t|�}	|j
|	d|d	dd
dddd
|d|d|d|�q{Wx�|dd�D]�\}}t|d|dt�}t|�}t|�}t	||�}|j
|d|d	dd
dddd
|d|d|jd|�t|�}	|j
|	d|d	dd
dddd
|d|d|jd|�q�W|jttdd�|jtti�tdddgddg�}t|dt�}
|jtt|
�t|dttB�}
|jtt|
�tdgdddgddd�}
|jtt|
�|jt|
j�|jtt|
td�|jtt|
td�|jtt|
ddd�td�dS)Nrrrr�r�ryrvrLrzr2rr�rxr{rWr	r7rr�r��9rMr)r�rr�r@)rrw)rqrVrrDr�rrrRr|r�rr#rr�r{r:rr�ryr�r�rr�r$rr�r�r�r�r�)r�Zitems_shapercryrr=rxr{rWr+r�r4r4r5�test_memoryview_construction 	s�B&z/TestBufferProtocol.test_memoryview_constructioncCs�dddg}xvdddgdddgdddgfD]J}t|d|�}|j|j�t|�}|jt|jd�q:Wxgtdd�D]V\}}}td�}|j|�}|j|j	�d�|j|j
�g�q�WdS)	Nrrr�rryrrDr~)rr�rrDrr�r�rjr�r�r�)r�rcryr�msrcr2rar=r4r4r5�test_memoryview_cast_zero_shape�	s1z2TestBufferProtocol.test_memoryview_cast_zero_shapecCs�|j}tj}d}d}ttd��}|td�||d|��t|dddgd	d
�}|t|�||d|��t|ddddgd	d
�}|t|�||d|��dS)NzPnin 2P2n2i5P PZ3nr!r~rryrr�r�rr�)�check_sizeofrZcalcvobjsizerqrVrDr)r�ZcheckZvsizeZbase_structZper_dimrcr>r4r4r5�test_memoryview_sizeof�	s		!!!z)TestBufferProtocol.test_memoryview_sizeofcCs}Gdd�dt�}Gdd�dt�}dd�}|d�|d�d#td
�dtdd
�dd
dgdddhddifd$dddtddtd�td�dddd|dd�g}x�tdd�D]�\}}}t|ddgd|d t�}t|ddgd|d t�}	t|�}
t	j
||	d!|�||
d!<|j|
d!|	d!�t	j|�}d"|kr�q�x�|D]�}d}
yt	j
||	||�Wnt	j
k
r�t	j
}
YnXd}y||
d<Wn4ttfk
r)}z|j}WYdd}~XnX|
s6|rY|j|
d�|j|d�q�|j|
d|	d�q�Wq�WdS)%Nc@s(eZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.INTcSs
||_dS)N)�val)r�r�r4r4r5�__init__�	szFTestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__init__cSs|jS)N)r�)r�r4r4r5�__int__�	szETestBufferProtocol.test_memoryview_struct_module.<locals>.INT.__int__N)�__name__�
__module__�__qualname__r�r�r4r4r4r5�INT�	sr�c@s(eZdZdd�Zdd�ZdS)z=TestBufferProtocol.test_memoryview_struct_module.<locals>.IDXcSs
||_dS)N)r�)r�r�r4r4r5r��	szFTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__init__cSs|jS)N)r�)r�r4r4r5�	__index__�	szGTestBufferProtocol.test_memoryview_struct_module.<locals>.IDX.__index__N)r�r�r�r�r�r4r4r4r5�IDX�	sr�cSsdS)Nr"r4r4r4r4r5r�	sz;TestBufferProtocol.test_memoryview_struct_module.<locals>.frg������@y@z-21.1gffffff(@r�rrr�r�r�r"r!TF�asabcr>�abccSs|S)Nr4)rMr4r4r5�<lambda>�	szBTestBufferProtocol.test_memoryview_struct_module.<locals>.<lambda>rZrDryr�r�rry������@@)r)�objectr	r
rPr�rjrr�rDr/r�r�r%r1r�r�raZassertIsNot)r�r�r�r�valuesr2rcrdrr�r=rzrtZ
struct_errZmv_errrcr4r4r5�test_memoryview_struct_module�	sF'!!

z0TestBufferProtocol.test_memoryview_struct_modulecCs]tdddgddgddg�}|j|j�t|�}|jt|jd�dS)Nrrr�ryr{rr)rrprrDrr�r�)r�rr�r4r4r5�!test_memoryview_cast_zero_strides�	s'z4TestBufferProtocol.test_memoryview_cast_zero_stridescCsx�tD]�}td�r#d|n|}tj|�}x�tD]�}td�r[d|n|}tj|�}tttd��dd|gd|�}t|�}|jt	|j
|d|g�q?WqWx�td�D]�\}}	}
t|	ddgd|�}t|�}x�td�D]x\}}
}
t|�s]|jt
|j
|d|g�qt|�rt|�r|jt	|j
|d|g�qWq�Wtjd�}tjd�}tttd.|��ddd|gdd�}t|�}|jt	|j
ddd|gdd�tttd	��dddd
ddg�}t|�}
|jt	|
j
�|jt	|
j
ddd
�|jt	|
j
i�|jt
|
j
d
�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�|jt
|
j
d�td/d0gddgdd�}t|�}
|jt|
jd�|jt|
jdd�|jt|
j�tttd	��dddd
ddg�}t|�}
|jt	|
j
ddi�tttd	��dd3g�}t|�}
|jt|
j
ddd4g�|jt
|
j
ddd5g�|jt
|
j
dddd
ddddd6g�|jt
|
j
dddd
dddddg�|jt	|
j
dddd
dddddg�ttdd�td9�D��dd
ddd g�}t|�}
|jt	|
j
d!ddd
ddg�tttd"��dd"gdd!�}t|�}
|jt
|
j
d!dgd"�ttd#d�td<�D��dd?g�}t|�}
|jt	|
j
d!ddd
ddg�ttd$d�tdB�D��ddEg�}t|�}
|jt	|
j
dddd
ddg�tttd"��dd"gdd!�}t|�}tttd"��dd"gdd�}t|�}tjdGkr�|jt	|j
dddd&d'd(d)d*g�|jt
|j
ddHdIdJdKdLg�|jt
|j
d!dMdNdOdPdQg�no|jt	|j
ddd-g�|jt
|j
ddRdSdTdUdVg�|jt
|j
d!dWdXdYdZd[g�dS)\Nrr8r&ryr�rrr�xr�r�r��Xz@Xz@XYz=Bz!Lz<Pz>lZBIZxBIZIIrr!rrr�r"rMcSsg|]}d�qS)rr4)rnrar4r4r5roC
s	zCTestBufferProtocol.test_memoryview_cast_invalid.<locals>.<listcomp>rrr)cSsg|]}d�qS)rr4)rnrar4r4r5roM
s	cSsg|]}d�qS)rr4)rnrar4r4r5roR
s	r'�Ir*iQiAji��	rvrZi���r�)rr)r�r�r��r�lrwrwr#�ii�r#r�i�r#r�i�r#r�i�r#r�i�ll����iiiir!iiiiriir&r&riir&r!r)�NON_BYTE_FORMATrr/r%rrqrVrDrr�r�rjrmr�rkr�rJrHr�r7r��maxsize)r�ZsfmtZsformatZssizeZdfmtZdformatZdsizerr�ZsitemsraZsize_hZsize_dr=r�r*r+r4r4r5�test_memoryview_cast_invalid�	s�

+(1(-!-!1117(' .(.(''
z/TestBufferProtocol.test_memoryview_cast_invalidcsSddd�fddd�fddd�ff���fdd	�}tjd
�}tddgd
d
�}t|dd�\}}t|�}|jd�}�j|d|ddddddddd|ddd|dd�	tjd
�}tdg|d|gd
d�}t|d
|dg�\}}t|�}|jd
dg�}�j|d|d|dd
dddddfdfd|dd�	xQtdd�D]@\}	}
}tj|	|
�}t|�}||||
|	�q�Wx`tdd�D]O\}	}
}t|
ddgd
|	dt	�}t|�}||||
|	�q�WdS)NrcSst|j��S)N)rqr�)rr4r4r5r�l
sz9TestBufferProtocol.test_memoryview_cast.<locals>.<lambda>rcSsdd�t|j��D�S)NcSs,g|]"}|dkr"|dn|�qS)r*r(r4)rnrMr4r4r5rom
s	zMTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>)rqr�)rr4r4r5r�m
srcSsdd�t|j��D�S)NcSs%g|]}tt|�d��qS)zlatin-1)rG�chr)rnrMr4r4r5ron
s	zMTestBufferProtocol.test_memoryview_cast.<locals>.<lambda>.<locals>.<listcomp>)rqr�)rr4r4r5r�n
sc
stj|�}x��D]�\}}|j|�}||�}�j|d|ddd|dddddd	|gd
dd|dd
�	|j|�}	�j|	|�|j�}�j|	d|d|d|dddddd	gd
|fd|dd
�	qWdS)NrLrzrr2r�rrxryr%r{rWr�T)r)r/r%r�rr�r�)
rr=rcr2�srcsizerEZto_bytelistr+rW�m3)�bytespecr�r4r5�iter_roundtripq
s
z?TestBufferProtocol.test_memoryview_cast.<locals>.iter_roundtriprrryr�rrLrzr2r�rxr{rWr�Trr%rBrDr�)r)
r/r%rr�rDr�rrjrBr�)r�r�r�rZ	destitemsZ	destshaper=r+Zdestsizer2rcrar4)r�r�r5�test_memoryview_castj
s<
"
!z'TestBufferProtocol.test_memoryview_castcCs0x�t�D]�}x�tdD]�}dtd�|}tj|�}t|�|}t|�rfdnd}x,t||�D]\}}}	tj|�}
|dkr�|gng}||
g}t|d|d|�}
t	|
�}t
|
||d|�\}}|dkr,|jt|j
||�q||d	kr;q|t|d|d|�}|j
|d|�}t|�}|j}|j�}|j|d
|
d|d|d
dd|d|d|d|dd�	|j
|�}|j
|d|�}t|�}|
j}|
j�}|j|d
|
d|
d|d
dd|d|d|d|dd�	|j|d
|
d|
d|d
dd|d|d|d|dd�	q|WqWq
Wtr,Gdd�dtj�}|dd�}t	|�}|j
d�}|j|j|�|j|jd�|j|jd�|j|jd�|j|j|jf�|j|jd�|j|jf�tjd�}t	|�}|j
d�}|j|j|�|j|jd�|j|jd�|j|jd�|j|j|jf�|j|jd�|j|jf�dS)Nr8r7rrDrErryr�r�rLrzr2r�rrxr{rWr�Tc@s.eZdZdejfdejfgZdS)z>TestBufferProtocol.test_memoryview_cast_1D_ND.<locals>.BEPointrMrN)r�r�r��ctypes�c_long�c_double�_fields_r4r4r4r5�BEPoint�
sr�r�g33333i@rg333333�?r)r7r8)r)r)r�rFrr/r%rurkrjrrDr�rr�r�rRr{r�rr��BigEndianStructurer�rLrzr�rxryr�r�r�)r�Z_tshaperKZtfmtZtsizerrLr2rcra�sizeryZtshaperr=Ztitemsr�r+rxr{rWr�Zm4r��pointr*rMr4r4r5�test_memoryview_cast_1D_ND�
s|
	
	
z-TestBufferProtocol.test_memoryview_cast_1D_NDcCs�tjdttdd���}t|�}|j||�|j|j�|j��|ddd�}|ddd�}|j||�|j|j�|j��tttd��ddddddgd	d
�}t|�}|j|j�|j��tddgddgd	d�}t|�}|jt|j�tdgdd
gd	d�}t|�}|jt|j�tddddddgdddgd	d�}t|�}|jt|j�dS)Nrr�rr�r�r"rryr�rr3s12345rr~r��b�c�d�e�fi����r�r@��i	)rr�)r"r)	rBrqrVrDr�r�rrr�)r�r>r=rr4r4r5�test_memoryview_tolist�
s(!3!0z)TestBufferProtocol.test_memoryview_tolistcCsdttd��}|j�}|j|jd��|j�|j�}|j|jd��dS)Nrz<memoryz	<released)rDr��__repr__r��
startswithr9)r�r=r�r4r4r5�test_memoryview_reprs
z'TestBufferProtocol.test_memoryview_reprcCs�xqd	D]i}td�}tj|d|dg�}t|�}|jd|�|jd|�|jd|�qWtdgdd�}t|�}|jttdt��dS)
Nrrg�g�?g@g"@r�z9.0 in m)rr)	�floatrBrDZassertInrrr�rUrV)r�r2�infrr=r4r4r5�test_memoryview_sequences
z+TestBufferProtocol.test_memoryview_sequenceccsB|jt��}dVWdQRX|jt|j�d|f�dS)Nz#index out of bounds on dimension %d)rrKr��strZ	exception)r��dim�cmr4r4r5�assert_out_of_bounds_error+sz-TestBufferProtocol.assert_out_of_bounds_errorcCs�tddgdd�}t|�}|j|fd�|j|d|�|j|d|�|jt|jd�tddgdd
�}t|�}|jt|jf�tttd��ddgdt	�}t|�}|jt
|jd�|jt|jd�|jt|jd�|jt
|jd�|jt
|jd�tttd��dd	dgdt	�}t|�}|j|dd�|j|dd�|j|dd�|j|dd�|j|d!d�x6d#D].}|jdd��||dfWdQRXq�Wx6d%D].}|jdd��|d|fWdQRXq+W|jt
|jd'�|jt
|jd)�|jt|jd*�|jt|jd+�|jt|jf�|jt|jd�dS),Ng)@ryr�r.rrrr�Ziiir"r�rg@�r!rr�rr�r�)rrr�li����)rr)rr)rr�rwrw)rwrwr4r)r4rr)r�rrA)r�rA�)r�r�)rr�)rrr)r�r�)rrDr�rr�rJr�rqrVr�rKr�)r�rr=�indexr4r4r5�test_memoryview_index2sF'*

z(TestBufferProtocol.test_memoryview_indexcCsctddgdddt�}t|�}d|f<|j|fd�d|d<|j|fd�|jt|jd	d
�tttd��ddg�}t|�}|jt|jdd
�tttd��ddgdt�}t|�}|jt	|jd2d�|jt|jdd
�|jt|jdd�|jt	|jd3d�|jt	|jdd�x�t
dD]�}|dks�|dkr�q�tdddgddgd|dt�}t|�}td4d�}d||<|j||d�|j||||�q�Wtdddgddgdddt�}t|�}d|d<|j|dd�tdd dgddgdddt�}t|�}d|d<|j|dd�td!gddgdddt�}t|�}|jt|jd	d"�tttd#��ddddd$d%gdt�}t|�}x�t
dj�D]�\}}|dkr|qa|dkr�qa|j
|�}|\}	}
|d&ks�|dkr�d8\}	}
|d(kr|jt|jd	|	d�|jt|jd	d)�|jt|jd	|
�qaW|j
d�}|jt|jd	d*�tttd��ddgdd+dt�}t|�}|jt|jd	d�td,gddgdd-dt�}t|�}|jt|jd	d�tttd.��ddd$gdt�}t|�}d/|d9<|j|d	dd/�d0|d<<|j|ddd0�x8d>D]0}|jd1d��d	||d	f<WdQRXqmWx8d@D]0}|jd1d��d	|d	|f<WdQRXq�W|jt	|jdBd	�|jt	|jdDd	�|jt|jdEd	�|jt|jdFd	�|jt|jd	ddg�dS)GNg)@ryr�rr�g�6@g�7@.rg33333�8@r"rrZrrg@�rr!rv�r8rr
rr��1�2�3r�TF�xr�r�r�r�rirr0s��ZxLs12345r~r�*�+r�li����r4lE����E)r�r�)rrrwrw)rwrwr)r�rrA)r�rA�)r�r�)rr�)rrr)r�r�)rr�rDr�rr�rHrqrVrKrFrrcr�r�r�r�)r�rr=r2rr�r*Z_ranger+�lo�hir�r4r4r5�test_memoryview_assigngs�

!'*
!	
!	
$3-$*



z)TestBufferProtocol.test_memoryview_assigncCs�tttd��ddgdt�}t|�}|jt|jtddd��|jt|j	tddd�t
ddg��|jt|jf�tttd��ddgdt�}t|�}|jt|jtddd�tddd�f�|jt|j	tddd�tddd�ft
ddg��|jt|jtddd�if�|jt|j	tddd�ift
ddg��|jt|j	tddd�dg�xdt
fD]�}tttd��ddgddgdd	dt|B�}tttd
��ddgddgd|�}t|�}t|�}|dd�|dd�<|dd�|dd�<|j||�|j||�|dd�ddd�|dd�ddd�<|dd�ddd�|dd�ddd�<|j||�|j||�|dd
d�ddd�|d
dd�ddd�<|dd
d�ddd�|d
dd�ddd�<|j||�|j||�q�WdS)Nrryr�rrrr{r�rr�r�r�r�rwrwrwrrwrrw)rrqrVr�rDrr�rJr�rHr�r�r�r$r�)r�rr=r�r(r)r*r+r4r4r5�test_memoryview_slice�sD'"'%4($(-
044::z(TestBufferProtocol.test_memoryview_slicec&Csdd�}xltdd�D][}xRt|d�D]A\}}}x/t|�D]!}xt|�D]
}tj||�}tj||�}	t|	�}
|j|
|�|j|
j�|j��|j|
j�|j��|jt|
�t|��||||	|
|�d}d}y>||}
||}||||<t|
�t|�k}Wn.t	k
r�}z|j
}WYdd}~XnXd}y|
||
|<Wn.t	k
r�}z|j
}WYdd}~XnX|r�|j|t�qa|s�|r
|j||�qa|j|
|�|j|
j�|j��|j|
j�|j��||||	|
|�qaWqNWq2WqWdS)Nc	Ss�x�t|�D]�\}}||}||}|j||�|||<||krv|j||�|j||�n |j||�|j||�|||<|j||�|j||�|||<|||<q
WdS)N)r�r��assertNotEqual)	Ztestcaser>rr=�
singleitemrraZaiZmir4r4r5�cmptests




z9TestBufferProtocol.test_memoryview_array.<locals>.cmptestrr�rB)
rVrjr�rBrDr�r�r�rRr`rar�r�)r�r�rr2rcr�rhr�r>rr=Z	array_errZhave_resizeZal�arrcZm_errr4r4r5�test_memoryview_arraysF

z(TestBufferProtocol.test_memoryview_arrayc	Csetjddddg�}tjddddg�}t|�}t|�}xLdD]D}|jt||�|�t�|jt||�|�t�qUWt|�}|j�|j||�|j||�|j||�t|�}t|�}|j�|j||�|j||�t|�}|j|dddg�tdgddgdd
dt	�}dt
d�f|d
<|jt|�|�tjdd�}t|�}|j||�|j||�traGdd�dtj�}|dd�}t|�}t|�}|j||�|j||�|j||�|j
t|j�dS)Nrrrr�r"�__lt__�__le__�__gt__�__ge__rryr�zl x d xr�r��ur0c@s.eZdZdejfdejfgZdS)zITestBufferProtocol.test_memoryview_compare_special_cases.<locals>.BEPointrMrN)r�r�r�r�r�r�r4r4r4r5r�usr�r�r/)r�r�r�r�)rrrw)rBrDr��getattrrPr9r�r�rr�r�r�r�rr�r�)	r�r>rrt�w�attrr�r�r�r4r4r5�%test_memoryview_compare_special_casesJsF
#

$z8TestBufferProtocol.test_memoryview_compare_special_casescCs|tddgdd�}tddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�|j||�|j|j|��|j|j|��d|f<|j||�|j||�|j||�|j||�|j||�|j||�|j|j|��|j|j|��ttt	d��ddgdtt
B�}ttt	d��ddgdtt
B�}t|�}|j||�d	|d
<|j||�tddgdd
�}tddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�|j||�tddgdd
�}tddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�|j||�|j||�|j||�dS)N�ryr�z@Lrr�i�rr�r�333333�?�12345ZLf5sZhf5s)r�r�r�)r�r�r�)r�r�r��?���)r�r�r�)rr�rDr�rp�__ne__r�rOrqrVr$)r��nd1�nd2rtr�r�rr=r4r4r5�!test_memoryview_compare_ndim_zerosf
++
		z4TestBufferProtocol.test_memoryview_compare_ndim_zerocCs$tdddddgddgdd	�}tdddddgddgdd	�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdddddgddgdd
�}tdddddgddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tddd gddgdd	�}td!dd"dd#gddgdd	�}t|�}t|�}|j||ddd
��|j|ddd
�|�|j||ddd
��|j|ddd$�|ddd%��td&d'd(gddgdd�}td)dd*dd+gddgdd�}t|�}t|�}|j||ddd
��|j|ddd
�|�|j||ddd
��|j|ddd,�|ddd-��td.d/d0gddgdd	�}td1dd2dd3gddgdd	dt�}t|�}t|�}|j||ddd
��|j|ddd
�|�|j||ddd
��|j|ddd4�|ddd5��td6d7d8gddgdd�}td9dd:dd;gddgdddt�}t|�}t|�}|j||ddd
��|j|ddd
�|�|j||ddd
��|j|ddd<�|ddd=��dS)>Nii@iqi�i�ryr�r�z@hz<iz>hr�rrz!hz<lr�zh  0cz>  hi��i����i'���i��i����i��i����i'���i��i����i��i����i'���i��i����i'���rwri��i����i'���i��i����i'���rwri��i����i'���i��i����i'���rwri��i����i'���i��i����i'���rwr)rrDr�r�r$)r�r�r�rtr�r4r4r5� test_memoryview_compare_ndim_one�sh****$**$**$'	*$'	z3TestBufferProtocol.test_memoryview_compare_ndim_onecCsXtddgddgdd�}td	d
gddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tddgddgdd�}tddgddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)
Ni�i�ryrr�z@hz= h0cz@   ii|���i?���i|���i?���)rrDr�)r�r�r�rtr�r4r4r5�"test_memoryview_compare_zero_shape
s$!!!!z5TestBufferProtocol.test_memoryview_compare_zero_shapecCsktddddgddgdd�}tdgddgddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdgdddgdd	�}tdgddgddgdd
�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)
N�ryr�r�z@Lr{rrz@ Liz!L  h)r�r�)r�r�)rrDr�)r�r�r�rtr�r4r4r5�$test_memoryview_compare_zero_strides 
s$''"'z7TestBufferProtocol.test_memoryview_compare_zero_stridesc

Csud}x�tdD]�}t|dd|�\}}}x�dtfD]r}t|d|gd|d|�}t|�}|j||�|ddd�}t|�}|j||�qBWqWd}x�td
�D]�}	t|�\}}}x�dtfD]r}t|d|gd|d|�}t|�}|j||�|ddd�}t|�}|j||�q�Wq�WdS)
NrZz@mrDr8rryr�r�r�r�r4r4)rFrfr$rrDr�rV)
r�rrKr2rcr�r�r�r=rar4r4r5�&test_memoryview_compare_random_formats:
s(!!z9TestBufferProtocol.test_memoryview_compare_random_formatscCs�tttdd��ddddgdd�}tttdd	��ddddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdgd	ddddgdd�}tdgd	ddddgdd
�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd	��ddddgdd�}tttd	��ddddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdgddddgdd�}tdgddddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd	��ddddgdd�}tttd	��ddddgdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)Nr#ryr�rr�r�z@hrr@rz=f q xxLg333333�?z< f 2Qr�r"z! b B xLz
= Qx l xxLri�)rrr�333333�)r�rr)rrr)rrr)rrqrVrDr�r�)r�r�r�rtr�r4r4r5�"test_memoryview_compare_multidim_cV
sZ00((--%%--z5TestBufferProtocol.test_memoryview_compare_multidim_ccCstttdd��ddddgdddt�}tttd	d
��ddddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdgd
dddgdddt�}tdgd
dddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttdd��ddddgdddt�}tttdd��ddddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttdd��ddddgdddt�}tttdd��ddddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd
��ddddgdddt�}tttd
��ddddgdddt�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS) Nr#ryr�rr�r�z@hr�rr@rrr�z=Qqz=qQrZ0llz@bi�l�����rw)r�rwrwl�����)rwr�i�i�i�i�)rrqrVr�rDr�r�)r�r�r�rtr�r4r4r5�(test_memoryview_compare_multidim_fortran�
sn-	-	"	"	-	-	-	-	*	*	z;TestBufferProtocol.test_memoryview_compare_multidim_fortranc	Cslttdd��}t|dddg�}t|ddddgdd�}t|ddddgddd	t�}t|�}t|�}|j||�|j||�|j||�d"gd
}d%|d<t|dddg�}t|ddddgdd�}t|ddddgddd	t�}t|�}t|�}|j||�|j||�|j||�tttd��dddgdd�}|ddd&�ddd'�f}tttd��dddgdd�}|ddd�ddd(�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�td-gddddgdd�}|ddd.�ddd/�f}td4gddddgdd�}|ddd�ddd5�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd
��ddddgdd�}|dd�ddd6�f}tttd
��ddddgdd�}|dd�ddd7�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd
��ddddgdd�}|dd�ddd8�f}tttd
��ddddgdd�}|dd�ddd9�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�td:gd
ddddgdd�}|dd�ddd;�f}td<gd
ddddgdd�}|dd�ddd=�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)>Nr#r�rr�ryr�z@lrr�gffffff
@�r�r@g������@zd b czd h c�(r!z@Irrr%rz=iiz>iirr�123Zb3sZi3si��ffffff
����)r�r�r�皙��������)r�r�r�rwrrl��l��)r�r�rwrl��l��)r�r�rrrrr)rr�r)rr�r)rqrVr�rr�rDr�r�)	r��lst1�lst2r�r�rtr�r(r)r4r4r5�&test_memoryview_compare_multidim_mixed�
s�!'

!'*"*"%"%"----((z9TestBufferProtocol.test_memoryview_compare_multidim_mixedcCs�tttd��ddddgdd�}tttd��ddddgdd	�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd��ddddgdd�}tttd��ddddgdd	�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)
Nr@ryrr�rr�rr�z@i)rrqrVrDr�r�)r�r�r�rtr�r4r4r5�+test_memoryview_compare_multidim_zero_shape=s$----z>TestBufferProtocol.test_memoryview_compare_multidim_zero_shapecCs�tdgdddddgdd�}tdgddddgdd	d	d	gdd
�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�|j|j�|j��tdgd
dddgdd�}tdgdddgdd	d	gdd�}t|�}t|�}|j||�|j||�|j||�|j||�|j||�dS)Ni�r�ryr�r�r�z@Lr{rrrrrZz=lQz<lQ)rr)rr)rrDr�r�)r�r�r�rtr�r4r4r5�-test_memoryview_compare_multidim_zero_stridesWs&(3%-z@TestBufferProtocol.test_memoryview_compare_multidim_zero_stridesc		Cs�tttd��dddgdd�}|ddd%�ddd&�f}tttd��dddgdd
dt�}|ddd�ddd'�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�td+gddddgdd
dt�}d-|d	d<|ddd.�ddd/�f}td3gddddgdddttB�}d5|d	d<|ddd�ddd6�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd��dd	ddgdddt�}|dd�ddd7�f}tttd��ddd	dgdd�}|dd�ddd8�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�td<gddd	ddgdddttB�}|dd	�ddd=�f}tdAgdddd	dgdd�}|dd	�dddB�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tttd��dddd	gdddt�}|dd�dddC�f}tttd��dddd	gdddt�}|dd�dddD�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdEgdddddgdddttB�}dF|dd	d	<|dd�dddG�f}tdHgdddddgdddttB�}dI|dd	d	<|dd�dddJ�f}t|�}t|�}|j||�|j||�|j||�|j||�|j||�ttdKd��}t|dd	dg�}t|ddd	dgdddt�}t|ddd	dgdddt	tB�}t|�}t|�}|j||�|j||�|j||�dLgd}dM|d"<t|dd	dg�}t|ddd	dgdd#dt�}t|ddd	dgdd$dt	tB�}t|�}t|�}|j||�|j||�|j||�dS)NNr�ryr�r!r�z@Ir�rrrr�rz=Qqr"z>Qqr@rZBbr�hellor~�Z5s0sP�sushir#z@lr�sashimi�sliced������4@�ramen�spicy�fffff�"@rz
< 10p 9p dz
> 10p 9p drwrrl�����rw)r
rwr)rrrwrl�����rw)rrwr)rrrrrr(r2rw)r2rwrr(r2rw)r2rwrrr)rr~r)rr~rr)rr~r)rr~rri�)rrr	)r
rr)
rrqrVr$rDr�r�r�r�r�)	r�r(r�r)r�rtr�r�rr4r4r5�+test_memoryview_compare_multidim_suboffsetsrs�*"0""	""
"*	-%
(33%
%
'+

'
z>TestBufferProtocol.test_memoryview_compare_multidim_suboffsetsc
Csx�ddddgD]�}tdgddd	d
dddgd|d�}tdgddd	d
dddgd|dd
ttB�}d|dd	ddd<t|�}t|�}|j||�|j||�|j||�|j||�|j||�tdgddd	d
dddgd|d�}tdgddd	d
dddgd|dd
ttB�}d|dd	ddd<t|�}t|�}|j||�|j||�|j||�|j||�|j||�qWdS)Nr;r9r:r<rr'r�ryr�r�r�rr�rr%r#ZQLHll����)rrr����)rrr)rrr)rr�r�rDr�r�)r��	byteorderrMrr>rr4r4r5�!test_memoryview_compare_not_equal�s02/
%
%z4TestBufferProtocol.test_memoryview_compare_not_equalcCs�tjddddg�}t|�}|j�|jtt|�|jt|jd�|jtt|�|jt|j�|jt|j�|jtt	dt
��|jt|jd�|jt|jdd�x$dD]}|jt|j
|�q�Wtjddddg�}t|�}t|�}|j||�|j�|j||�|j||�|j||�dS)Nrg�������?g������@gffffff
@rz1.0 in mrrrLr�r�rzr�rxryr{r�rrr)rLr�r�rzr�rxryr{r�rrr)rBrDr9rr�r�rr�r�rUrVrJrH�__getattribute__r�r�)r�r>r=r�rr*r+r4r4r5�test_memoryview_check_releaseds.


z1TestBufferProtocol.test_memoryview_check_releasedcs�d�t�ddgdd	�}t|�}|j||�|j|j�|j��t�gdd
gdd�}t|�}|j||�|j|j�|j��t�fdd
�td�D�ddddgdd�}t|�}|j||�|j|j�|j��t�fdd
�td�D�ddddddgdd�}t|�}|j||�|j|j�|j��tr�Gdd�dtj�}|dd�}t|�}|j|j�t|��dS)Ni�@iq�i�ryr�r�z@hrz>hQiLlcsg|]}��qSr4r4)rnra)rir4r5roGs	z>TestBufferProtocol.test_memoryview_tobytes.<locals>.<listcomp>rrr�z=hQiLlcsg|]}��qSr4r4)rnra)rir4r5roLs	r�z<hQiLlc@s.eZdZdejfdejfgZdS)z;TestBufferProtocol.test_memoryview_tobytes.<locals>.BEPointrMrN)r�r�r�r�r�r�r4r4r4r5r�Usr�r�r/�������'���)rrrrr)rrDr�r�rVr�r�rG)r�r�r=r�r�r>r4)rir5�test_memoryview_tobytes8s.:7	z*TestBufferProtocol.test_memoryview_tobytescCs�|jttitd�|jttdtd�tdddgddgddg�}|jtt|td	�td
dfdd�}xMddd	gD]<}t|t|�}|j||�|j|fd
�q�Wtd
dfddd
t�}xMddd	gD]<}t|t|�}|j||�|j|fd
�qWx�ddd	gD]x}d
|f<t|t|�}|j||�|j|fd
�d|f<|j|fd�|j|fd�qXWtdgddgddd
t�}xeddd	gD]T}t|t|�}|jt	|j
d�|j||�|j|j�g�qWttt
d��ddddgddd
t�}xKddd	gD]:}t|t|�}|jt|�j�ggg�q�Wtdgddgddd
t�}xUddd	gD]D}t|t|�}|j||�|j|j�|j��qWtdddgddgddd
t�}xUddd	gD]D}t|t|�}|j||�|j|j�|j��q�Wtdddgddgddgd
t�}x�ddd	gD]�}t|t|�}|j||�|j|j�|j��|jt|jdd�|j|dd�|j|dd�qW|ddd�}x�ddd	gD]�}t|t|�}|j||�|j|j�|j��|jt|jdd�|j|dd�|j|dd�q�Wttt
d��dddgd
t�}xHdd	gD]:}t|t|�}|jt|�j�|j��q�W|jtt|td�t|t|�}|jt|�j�|j��ttt
d��dddgd
ttB�}xHdd	gD]:}t|t|�}|jt|�j�|j��qNW|jtt|td�t|t|�}|jt|�j�|j��ttt
d��dddgd
ttB�}xdddd	gD]S}|jtt|t|�t|t|�}|jt|�j�|j��qWtdddddgddgddg�}t|td�}|j|j�dS)Nr�r�rvrrr�ryr{r�rr�rr�rZrr!r"rrrvrr�r�rw)rr�r�r�r�ZPyBUF_WRITErr�r�rKrJr�rqrVrHr�r$r�r)r�r�rr=r4r4r5�test_memoryview_get_contiguous[s�'

$*	&$ * -*&"!
&".&-z1TestBufferProtocol.test_memoryview_get_contiguouscCstjd�}tjddddddg�}t|�}tj|�}td|�}|j|�|j|j	�|�tjd�}t
ttd��d	dddgd
d�}t|�}tj|�}td|�}|j|�|j|j	�|�dS)
Nrrrr�r�r�rrryr�r�r)
r/r%rBrD�io�BytesIOr��readintor�r�rrqrV)r�r�r>r=r�rr�r4r4r5�test_memoryview_serializing�s!
-
z.TestBufferProtocol.test_memoryview_serializingc	Cs�tttd���}t|�}|jt|�t|��|jddddg�}|jt|�t|��|ddd�}tttd��ddd��}|jt|�t|��tttd��ddddgd	t�}t|�}|jt|�t|��tttd��ddddg�}|ddd�dd�ddd�f}t|�}|jt|�t|��tttd��ddddgd	t	�}|ddd�dd�ddd�f}t|�}|jt|�t|��tttd��ddgdd�}t|�}tttd��ddgdd
�}t|�}|j||�|jt|�t|��tttd��ddddgdd�}t|�}|j
t|j�tttdd��ddddgdd�}t|�}|j
t|j�tttd��ddddgdd�}t|�}|j
t|j�tttdd��ddddgdd�}t|�}|j
t|j�dS)Nrrryr�r�rr@r�r�rr�rrrr�rz= Lz< hrrrwrwi����i����)
rGrqrVrDr�r|r�rr�r$rr��__hash__)	r�rr=ZmcZmxr�rMr>rr4r4r5�test_memoryview_hash�sJ%-'+-+''-0-0z'TestBufferProtocol.test_memoryview_hashc=Cs{tdddg�}t|�}t|�}|jt|j�~|j�tdddg�}t|�}t|dtdt�}t|dtdt�}|j|j	|�|jt|j�~~|j�tdddg�}t|�}t|�}t|�}|j�|jt|j�~|j�tdddg�}t|�}t|�}t|dtdt�}t|dtdt�}|j|j	|�|j�|jt|j�~~|j�tdddgddgdt
�}t|�}|jddd	d
dgddg�t|�}t|�}|j|j
�|j
��t|�}	|j|	j
�|j
��|j|	j
�|j
��|j�|	j�|j�|j|j
�|j
��~|j�|j�dd
�}
td�}t|��+}|
|�|j|dtd��WdQRXtttd��ddddgdd�}t|dtdt�}	t|	dtdt�}|j|j	|�t|��L}|
|�|j|dd�j
�dddgdddggg�WdQRXxdtfD]�}td�}t|���}~t|dtd|�}	t|	���}~	t|dtd|�}t|��y}
~|
|
�|
|�|
|�|j|dtd��|j|dtd��|j|
dtd��~
WdQRX~WdQRX~WdQRXtd�}t|���}~t|dtd|�}	t|	���}~	t|dtd|�}t|��}
~|
|�|
|�|
|
�|j|dtd��|j|dtd��|j|
dtd��~~~
WdQRXWdQRXWdQRXqWtd�}|jt��;t|��'}t|�}|dtd�kWdQRXWdQRXdS)Nrrr�r	r�ryr�r�r�r"r!c	Sst|��}WdQRXdS)N)rD)rr+r4r4r5�catch22lsz;TestBufferProtocol.test_memoryview_release.<locals>.catch22s123rr�rr�rr�r�)r�rDrrr�r9r��ND_REDIRECTr�rLr5r6r�r�r8�ordrqrV)r�r>r=r�r�r�r*r+rMrr'rnr�r�rr4r4r5�test_memoryview_release*s�





$%





!-
B








"z*TestBufferProtocol.test_memoryview_releasecCs�tdd�td�D�ddgdd�}tjddd�td�D��}xO||fD]A}t|dtd	t�}t|dtd	t�}t|�}|j|j|�|j|j|�|j|j|�|j||�|j||�|j||�|j|d
d�|d
d��|j|d
d�|d
d��|j|d
d�|d
d��~~|j|d
d�|d
d��q`WdS)NcSsg|]}d|�qS)g�?r4)rnrMr4r4r5ro�s	z?TestBufferProtocol.test_memoryview_redirect.<locals>.<listcomp>rryr�rcSsg|]}d|�qS)g�?r4)rnrMr4r4r5ro�s	r	r�rr�)	rrVrBr�r(rDr�rLr�)r�r�r>rMrrnr=r4r4r5�test_memoryview_redirect�s".%$$$z+TestBufferProtocol.test_memoryview_redirectcCs�d}dddddddd	d
ddd
g}|jttddd�t�}t|�}|j|d|ddd|ddddddgddgd|�x(td�D]}|j|||�q�W~~t�}t|�}~~t�}t|dt�}t|dt�}t|�}|j	|j
|�|j	|j
|�|j|d|ddd|ddddddgddgd|�~~~~t�}t|dtdt�}t|dtdt�}t|�}|j	|j
|�|j	|j
|�|j	|j
|�|j|d|ddd|ddddddgddgd|�~~~~tdd�}t|�}|j|ddddd|ddddddgddgd|�x(td�D]}|j|||�q�W~~tdd�}t|�}~~tdd�}t|dt�}t|dt�}t|�}|j	|j
d�|j	|j
|�|j|d|ddd|ddddddgddgd|�~~~~tdd�}t|dtdt�}t|dtdt�}t|�}|j	|j
d�|j	|j
|�|j	|j
|�|j|d|ddd|ddddddgddgd|�~~~~dS)Nrrrrr�r�r�r�r"r!rrZrrLrzr2r�rxryrr{rWr	r�Zlegacy_modeT)rr�ZstaticarrayrDrrVr�rr�r�rLr()r�r2rWrMrrrnr=r4r4r5�$test_memoryview_from_static_exporter�s�*				z7TestBufferProtocol.test_memoryview_from_static_exportercCs<tdddgdgdttB�}|jtt|�dS)Nrrr�r�)rr&ZND_GETBUF_UNDEFINEDrr�rD)r�r�r4r4r5�#test_memoryview_getbuffer_undefined s%z6TestBufferProtocol.test_memoryview_getbuffer_undefinedcCs;tdddgddgdt�}|jtt|�dS)Nrrr�ryr�)rr&rr�rD)r�rMr4r4r5�test_issue_7385&s$z"TestBufferProtocol.test_issue_7385Nrwrwrwrwrw)Sr�r�r�r�rrr.r<r=r>r?rBrCrFrLrMrNrQrRrTrWr^r_rfrgrirkrorqrrrsrtrurwrxryrzr{r}rr�r�rr�r�r�r�r�r�r�r�r�r��
contextlib�contextmanagerr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr r$r&r*r+r,r-r.r4r4r4r5r��s��2i�
-'	0.Y #6!)>
		%�u	
8	s<P	5m8>5?H>Ha�(#u<�^r��__main__)er/ZunittestZtestr�	itertoolsrrZrandomrrr�	sysconfigr�warningsr�rBr!�decimalr	Z	fractionsr
Z_testbuffer�ImportErrorrr/r��catch_warningsrCr�Z
SHORT_TESTZNATIVEr0r1ZSTANDARDr6rFr2�copyrlZARRAYrSZBYTEFMTr\r^r[rNrUrXrerfrgrjrkrmr�rrrsrur|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�rjrlrmZ
skipUnlessZTestCaser�r��mainr4r4r4r5�<module>s8$




	
%%%%%0








*	

	

?
+!��������������C