Your IP : 216.73.216.52


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_memoryio.cpython-310.opt-1.pyc

o

0�i�}�@s�dZddlZddlmZddlZddlZddlZddlZGdd�d�Z	Gdd�d�Z
Gdd	�d	�ZGd
d�dee
ej�Z
Gdd
�d
�ZGdd�dee
eej�ZGdd�deej�ZGdd�de
�ZGdd�de�ZGdd�de�Zedkr{e��dSdS)zdUnit tests for memory-based file-like objects.
StringIO -- for unicode strings
BytesIO -- for bytes
�N)�supportc@s eZdZdd�Zdd�ZeZdS)�IntLikecCs
||_dS�N�Z_num)�selfZnum�r�9/opt/alt/python310/lib64/python3.10/test/test_memoryio.py�__init__s
zIntLike.__init__cCs|jSrr�rrrr�	__index__szIntLike.__index__N)�__name__�
__module__�__qualname__r	r�__int__rrrrrsrc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�MemorySeekTestMixincCs|�d�}|�|�}dS�N�
1234567890)�buftype�ioclass�r�bufZbytesIorrr�testInit�
zMemorySeekTestMixin.testInitcCsx|�d�}|�|�}|�|dd�|�d��|�|dd�|�d��|�|dd�|�d��|�|j|���dS)Nr�����rr�assertEqual�read�EOFrrrr�testReads

zMemorySeekTestMixin.testReadcCs:|�d�}|�|�}|�||���|�|j|���dSrrrrrr�testReadNoArgs$s

z"MemorySeekTestMixin.testReadNoArgscCsn|�d�}|�|�}|�d�|�d�|�||���|�d�|�|dd�|���|�t|jd�dS)Nrrr��)rrr�seekr�assertRaises�	TypeErrorrrrr�testSeek+s




zMemorySeekTestMixin.testSeekcCs\|�d�}|�|�}|�d|���|�d�|�d|���|�d�|�d|���dS�Nrrri')rrr�tellr%rrrr�testTell7s



zMemorySeekTestMixin.testTellN)rr
rrr!r"r(r+rrrrrs	rc@s�eZdZdd�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�dSr)rr&�UnsupportedOperation�detach�rrrrr�test_detachDszMemoryTestMixin.test_detachcCs�|�|�|d��d�|�|�d�d�|�|�|d��d�|�|��d�|�|�d�d�|�|��d�|�|�|d��d�|�|�d�d�|�|�|d��d	�|�|�d
�d
�|�|��d	�dS)Nzblah.rrzHello.�z	 world


�	�hr�)r�writer%r*�truncate)r�f�trrr�	write_opsHszMemoryTestMixin.write_opscCs�|�d�}|�|�}|�||j�|�|��|�|��}|�||j�|�|��|�|�t|jd�|��|�t	|j|�d��dS)Nzhello world
�)
rrr9r�getvaluer&r'r5�close�
ValueError�rr�memiorrr�
test_writeUs

zMemoryTestMixin.test_writecCs�|�d�}|��}|�|�|gd�d�|�|��|d�|�g�|�|��|d�|��}|�t|j|gdg�|�|��|�|�t|jd�|��|�t|jg�dS)Nr�dr)	rrr�
writelinesr;r&r'r<r=r>rrr�test_writelinesbs

zMemoryTestMixin.test_writelinescs*���}�fdd�}��t|j|��dS)Nc3s���d�Vt�)N�spam)r�KeyboardInterruptrr
rr�	error_genss�z8MemoryTestMixin.test_writelines_error.<locals>.error_gen)rr&rErB)rr?rFrr
r�test_writelines_errorqsz%MemoryTestMixin.test_writelines_errorcCsn|�d�}|�|�}|�t|jd�|�t|jtd��|�d�|�|�td��d�|�|��|dd��|�|��d�|�|��|dd��|�|�d�d�|�|��|dd��|�|�	�d�|�dd�|�
|�|�|��|dd�|�|�	�}|�|�d�|�|�|�	�|�|�t|jd�|��|�t|jd�|�t|jtd��dS)	Nr���r1�rr��0)
rrr&r=r6rr%rr;r*r5r'r<)rrr?�posrrr�
test_truncateys,



