Your IP : 216.73.216.213


Current Path : /proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/
Upload File :
Current File : //proc/242857/root/opt/alt/python34/lib64/python3.4/test/__pycache__/test_memoryview.cpython-34.pyc

�
g f�@�@s�dZddlZddlZddlZddlZddlZddlZddlZGdd�d�Z	Gdd�de	�Z
Gdd�de	�ZGd	d
�d
�ZGdd�d�Z
Gd
d�d�ZGdd�dejee
�ZGdd�dejee�ZGdd�deje
e
�ZGdd�deje
e�ZGdd�dejee
�ZGdd�dejee�Zdd�Zedkr�e�ndS)z�Unit tests for the memoryview

   Some tests are in test_bytes. Many tests that require _testbuffer.ndarray
   are in test_buffer.
�Nc@sZeZdZdZedd��Zedd��Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6S)7�AbstractMemoryTestssabcdefcCs|jS)N)�source_bytes)�self�r�9/opt/alt/python34/lib64/python3.4/test/test_memoryview.py�_sourceszAbstractMemoryTests._sourcecCstd|j|jg�S)N)�filter�ro_type�rw_type)rrrr�_typesszAbstractMemoryTests._typescs�||j�}tj|�}|j|��|j�dtd��|j�dt�|j�dtd��|j�dtd��|j�dtd��|jt	�fdd��|jt	�fd	d��|jt	�fd
d��|jt	�fdd��|jt
�fdd��|jt
�fd
d��|jt
�fdd��d�|jtj|�|�dS)Nr�a��f��cs�dS)Nrrr)�mrr�<lambda>%sz=AbstractMemoryTests.check_getitem_with_type.<locals>.<lambda>cs�dS)N�i����rr)rrrr&scs�tjS)N)�sys�maxsizer)rrrr'scs�tjS)N)rrr)rrrr(scs�dS)Nrr)rrrr*scs�dS)Ngrr)rrrr+scs�dS)N�arr)rrrr,s���i����)rr�getrefcount�_view�assertEqual�ord�assertIsInstance�int�assertRaises�
IndexError�	TypeError)r�tp�b�oldrefcountr)rr�check_getitem_with_types"z+AbstractMemoryTests.check_getitem_with_typecCs%x|jD]}|j|�q
WdS)N)rr$)rr!rrr�test_getitem0sz AbstractMemoryTests.test_getitemcskxd|jD]Y}||j�}|j|��|jt���fdd�tt���D��q
WdS)Ncsg|]}�|�qSrr)�.0�i)rrr�
<listcomp>8s	z1AbstractMemoryTests.test_iter.<locals>.<listcomp>)rrrr�list�range�len)rr!r"r)rr�	test_iter4szAbstractMemoryTests.test_itercs�|js|jd�n|j|j�}tj|�}|j|���fdd�}|jt|d�|jt|d�|jt|td��d�|j	tj|�|�dS)Nzno read-only type to testcs|�d<dS)Nrr)�value)rrr�setitem@sz:AbstractMemoryTests.test_setitem_readonly.<locals>.setitemr�A)
r	�skipTestrrrrrr �
memoryviewr)rr"r#r.r)rr�test_setitem_readonly:s	z)AbstractMemoryTests.test_setitem_readonlycs�|js|jd�n|j�|j|j�}tj|�}|j|��td��d<|j�|d��d��dd�<|j�|d��d��dd	�<|j�|d
��d��dd�<|j�|d
��d��dd�<|j�|d��d
d��dd	�<|j�|d��d��dd�<�dd	��d
d�<|j�|d���fdd�}|jt	|dd�|jt	|dd�|jt	|tj
d�|jt	|tj
d�|jt|dd�|jt|dd�|jt|tddd�dfd�|jt|dtddd�fd�|jt|dd�|jt|dd�tddd�tddd
�f}|jt
||d��jdkr�tnt}|j||dd�|j||dd�|jt|tdd�d�|jt|tdd
�d�d�|jtj|�|�dS)Nzno writable type to test�1rs1bcdef�0rs0bcdefs12�s012def�sabcdef�r
scdedefsababcfcs�|��|<dS)Nr)�keyr-)rr!rrr.asz:AbstractMemoryTests.test_setitem_writable.<locals>.setitemrrrgr�csabi����)r)r)r
r0rrrrr�_check_contentsrrrr �slice�NotImplementedError�format�
ValueErrorr)rr"r#r.Zslices�excr)rr!r�test_setitem_writableHsR		(($z)AbstractMemoryTests.test_setitem_writablecCsvxo|jD]d}||j�}|j|�}|jt��|d=WdQX|jt��|dd�=WdQXq
WdS)Nr�)rrrrr )rr!r"rrrr�test_delitem|s
z AbstractMemoryTests.test_delitemcs~xw�jD]l}�j|�j��}|j�}dj�fdd�dD��}�j||��j|t�q
WdS)Nr6c3s'|]}�jt|g��VqdS)N)�getitem_type�bytes)r&r9)rrr�	<genexpr>�sz3AbstractMemoryTests.test_tobytes.<locals>.<genexpr>sabcdef)rrr�tobytes�joinrrrD)rr!rr"Zexpectedr)rr�test_tobytes�sz AbstractMemoryTests.test_tobytescCsRxK|jD]@}|j||j��}|j�}|j|td��q
WdS)Nsabcdef)rrr�tolistrr))rr!r�lrrr�test_tolist�szAbstractMemoryTests.test_tolistcs-x&|jD]}|j||j���x�|jD]�}|j�|d�k�|j�|d�k�|j�|d�k�|j�|d�k�|j�|d�k�|j�|d�k�q2W|j��k�|j��dd�k�|j�dd��dd�k�|j�dd��k�|j�dk�|j�dk�|jd�k�|jd�k�x��dfD]��|jt��fdd	��|jt��fd
d	��|jt��fdd	��|jt��fdd	��q�Wq
WdS)
Nsabcdefsabcdesabcde1rrr
Zabcdefcs
��kS)Nrr)r9rrrr�sz2AbstractMemoryTests.test_compare.<locals>.<lambda>cs
��kS)Nrr)r9rrrr�scs
��kS)Nrr)r9rrrr�scs
��kS)Nrr)r9rrrr�s)rrr�
assertTrueZassertFalserr )rr!Ztp_compr)r9rr�test_compare�s,'z AbstractMemoryTests.test_comparecCs�|j||j��}|j|j|j�|j|j|j�|j|jd�|j|jd�|jt|�d�|j|j|jf�|j|j	f�|S)Nrr)r)
rrrr=�itemsize�ndim�shaper+�strides�
suboffsets)rr!rrrr�check_attributes_with_type�sz.AbstractMemoryTests.check_attributes_with_typecCsB|js|jd�n|j|j�}|j|jd�dS)Nzno read-only type to testT)r	r0rSr�readonly)rrrrr�test_attributes_readonly�s	z,AbstractMemoryTests.test_attributes_readonlycCsB|js|jd�n|j|j�}|j|jd�dS)Nzno writable type to testF)r
r0rSrrT)rrrrr�test_attributes_writable�s	z,AbstractMemoryTests.test_attributes_writablecCs�x�|jD]�}||j�}tj|�}|j|�}tj|�}t|d�}|j|||jd��|jtj|�|�d}|jtj|�|�q
WdS)Nzutf-8)	rrrrr�strr:�encoder)rr!r"r#rZoldviewrefcount�srrr�test_getbuffer�sz"AbstractMemoryTests.test_getbufferc	CsTxM|jD]B}t|t�s%q
nGdd�d�}Gdd�d|�}Gdd�d�}||d��}|j|�}|�}||_||_tj|�}d}}}tj	�|j
|�dk|��||d��}|�}||_||_tj|�}d}}tj	�|j
|�dk|��q
WdS)Nc@seZdZdd�ZdS)z+AbstractMemoryTests.test_gc.<locals>.MyViewcSst|�|_dS)N)r1r)r�baserrr�__init__�sz4AbstractMemoryTests.test_gc.<locals>.MyView.__init__N)�__name__�
__module__�__qualname__r\rrrr�MyView�sr`c@seZdZdS)z-AbstractMemoryTests.test_gc.<locals>.MySourceN)r]r^r_rrrr�MySource�srac@seZdZdS)z-AbstractMemoryTests.test_gc.<locals>.MyObjectN)r]r^r_rrrr�MyObject�srbsabc)r�
isinstance�typerr�o�weakref�ref�gcZcollectrL�x)	rr!r`rarbr"rre�wrrrr�test_gc�s.			
			

