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_memoryio.cpython-34.pyc

�
g faq�@sZdZddlZddlmZddlZddlZddlZGdd�d�ZGdd�d�Z	Gdd	�d	�Z
Gd
d�de	ee
ej�ZGdd
�d
�Z
Gdd�de	ee
ej�ZGdd�de
ej�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�ZedkrVe�ndS)zdUnit tests for memory-based file-like objects.
StringIO -- for unicode strings
BytesIO -- for bytes
�N)�supportc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�MemorySeekTestMixincCs"|jd�}|j|�}dS)N�
1234567890)�buftype�ioclass)�self�buf�bytesIo�r
�7/opt/alt/python34/lib64/python3.4/test/test_memoryio.py�testInitszMemorySeekTestMixin.testInitcCs�|jd�}|j|�}|j|dd�|jd��|j|dd�|jd��|j|dd�|jd��|j|j|j��dS)Nr���i�)rr�assertEqual�read�EOF)rrr	r
r
r�testReads###zMemorySeekTestMixin.testReadcCsQ|jd�}|j|�}|j||j��|j|j|j��dS)Nr)rrrrr)rrr	r
r
r�testReadNoArgssz"MemorySeekTestMixin.testReadNoArgscCs�|jd�}|j|�}|jd�|jd�|j||j��|jd�|j|dd�|j��|jt|jd�dS)Nrrr�g)rrr�seekr�assertRaises�	TypeError)rrr	r
r
r�testSeek#s


 zMemorySeekTestMixin.testSeekcCs~|jd�}|j|�}|jd|j��|jd�|jd|j��|jd�|jd|j��dS)Nrrri')rrr�tellr)rrr	r
r
r�testTell/s

zMemorySeekTestMixin.testTellN)�__name__�
__module__�__qualname__rrrrrr
r
r
rr
s
	rc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)S)*�MemoryTestMixincCs&|j�}|j|j|j�dS)N)rr�UnsupportedOperation�detach)rrr
r
r�test_detach<szMemoryTestMixin.test_detachcCs&|j|j|d��d�|j|jd�d�|j|j|d��d�|j|j�d�|j|jd�d�|j|j�d�|j|j|d��d�|j|jd�d�|j|j|d��d	�|j|jd
�d
�|j|j�d	�dS)Nzblah.rrzHello.�z	 world


�	�hr
�)r�writerr�truncate)r�f�tr
r
r�	write_ops@szMemoryTestMixin.write_opscCs�|jd�}|j|�}|j||j�|j|j�|�|j�}|j||j�|j|j�|�|jt|jd�|j�|jt	|j|jd��dS)Nzhello world
�)
rrr+r�getvaluerrr'�close�
ValueError)rr�memior
r
r�
test_writeMs
zMemoryTestMixin.test_writecCs�|jd�}|j�}|j|j|gd�d�|j|j�|d�|jg�|j|j�|d�|j�}|jt|j|gdg�|j|j�|�|jt|jd�|j�|jt|jg�dS)Nr�dr
)	rrr�
writelinesr-rrr.r/)rrr0r
r
r�test_writelinesZs 
 
zMemoryTestMixin.test_writelinescs;�j�}�fdd�}�jt|j|��dS)Nc3s�jd�Vt�dS)N�spam)r�KeyboardInterruptr
)rr
r�	error_genksz8MemoryTestMixin.test_writelines_error.<locals>.error_gen)rrr6r3)rr0r7r
)rr�test_writelines_errorisz%MemoryTestMixin.test_writelines_errorcCs||jd�}|j|�}|jt|jd�|jd�|j|j�d�|j|j�|dd��|j|jd�d�|j|j�|dd��|j|j�d�|jdd�|j	|�|j|j�|dd�|�|j�}|j|jd�|�|j|j�|�|jt
|jd�|j�|jt|jd�dS)	Nrr
r#rr��0���)rrrr/r(rrr-rr'rr.)rrr0�posr
r
r�
test_truncateqs$
  
$
zMemoryTestMixin.test_truncatecCs�|jd�}|j|�}|j|j�|�|jd�}|j|j�|j�|j|d�|j|j�|d�|j|�|j|j�|�|jt|jg�dS)Nrr9)rrrr-r�__init__rr)rrr0r
r
r�	test_init�s
zMemoryTestMixin.test_initcCs�|jd�}|j|�}|j|jd�|j�|j|jd�|dd��|j|jd�|dd��|j|jd�|dd��|j|j�|j�|jd�|j|j�|�|j|j�|j�|j|j�d�|jd�|j|jd
�|�|jd�|jt|j��t|��|jd�|jt|j��t|��|jd�|j|jd�|�|jt	|jd	�|j
�|jt|j�dS)Nrrr
rri��
r2r,r;)rrrrrrr�typerrr.r/)rrr0r
r
r�	test_read�s,###