zMemoryTestMixin.test_truncatecCs�|�d�}|�|�}|�|��|�|�d�}|�|��|j�|�|d�|�|��|d�|�|�|�|��|�|�t|jg�dS)NrrJ)rrrr;r r	r&r'r>rrr�	test_init�s



zMemoryTestMixin.test_initcCsz|�d�}|�|�}|�|�d�|j�|�|�d�|dd��|�|�d�|dd��|�|�d�|dd��|�|��|j�|�d�|�|�td��|j�|�|�td��|dd��|�|�td��|dd��|�|�td��|dd��|�d�|�|��|�|�|��|j�|�|��d�|�d�|�|�d�|�|�d�|�|�td��|�|�d�|�t|���t|��|�d	�|�t|���t|��|�d�|�|�d�|�|�	t
|jd
�|�t|�d�|�|�d�|j�|�t|�d�|�|�td��|j�|�t|�d�|�|��|j�|��|�	t
|j�dS)Nrrrrrr�
rHrAr:)rrrrr r%rr*�typer&r'�lenr<r=r>rrr�	test_read�sF








zMemoryTestMixin.test_readcCs�|�d�}|�|d�}|�|�d�|j�|�|�td��|j�|�|��|�|�|��|�|�|��|j�|�d�|�|�d�|dd��|�|�d�|dd��|�|�d�|dd��|�d�|�|�td��|dd��|�|�td��|dd��|�|�td��|dd��|�d�|�|�d�|�|�d�|�|�td��|�|�d�|�|�d�|j�|�|�td��|j�|�t|�dd�|�|��|j�|�d�}|�|d	dd��}|�|��|�|�|��|�|�|��|dd��|�|��|j�|�d�|�t|���t|��|�|��|�|�	t
|jd
�|��|�	t|j�dS)N�1234567890
rJrrrO�rHrr#r:)
rrr�readliner rr%rQrPr&r'r<r=r>rrr�
test_readline�sH







zMemoryTestMixin.test_readlinecCsZ|�d�}|�|d�}|�|��|gd�|�d�|�|��|dd�g|gd�|�d�|�|�d�|gd�|�d�|�|�d�|gd�|�d�|�|�d�|gd�|�d�|�t|��d�t|��|�d�|�|�d�|gd�|�t|jd	�|�t|�dd
�|�|��g�|�	�|�t
|j�dS)NrSrOrr2rrTrJrHr:r)rrr�	readlinesr%rPr&r'rQr<r=r>rrr�test_readlines�s(

$




zMemoryTestMixin.test_readlinescCs�|�d�}|�|d�}|�t|�|�|�t|d��|�t|d��d}|D]}|�||�|d7}q(|�|d�|�d�d}|D]}|�||�|d7}qD|�|d�|�t|�dd�|�t|�g�|�|d�}|�	�|�
t|j�dS)NrSrO�__iter__�__next__rrrJ)
rrr�iterZ
assertTrue�hasattrr%rQ�listr<r&r=rZ)rrr?�i�linerrr�
test_iterators*



zMemoryTestMixin.test_iteratorcCs�|�d�}|�|�}|�|��|�|��|�|��|�|�t|���t|��|�|d�}|�|��dd�|�d��|�|�}|��|�t|j�dS)Nr�����Z890)	rrrr;rrPr<r&r=r>rrr�
test_getvalues