zAbstractMemoryTests.test_gccYCs�|jtd�}|�t|�WdQX|�|j�WdQX|�|j�WdQX|�
|dWdQX|�d|d<WdQX|�t|�WdQX|�|jWdQX|�|jWdQX|�|jWdQX|�|j	WdQX|�|j
WdQX|�|jWdQX|�|�WdQXWdQX|jdt
|��|jdt|��|j||�|j|t||j���|j|||j��dS)NZreleasedr�xzreleased memory)ZassertRaisesRegexr>rDrFrIr+r=rNrOrTrPrQZassertInrW�reprrZassertNotEqualr1r)rrr!Zcheckrrr�_check_released�sB





z#AbstractMemoryTests._check_releasedcCs�x�|jD]y}||j�}|j|�}|�}|j||�WdQX|j||�|j|�}|�|j�WdQXq
WdS)N)rrr�assertIsrn�release)rr!r"r�cmrrr�test_contextmanagers	z'AbstractMemoryTests.test_contextmanagercCsjxc|jD]X}||j�}|j|�}|j�|j||�|j�|j||�q
WdS)N)rrrrprn)rr!r"rrrr�test_release!s

z AbstractMemoryTests.test_releasecCsl|j}|dkr%|jd�n||j�}|j|�}tjd�}|jt|j|�dS)Nzno read-only type to testsZZZZ)	r	r0rr�io�BytesIOrr �readinto)rr!r"rr'rrr�test_writable_readonly+s	z*AbstractMemoryTests.test_writable_readonlycCs|jt|ji�dS)N)rr r)rrrr�test_getbuf_fail6sz$AbstractMemoryTests.test_getbuf_failcCs�|j}|dkr%|jd�n||j�}|j|�}|jt|�td��|j�|jt|�td��|j|�}|j�|jtt|�dS)Nzno read-only type to testsabcdef)	r	r0rrr�hashrprr>)rr!r"rrrr�	test_hash9s	