"
"

zMemoryTestMixin.test_readcCsU|jd�}|j|d�}|j|jd�|j�|j|j�|�|j|j�|�|j|j�|j�|jd�|j|jd�|dd��|j|jd�|dd��|j|jd�|dd��|jd�|j|jd
�|�|jd�|j|jd�|j�|jd�}|j|ddd��}|j|j�|�|j|j�|�|j|j�|dd��|j|j�|j�|jd�|jt|j��t|��|j|j�|�|jt|jd	�|j	�|jt
|j�dS)
Nz1234567890
r9rrr@�r
rr,r;r;r;)rrr�readlinerrrArrr.r/)rrr0r
r
r�
test_readline�s4
###

 
"
zMemoryTestMixin.test_readlinecCs�|jd�}|j|d�}|j|j�|gd�|jd�|j|j�|dd�g|gd�|jd�|j|jd�|gd�|jd�|j|jd
�|gd�|jd�|j|jd�|gd�|jd�|jt|j�d�t|��|jd�|j|jd�|gd�|jt|jd	�|j�|jt	|j�dS)Nz1234567890
r@rr$rrCr9r
r,r;)
rrr�	readlinesrrArrr.r/)rrr0r
r
r�test_readlines�s$
.
 
 
 
&
 
zMemoryTestMixin.test_readlinescCs'|jd�}|j|d�}|jt|�|�|jt|d��|jt|d��d}x(|D] }|j||�|d7}qqW|j|d�|jd�d}x(|D] }|j||�|d7}q�W|j|d�|j|d�}|j�|jt	|j
�dS)Nz1234567890
r@�__iter__�__next__rr
r9)rrr�iterZ
assertTrue�hasattrrr.rr/rI)rrr0�i�liner
r
r�
test_iterator�s&



zMemoryTestMixin.test_iteratorcCs�|jd�}|j|�}|j|j�|�|j�|j|j�|�|jt|j��t|��|j|d�}|j|j�dd�|jd��|j|�}|j�|jt|j�dS)Nri�rZ890���)	rrrr-rrAr.rr/)rrr0r
r
r�
test_getvalue�s
")
zMemoryTestMixin.test_getvaluecCs�|jd�}|j|�}|jd�|jt|jd�|jt|jdd�|jt|jdd�|j|jd�d�|j|jdd�d�|j|j�|�|j|jd�d�|j|jdd�d�|j|j�|dd��|j|jt|��t|��|j|j�|j�|jt|�d�|j|j�|j�|j|jdd�t|��|j|j�|j�|j	�|jt|jd�dS)	Nrrr
rrr9r;r;)
rrrrr/rr�lenrr.)rrr0r
r
r�	test_seeks(
 %"
zMemoryTestMixin.test_seekcCs�|jd�}|j|�}|j|jt|�d�d�|j|j�|j�|j|j�d�|j|j�|�|j	|j�|j|j�|�|j	|�|j|j�||jd�|�dS)Nrr
��)
rrrrrQrrrr-r')rrr0r
r
r�
test_overseeks#
zMemoryTestMixin.test_overseekcCs�|jd�}|j|�}|j|j�d�|jd�|j|j�d�|jd�|j|j�d�|j�|jt|j�dS)Nrrri')rrrrrr.rr/)rrr0r
r
r�	test_tell&s