zMemoryTestMixin.test_getvaluecCs\|�d�}|�|�}|�d�|�t|jd�|�t|jdd�|�t|jdd�|�|�d�d�|�|�dd�d�|�|��|�|�|�d�d�|�|�dd�d�|�|��|dd��|�|�t|��t|��|�|��|j�|�t|�d�|�|��|j�|�|�dd�t|��|�|��|j�|�	�|�t|jd�dS)NrrrHrr#rrJ)
rrrr&r=r%rrQr r<r>rrr�	test_seek,s(


zMemoryTestMixin.test_seekcCs�|�d�}|�|�}|�|�t|�d�d�|�|��|j�|�|��d�|�|��|�|�	|j�|�|��|�|�	|�|�|��||�d�|�dS)Nrr��)
rrrr%rQrr r*r;r5r>rrr�
test_overseekCs


"zMemoryTestMixin.test_overseekcCsr|�d�}|�|�}|�|��d�|�d�|�|��d�|�d�|�|��d�|��|�t|j�dSr))rrrr*r%r<r&r=r>rrr�	test_tellPs



zMemoryTestMixin.test_tellcCs(|�d�}|�|�}|�|��d�dSr)rrr�flushr>rrr�
test_flush\s

zMemoryTestMixin.test_flushcCs�|��}|�|��d�|�|��d�|�|��d�|�|��d�|�|jd�|��|�t	|j�|�t	|j�|�t	|j�|�t	|j�|�|jd�dS)NTF)
rr�writable�readable�seekable�isatty�closedr<r&r=�rr?rrr�
test_flagsbszMemoryTestMixin.test_flagscsF��d����fdd�}��fdd�}��|�����|���dS)Nrcs"Gdd�d�j�}|��}|��S)Nc@seZdZdS)z>MemoryTestMixin.test_subclassing.<locals>.test1.<locals>.MemION)rr
rrrrr�MemIOtsrr�rr;�rr�m�rrrr�test1ssz/MemoryTestMixin.test_subclassing.<locals>.test1cs(G�fdd�d�j�}|�d�}|��S)Nc�eZdZ�fdd�ZdS)z>MemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIOcs�j�||�dSr)rr	)�me�a�br
rrr	zszGMemoryTestMixin.test_subclassing.<locals>.test2.<locals>.MemIO.__init__N�rr
rr	rr
rrrry�rrrsrtrvrr�test2xs
z/MemoryTestMixin.test_subclassing.<locals>.test2)rr)rrwr~rrvr�test_subclassingqs

z MemoryTestMixin.test_subclassingcCs td�D]	}|��}d|_qdS)NrAr)�ranger�foo)r�_r?rrr�test_instance_dict_leak�s�z'MemoryTestMixin.test_instance_dict_leakc	s��d�}��|�}d|_|�d�G�fdd�d�j�}ddl}d|_|j|_||_||d�}|�d�t	dt
jd	�D]D}||fD]=}t
�t
j
||d
��}��|��|�����|j|j���|j|j���|��|���|����tt
j
||�qCq=|`dS)Nr�*rJcrx)z6MemoryTestMixin.test_pickling.<locals>.PickleTestMemIOcs�j�||�||_dSr)rr	r�)ryZ	initvaluer�r
rrr	�s
z?MemoryTestMixin.test_pickling.<locals>.PickleTestMemIO.__init__Nr|rr
rr�PickleTestMemIO�r}r�r�__main__�Pr)Zprotocol)rrr�r%r�r
rrr�r��pickleZHIGHEST_PROTOCOL�loads�dumpsrr;�	__class__r*r<r&r=)	rrr?r�r�Zsubmemio�proto�objZobj2rr
r�
test_pickling�s,




�zMemoryTestMixin.test_picklingN)rr
rr0r9r@rCrGrMrNrRrVrXr`rcrdrgrhrjrqrr�r�rrrrr,Bs*