zAbstractMemoryTests.test_hashcCsZ|j}|dkr%|jd�n||j�}|j|�}|jtt|�dS)Nzno writable type to test)r
r0rrrr>ry)rr!r"rrrr�test_hash_writableKs	z&AbstractMemoryTests.test_hash_writablecs�x�|jD]�}||j�}|j|�}g�|�fdd�}tj||�}|j|�|�~tjj�|j|�d�|j�d|�q
WdS)Ncs�j|�dS)N)�append)rjr")�Lrr�callbackZsz2AbstractMemoryTests.test_weakref.<locals>.callbackr)	rrrrfrgro�test�supportZ
gc_collect)rr!r"rr~rjr)r}r�test_weakrefTs
z AbstractMemoryTests.test_weakrefcCs�x�|jD]�}||j�}|j|�}tt|j���}|jtt|��|�|jtt|��t|ddd���q
WdS)Nrr)rrrr)�reversedrIr)rr!r"rZaslistrrr�
test_reversedcsz!AbstractMemoryTests.test_reversedcCstjdddddg�}t|�}|jd�}|jd�}|dd�}t|�}~|j|dd�|j|dd�|j|jd�|j|jd�|jd�}|j|dd�|j|dd�|j|jd�|j|jd�dS)N�H��Brr7�I)�arrayr1�castrr=)rrrirr"r9�d�_rrr�test_issue22668ks z#AbstractMemoryTests.test_issue22668N)r]r^r_r�propertyrrr$r%r,r2r@rBrHrKrMrSrUrVrZrkrnrrrsrwrxrzr{r�r�r�rrrrrs64	