zMemoryTestMixin.test_tellcCs8|jd�}|j|�}|j|j�d�dS)Nr)rrr�flush)rrr0r
r
r�
test_flush2szMemoryTestMixin.test_flushcCs�|j�}|j|j�d�|j|j�d�|j|j�d�|j|j�d�|j|jd�|j�|jt	|j�|jt	|j�|jt	|j�|jt	|j�|j|jd�dS)NTF)
rr�writable�readable�seekable�isatty�closedr.rr/)rr0r
r
r�
test_flags8s
zMemoryTestMixin.test_flagscsc�jd����fdd�}��fdd�}�j|����j|���dS)Nrcs/Gdd�d�j�}|��}|j�S)Nc@seZdZdS)z>MemoryTestMixin.test_subclassing.<locals>.test1.<locals>.MemION)rrrr
r
r
r�MemIOJsr_)rr-)r_�m)rrr
r�test1Isz/MemoryTestMixin.test_subclassing.<locals>.test1cs8G�fdd�d�j�}|�d�}|j�S)Ncs"eZdZ�fdd�ZdS)z>MemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIOcs�jj||�dS)N)rr>)�me�a�b)rr
rr>PszGMemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIO.__init__N)rrrr>r
)rr
rr_Osr_)rr-)r_r`)rrr
r�test2Nsz/MemoryTestMixin.test_subclassing.<locals>.test2)rr)rrarer
)rrr�test_subclassingGs
z MemoryTestMixin.test_subclassingcCs0x)td�D]}|j�}d|_q
WdS)Nr2r
)�ranger�foo)r�_r0r
r
r�test_instance_dict_leakWsz'MemoryTestMixin.test_instance_dict_leakc	s��jd�}�j|�}d|_|jd�G�fdd�d�j�}ddl}d|_|j|_||_||d�}|jd�x�t	dt
jd	�D]�}x�||fD]�}t
jt
j
|d
|��}�j|j�|j���j|j|j��j|j|j��j|j�|j��|j��jtt
j
||�q�Wq�W|`dS)Nr�*r9cs"eZdZ�fdd�ZdS)z6MemoryTestMixin.test_pickling.<locals>.PickleTestMemIOcs �jj||�||_dS)N)rr>rh)rbZ	initvaluerh)rr
rr>esz?MemoryTestMixin.test_pickling.<locals>.PickleTestMemIO.__init__N)rrrr>r
)rr
r�PickleTestMemIOdsrlr�__main__�Pr
Zprotocol)rrrhrrmrrrrlrg�pickleZHIGHEST_PROTOCOL�loads�dumpsrr-�	__class__rr.rr/)	rrr0rlrmZsubmemio�proto�objZobj2r
)rr�
test_pickling^s*	
		

!zMemoryTestMixin.test_picklingN)rrrr"r+r1r4r8r=r?rBrErGrNrPrRrUrVrXr^rfrjrur
r
r
rr:s(


rc@seZdZdd�ZdS)�BytesIOMixincCs$|jd�}|j�}|jt|�d�|jd�|j�}|jt|�d�|jt|jdd�|jt|j�|jt|j	�|j
|j�d|dd�<|jt|�d�|j|j�d�~t
j�|j�|j	�|jt|j�dS)	Ns
1234567890r�xr2sabcrr#s
123abc7890)r�	getbufferr�bytesrr�BufferErrorr'r(r.�assertFalser]r-rZ
gc_collectr/)rr0rr
r
r�test_getbuffer�s$



zBytesIOMixin.test_getbufferN)rrrr|r
r
r
rrv�srvc@s�eZdZejZedd��ZejZdZ	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�ZdS)�
PyBytesIOTestcCs
|jd�S)N�ascii)�encode)�sr
r
rr�szPyBytesIOTest.buftype�cCsK|jd�}|j|�}|jt|j�|j|j�|�dS)Nr)rrrr�read1rr)rrr0r
r
r�
test_read1�szPyBytesIOTest.test_read1cCs�|jd�}|j|�}td�}|j|j|�d�|j|d�|j|j|�d�|j|d�|j|j|�d�|j|d�td�}|jd�|j|j|�d�|j|d	�td
�}|jd�|j|j|�d�|j|d
�|jt|jd�ddl}|jdd�}|j|�}|j|�|j|j	�d	�|j
�|jt|j|�|jd
�}t�}|jd�|j|�|j|d
�dS)Nrshellors12345s67890rshello worldr@s1234567890dr�r,rds123rk)rr�	bytearrayr�readintorrr�array�tobytesr.r/)rrr0rdr�rcr
r
r�
test_readinto�s<



	

zPyBytesIOTest.test_readintocCs7|jd�}|j|�}|j|jd
d�d�|j|jdd�d�|j|jdd�d�|j|jdd�d�|j|jdd�d�|j|jdd�d	�|jd
d�|j|j�|dd��|jd�|jdd�|j|j�|dd��dS)Nrr
rrrr9r$r@rSr;���r;rOrO)rrrrr)rrr0r
r
r�test_relative_seek�s 
z PyBytesIOTest.test_relative_seekcCsU|j�}|jt|jd�|jt|jd�|jt|jdg�dS)Nr)rrrr'r3)rr0r
r
r�test_unicode�szPyBytesIOTest.test_unicodecCs�d}ddl}|jdt|��}|j|�}|j|j�|�|j|j|�d�|j|j�|�dS)Ns
1234567890rrdr@)r��listrrr-r')rrr�rcr0r
r
r�test_bytes_array�szPyBytesIOTest.test_bytes_arraycCs?|jd�}|jd|�|jt|j|dd�dS)NrZ
initial_bytesrh)rrrr)rrr
r
r�test_issue5449�szPyBytesIOTest.test_issue5449N)rrr�pyior �staticmethodr�BytesIOrrr�r�r�r�r�r�r
r
r
rr}�s		!	r}c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TextIOTestMixincs�|jdd���fdd�}|j�jd��jd�|�|j�jd��jd�|�|j�jd
��jd�|�|j�jd�dS)N�newlinecs�jd��j�dS)Nr)rrr
)r0r
r�force_decodes
z<TextIOTestMixin.test_newlines_property.<locals>.force_decodeza
�
zb
�
zc
d�
)r�r�)r�r�r�)rr�newlinesr')rr�r
)r0r�test_newlines_property�s