&)
r,c@s`eZdZejZedd��ZejZdZ	dd�Z
dd�Zdd	�Zd
d�Z
dd
�Zdd�Zdd�ZdS)�
PyBytesIOTestcCs
|�d�S)N�ascii)�encode)�srrrr�s
zPyBytesIOTest.buftype�cCs�|�d�}|��}|�t|�d�|�d�|��}|�t|�d�|�t|jd�|�t|j�|�t|j	�|�
|j�d|dd�<|�t|�d�|�|��d�~t
��|��|�	�|�t|j�dS)N�
1234567890rsdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsabcr#r1s
123abc7890)r�	getbufferr�bytesr%r&�BufferErrorr5r6r<�assertFalseror;rZ
gc_collectr=)rr?rrrr�test_getbuffer�s$

zPyBytesIOTest.test_getbuffercCs<|�d�}|�|�|���|�|�|�|��d�|�dS)NrrH)rrr�read1r/rrr�
test_read1�s
zPyBytesIOTest.test_read1cCsj|�d�}|�|�}td�}|�|�|�d�|�|d�|�|�|�d�|�|d�|�|�|�d�|�|d�td�}|�d�|�|�|�d�|�|d	�td
�}|�d�|�|�|�d�|�|d
�|�t|jd�ddl}|�dd�}|�|�}|�|�|�|�	�d	�|�
�|�t|j|�|�d
�}t�}|�d�|�|�|�|d
�dS)Nrshellors12345s67890rshello worldrOs1234567890dr�r:r{s123r�)rr�	bytearrayr�readintor%r&r'�array�tobytesr<r=)rrr?r{r�rzrrr�
test_readinto�s<








zPyBytesIOTest.test_readintocCs�|�d�}|�|�}|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d�|�|�dd�d	�|�|�dd�d
�|�dd�|�|��|dd��|�d�|�dd�|�|��|dd��dS)NrrHrrr#���rJr2rOrerb)rrrr%rr>rrr�test_relative_seek�s


z PyBytesIOTest.test_relative_seekcCs>|��}|�t|jd�|�t|jd�|�t|jdg�dSr)rr&r'r5rBrprrr�test_unicodeszPyBytesIOTest.test_unicodecCs\d}ddl}|�dt|��}|�|�}|�|��|�|�|�|�d�|�|��|�dS)Nr�rr{rO)r�r]rrr;r5)rrr�rzr?rrr�test_bytes_arrays
zPyBytesIOTest.test_bytes_arraycCs.|�d�}|j|d�|jt|j|dd�dS)Nr)Z
initial_bytes)r�)rrr&r'r/rrr�test_issue5449s
zPyBytesIOTest.test_issue5449N)rr
r�pyior-�staticmethodr�BytesIOrr r�r�r�r�r�r�r�rrrrr��s
!	r�c@sdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�TextIOTestMixincs�|jdd���fdd�}|��jd���d�|�|��jd���d�|�|��jd���d�|�|��jd	�dS)
N��newlinecs��d����dS)Nr)r%rr�r?rr�force_decode%s
z<TextIOTestMixin.test_newlines_property.<locals>.force_decode�a
�
�b
)r��
�c
d)�
r�r�)rr�newlinesr5)rr�rr�r�test_newlines_property s


z&TextIOTestMixin.test_newlines_propertycCsx|��}|�t|jdd�|�t|jdd�|�t|jdd�|�t|jdd�|�t|jdd�|�t|jdd�dS)NrHrr#rbrJ)rr&�OSErrorr%rprrrr�3sz"TextIOTestMixin.test_relative_seekcCs0|��}|�|j�|�|j�|�|j�dSr)rZassertIsNone�encoding�errorsr��line_bufferingrprrr�test_textio_properties=sz&TextIOTestMixin.test_textio_propertiescCsz|�d�}|�t|�gd��|�|��d�|��}|�|�d�d�|�d�|�t|�gd��|�|��d�dS)N�a
b
c
d�r�r�r�rIr�rrr]r;r5r%rprrr�test_newline_defaultFs

z$TextIOTestMixin.test_newline_defaultcCs|jddd�}|�t|�gd��|�d�|�|�d�d�|�|�d�d�|�|�d�d	�|�|�d�d
�|�|��d�|jdd�}|�d|�d��|�d
|�d��|�d
|�d��|�d�|�|��d�|�|��d�|jddd�}|�|�d
�d�dS)Nr�r�)r�zb
zc
�drrrzrJz
b�
cr�za
b
c
dr�r#r�r�za
bza
b�rrr]r%rr;r5rprrr�test_newline_noneQs"

z!TextIOTestMixin.test_newline_nonecCs�|jddd�}|�t|�gd��|�d�|�|�d�d�|�|�d�d	�|�|�d
�d�|�|��d�|jdd�}|�d|�d��|�d|�d
��|�d|�d	��|�d|�d��|�d�|�t|�gd��|�|��d�dS)Nr�r:r�)r�r��c
r�rrza
b
rJr�rr�r��b
z
dr�rprrr�test_newline_emptygs

z"TextIOTestMixin.test_newline_emptycCs�|jddd�}|�t|�gd��|�|��d�|jdd�}|�|�d�d�|�d�|�t|�gd��|�|��d�dS)Nr�r�r�r�rIrr�rprrr�test_newline_lfzs
zTextIOTestMixin.test_newline_lfcCs�|jddd�}|�|��d�|�d�|�t|�gd��|�|��d�|jdd�}|�|�d�d�|�d�|�t|�gd��|�d�|�|��gd��|�|��d�dS)Nr�r�r�za
b

c
dr)za
r�r�r�r�rI)rrrr%r]r;r5rWrprrr�test_newline_cr�s


zTextIOTestMixin.test_newline_crcCs�|jddd�}|�|��d�|�d�|�t|�gd��|�d�|�|��gd��|�|��d�|jdd�}|�|�d�d�|�d�|�t|�gd��|�|��d�dS)Nr�r�r�z
a
b

c
dr)za
zb

r�rI)rrrr%r]rWr;r5rprrr�test_newline_crlf�s


z!TextIOTestMixin.test_newline_crlfcCs4|jddd�}|�|�d�d�|�|��d�dS)Nza
b
r�rza
b
)rrrr;rprrr�test_issue5265�szTextIOTestMixin.test_issue5265cCs>|jt|jdd�|jt|jdd�dD]}|j|d�qdS)N�
r��error)Nr:r�r�r�)r&r'rr=)rr�rrr�test_newline_argument�s
�z%TextIOTestMixin.test_newline_argumentN)rr
rr�r�r�r�r�r�r�r�r�r�r�rrrrr�s
	r�c@s(eZdZeZejZejZdZ	dd�Z
dS)�PyStringIOTestr:cCs@|�d�}|�|��d�|��}|�d�|�|��d�dS)Nu�)rrrr5r;rprrr�test_lone_surrogates�s


z#PyStringIOTest.test_lone_surrogatesN)rr
r�strrr��StringIOrr-r r�rrrrr��sr�c@s0eZdZdZeZejZdZGdd�dej	�Z
dS)�PyStringIOPickleTestzETest if pickle restores properly the internal state of StringIO.
    r:c@�eZdZdd�Zdd�ZdS)zPyStringIOPickleTest.ioclasscO�t�t�tj|i|����Sr)r�r�r�r�r���cls�args�kwargsrrr�__new__��z$PyStringIOPickleTest.ioclass.__new__cO�dSrr�rr�r�rrrr	��z%PyStringIOPickleTest.ioclass.__init__N�rr
rr�r	rrrrr��rN)rr
r�__doc__r�rr�r-r r�rrrrrr��sr�c@s|eZdZejZejZdd�Zdd�Ze	j
Z
e	jdd��Zdd�Z
e	jd	d
��Ze	jdd��Ze	jd
d��Ze	jdd��ZdS)�CBytesIOTestcCsr|��}|��}|�t|�d�t|d�|�|dt�|ddur,|�|dt�|��|�	t
|j�dS)Nr#rrrJ)r�__getstate__rrQr��assertIsInstance�int�dictr<r&r=�rr?�staterrr�
test_getstate�szCBytesIOTest.test_getstatecCs�|��}|�d�|�td�ddf�|�ddddif�|�t|jd�|�t|jd�|�t|jd�|�t|jd	�|�t|jd
�|�t|j�|�t|jd�|��|�t|jd�dS)N)�no errorrNr�rrDr#)r�rHN)ZunicoderN)r�r$N)r�rr)slen-testr)sclosedrN)r�__setstate__r�r&r=r'r<rprrr�
test_setstate�s
zCBytesIOTest.test_setstatecCs^t�d�}|j}|�t�t���|�|t��|�d}|t�d|�|t�	d|��dS)NZP2n2Pnra�a)
rZcalcobjsize�check_sizeofr�object�
__sizeof__�ior��sys�	getsizeof)rZbasesizeZcheck�nrrr�test_sizeof�s
&zCBytesIOTest.test_sizeofcCsLd}t�|�}|�|�}|�t�|�|d�||�|�t�|�|�dS)Ns                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                r)r��getrefcountrr)r�mutationZimm�old_rcr?rrr�_test_cow_mutation�s

zCBytesIOTest._test_cow_mutationcC�dd�}|�|�dS)NcSs|�d�dS)Nr)r6r�rrrr��z0CBytesIOTest.test_cow_truncate.<locals>.mutation�r��rr�rrr�test_cow_truncateszCBytesIOTest.test_cow_truncatecCr�)NcSs|�d�|�d�dS)Nrsfoo)r%r5r�rrrr�rz-CBytesIOTest.test_cow_write.<locals>.mutationr�r�rrr�test_cow_writeszCBytesIOTest.test_cow_writecs,|�d�}|����fdd�}|�|�dS)Nsfoooooocs|���dSr)r�r��r�rrr�r�z0CBytesIOTest.test_cow_setstate.<locals>.mutation)rr�r�)rr?r�rr�r�test_cow_setstates
zCBytesIOTest.test_cow_setstatecCs2td�}t�|�}|�|�}|�t�|�|�dS)Ni)r�r�r�rr)rZbar�r?rrr�test_cow_mutable s

zCBytesIOTest.test_cow_mutableN)rr
rr�r�rr-r�r�rr�Zcpython_onlyr�r�r�r�r�rrrrrr��s"

	


r�c@s0eZdZejZejZdd�Zdd�Zdd�Z	dS)�
CStringIOTestcCs�|�d�}|�|�}|�|��|�|�|�|�t|��|�|��t|��|�|��|�|�|�|�t|��|�|��t|�d�|�|��||�dS)Nu𠌊𠍇rJ)rrrr;r5rQr*r>rrr�
test_widechar0s

zCStringIOTest.test_widecharcCs�|��}|��}|�t|�d�|�|dt�|�|dt�|�|dt�|ddur6|�|dt�|��|�	t
|j�dS)NrrrrJr#)rr�rrQr�r�r�r�r<r&r=r�rrrr�<szCStringIOTest.test_getstatecCs�|��}|�d�|�dddddif�|�t|jd�|�t|jd�|�t|jd	�|�t|jd
�|�t|jd�|�t|jd�|�t|jd
�|�t|j�|�t|jd�|��|�t|jd�dS)N)�no errorr�rNrr:rrDr#)r:r7rN)r:r:rHN)r�r:rN)r:r�rN)r:r:r$N)r:r:rr)zlen-testr)ror:rN)rr�r&r=r'r<rprrrr�Hs
zCStringIOTest.test_setstateN)
rr
rr�r�rr-rr�r�rrrrr*src@s$eZdZejZGdd�dej�ZdS)�CStringIOPickleTestc@r�)zCStringIOPickleTest.ioclasscOr�r)r�r�r�r�r�r�rrrr�^r�z#CStringIOPickleTest.ioclass.__new__cOr�rrr�rrrr	`r�z$CStringIOPickleTest.ioclass.__init__Nr�rrrrr]r�rN)rr
rr�r-r�rrrrrrZsrr�)r�Zunittest�testrr�Z_pyior�r�r�rrr,ZTestCaser�r�r�r�r�rrr�mainrrrr�<module>s2-np�W0