&
	rc@s.eZdZeZeZeZdZdZ	dS)�BaseBytesMemoryTestsrr�N)
r]r^r_rDr	�	bytearrayr
rCrNr=rrrrr��s
r�c@s|eZdZdZdd�Zdd�Zejd�jZdZe	j
d�dd��Ze	j
d	�d
d��ZdS)�BaseArrayMemoryTestsNcCstjdt|��S)Nr')r�r))rr"rrrr�szBaseArrayMemoryTests.<lambda>cCstjdt|��j�S)Nr')r�r)rF)rr"rrrr�sr'z/XXX test should be adapted for non-byte bufferscCsdS)Nr)rrrrrZ�sz#BaseArrayMemoryTests.test_getbufferz:XXX NotImplementedError: tolist() only supports byte viewscCsdS)Nr)rrrrrK�sz BaseArrayMemoryTests.test_tolist)
r]r^r_r	r
rCr�rNr=�unittest�skiprZrKrrrrr��sr�c@s(eZdZdd�Zdd�ZdS)�BaseMemoryviewTestscCs
t|�S)N)r1)r�objrrrr�szBaseMemoryviewTests._viewcCs|j|||��dS)N)r)rr!r��contentsrrrr:�sz#BaseMemoryviewTests._check_contentsN)r]r^r_rr:rrrrr��sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�BaseMemorySliceTestssXabcdefYcCst|�}|dd�S)Nrr)r1)rr�rrrrr�szBaseMemorySliceTests._viewcCs$|j|dd�||��dS)Nrr)r)rr!r�r�rrrr:�sz$BaseMemorySliceTests._check_contentscCscx\|jD]Q}t||j��}tj|�}|dd�|jtj|�|�q
WdS)Nrr7)rr1rrrr)rr!rr#rrr�	test_refs�s
zBaseMemorySliceTests.test_refsN)r]r^r_rrr:r�rrrrr��sr�c@s.eZdZdZdd�Zdd�ZdS)�BaseMemorySliceSliceTestssXabcdefYcCs$t|�}|dd�dd�S)Nrr)r1)rr�rrrrr�szBaseMemorySliceSliceTests._viewcCs$|j|dd�||��dS)Nrr)r)rr!r�r�rrrr:�sz)BaseMemorySliceSliceTests._check_contentsN)r]r^r_rrr:rrrrr��sr�c@seZdZdd�ZdS)�BytesMemoryviewTestcCs�x�|jD]�}||j�}|jt|��|jtd|��|jtt�|jtt||�|jttd|�|jtt|dd�q
WdS)N�objectZargumentT)rrrLr1rr )rr!�obrrr�test_constructor�sz$BytesMemoryviewTest.test_constructorN)r]r^r_r�rrrrr��sr�c@seZdZdd�ZdS)�ArrayMemoryviewTestcCsftjdtd��}t|�}tjdtddd��}||dd�<|j||�dS)Nr'�
�	rrr)r�r*r1r)rrrZnew_arrr�test_array_assign�s
z%ArrayMemoryviewTest.test_array_assignN)r]r^r_r�rrrrr��sr�c@seZdZdS)�BytesMemorySliceTestN)r]r^r_rrrrr��sr�c@seZdZdS)�ArrayMemorySliceTestN)r]r^r_rrrrr��sr�c@seZdZdS)�BytesMemorySliceSliceTestN)r]r^r_rrrrr��sr�c@seZdZdS)�ArrayMemorySliceSliceTestN)r]r^r_rrrrr��sr�cCstjjt�dS)N)rr�Zrun_unittestr]rrrr�	test_main�sr��__main__)�__doc__r�Ztest.supportrrrhrfr�rtrr�r�r�r�r�ZTestCaser�r�r�r�r�r�r�r]rrrr�<module>s:�v