z&TextIOTestMixin.test_newlines_propertycCs�|j�}|jt|jdd�|jt|jdd�|jt|jdd�|jt|jdd�|jt|jdd�|jt|jdd�dS)Nr
rr9r;rOr;)rr�OSErrorr)rr0r
r
rr�sz"TextIOTestMixin.test_relative_seekcCs@|j�}|j|j�|j|j�|j|j�dS)N)rZassertIsNone�encoding�errorsr{�line_buffering)rr0r
r
r�test_textio_propertiessz&TextIOTestMixin.test_textio_propertiescCs�|jd�}|jt|�dddg�|j|j�d�|j�}|j|jd�d�|jd�|jt|�dddg�|j|j�d�dS)Nza
b
c
dza
zb
zc
d�r)rrr�r-r'r)rr0r
r
r�test_newline_default!s
z$TextIOTestMixin.test_newline_defaultcCs�|jddd�}|jt|�ddddg�|jd�|j|jd�d	�|j|jd
�d�|j|jd
�d�|j|jd�d
�|j|j�d�|jdd�}|jd
|jd��|jd|jd��|jd|jd��|jd�|j|j�d�|j|j�d�|jddd�}|j|jd�d�dS)Nza
b
c
dr�za
zb
zc
�drr
rcr9z
bz
cr�za
b
c
drzb
zc
dza
bza
b)rrr�rrr-r')rr0r
r
r�test_newline_none,s""

z!TextIOTestMixin.test_newline_nonecCsd|jddd�}|jt|�ddddg�|jd�|j|jd	�d
�|j|jd�d�|j|jd
�d�|j|j�d�|jdd�}|jd|jd��|jd|jd��|jd|jd��|jd|jd��|jd�|jt|�ddddg�|j|j�d�dS)Nza
b
c
dr�r,za
zb
zc
r�rrza
b
r9z
cr
r�zb
z
d)rrr�rrr-r')rr0r
r
r�test_newline_emptyBs"

"z"TextIOTestMixin.test_newline_emptycCs�|jddd�}|jt|�dddg�|j|j�d�|jdd�}|j|jd�d�|jd�|jt|�dddg�|j|j�d�dS)	Nza
b
c
dr�r�za
zb
zc
dr�r)rrr�r-r'r)rr0r
r
r�test_newline_lfUs
zTextIOTestMixin.test_newline_lfcCs|jddd�}|j|j�d�|jd�|jt|�ddddd	g�|j|j�d�|jdd�}|j|jd�d
�|jd�|jt|�ddddd	g�|jd�|j|j�ddddd	g�|j|j�d�dS)Nza
b
c
dr�r�za
b

c
drza
zb
zc
r�r�)rrrrr�r-r'rF)rr0r
r
r�test_newline_cras
%
%
%zTextIOTestMixin.test_newline_crcCs
|jddd�}|j|j�d�|jd�|jt|�dddg�|jd�|j|j�dddg�|j|j�d�|jdd�}|j|jd�d	�|jd�|jt|�dddg�|j|j�d�dS)
Nza
b
c
dr�z
z
a
b

c
drza
zb

zc
dr�)rrrrr�rFr-r')rr0r
r
r�test_newline_crlfqs


z!TextIOTestMixin.test_newline_crlfcCsH|jddd�}|j|jd�d�|j|j�d�dS)Nza
b
r�rza
b
)rrrr-)rr0r
r
r�test_issue5265�szTextIOTestMixin.test_issue5265cCsW|jt|jdd�|jt|jdd�xdD]}|jd|�q9WdS)	Nr�s
�errorr,r�r��
)Nr,r�r�r�)rrrr/)rr�r
r
r�test_newline_argument�s
z%TextIOTestMixin.test_newline_argumentN)rrrr�r�r�r�r�r�r�r�r�r�r�r
r
r
rr��s
	r�c@s:eZdZeZejZejZdZ	dd�Z
dS)�PyStringIOTestr,cCsX|jd�}|j|j�d�|j�}|jd�|j|j�d�dS)Nu�)rrrr'r-)rr0r
r
r�test_lone_surrogates�s

z#PyStringIOTest.test_lone_surrogatesN)rrr�strrr��StringIOrr rr�r
r
r
rr��s
		r�c@sDeZdZdZeZejZdZGdd�dej	�Z
dS)�PyStringIOPickleTestzETest if pickle restores properly the internal state of StringIO.
    r,c@s(eZdZdd�Zdd�ZdS)zPyStringIOPickleTest.ioclasscOs"tjtjtj||���S)N)rorprqr�r�)�cls�args�kwargsr
r
r�__new__�sz$PyStringIOPickleTest.ioclass.__new__cOsdS)Nr
)rr�r�r
r
rr>�sz%PyStringIOPickleTest.ioclass.__init__N)rrrr�r>r
r
r
rr�srN)rrr�__doc__r�rr�r rr�rr
r
r
rr��s
	r�c@sXeZdZejZejZdd�Zdd�Ze	j
Z
e	jdd��ZdS)�CBytesIOTestcCs�|j�}|j�}|jt|�d�t|d�|j|dt�|ddk	rw|j|dt�n|j�|j	t
|j�dS)Nrrr
r9)r�__getstate__rrQr��assertIsInstance�int�dictr.rr/)rr0�stater
r
r�
test_getstate�s
zCBytesIOTest.test_getstatecCs
|j�}|jd�|jtd�ddf�|jddidd6f�|jt|jd
�|jt|jd�|jt|jd�|jt|jd�|jt|jd�|jt|j�|jt|jd�|j�|jt|jd�dS)N�no errorrrr5r�r
�unicode��len-test�closed)r�rNr;)r�r;N)r�rN)r�r�N)r�rr)r�r)r�rN)r�__setstate__r�rr/rr.)rr0r
r
r�
test_setstate�s

zCBytesIOTest.test_setstatecCs�tjd�}|j}|jtjtj��|�|tj�|�|tjd�|dd�|tjdd�|dd�dS)NZP2nN2Pn�ar
i�)rZcalcobjsize�check_sizeofr�object�
__sizeof__�ior�)rZbasesizeZcheckr
r
r�test_sizeof�s	zCBytesIOTest.test_sizeofN)
rrrr�r�rr r�r�rr�Zcpython_onlyr�r
r
r
rr��s			r�c@sFeZdZejZejZdd�Zdd�Zdd�Z	dS)�
CStringIOTestcCs�|jd�}|j|�}|j|j�|�|j|j|�t|��|j|j�t|��|j|j�|�|j|j|�t|��|j|j�t|�d�|j|j�||�dS)Nu𠌊𠍇r9)rrrr-r'rQr)rrr0r
r
r�
test_widechar�s zCStringIOTest.test_widecharcCs�|j�}|j�}|jt|�d�|j|dt�|j|dt�|j|dt�|ddk	r�|j|dt�n|j�|j	t
|j�dS)Nrrr
r9r)rr�rrQr�r�r�r�r.rr/)rr0r�r
r
rr��s
zCStringIOTest.test_getstatecCs |j�}|jd
�|jdddidd6f�|jt|jd�|jt|jd�|jt|jd�|jt|jd�|jt|jd�|jt|jd�|jt|jd�|jt|j�|jt|jd�|j�|jt|jd�dS)N�no errorr�rr,rr5r)r
r���len-testr])r�r�rN)r,r)rNr;)r,r,r;N)r�r,rN)r,r�rN)r,r,r�N)r,r,rr)r�r)zclosedr,rN)rr�rr/rr.)rr0r
r
rr��s
 
zCStringIOTest.test_setstateN)
rrrr�r�rr r�r�r�r
r
r
rr��s
		r�c@s2eZdZejZGdd�dej�ZdS)�CStringIOPickleTestc@s(eZdZdd�Zdd�ZdS)zCStringIOPickleTest.ioclasscOs"tjtjtj||���S)N)rorprqr�r�)r�r�r�r
r
rr�sz#CStringIOPickleTest.ioclass.__new__cOsdS)Nr
)rr�r�r
r
rr>sz$CStringIOPickleTest.ioclass.__init__N)rrrr�r>r
r
r
rrsrN)rrrr�r r�rr
r
r
rr�s	r�cCs)ttttttg}tj|�dS)N)r}r�r�r�r�r�rZrun_unittest)Ztestsr
r
r�	test_mainsr�rm)r�ZunittestZtestrr�Z_pyior�rorrrvZTestCaser}r�r�r�r�r�r�r�rr
r
r
r�<module>s*-�KX�*0