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

�
f fO>�@sddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZddlmZddlmZGdd	�d	ej�ZGd
d�dej�Zdd
�Zedkre�ndS)�N)�array)�proxy)�wraps)�TESTFN�check_warnings�run_unittest�make_bad_fd�cpython_only)�UserList)�FileIOc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejejdkd �d!d"��Zd#d$�Zd%d&�Zed'd(��Zed)d*��Zed+d,��Zed-d.��Zed/d0��Zed1d2��Zed3d4��Zed5d6��Z ed7d8��Z!ed9d:��Z"d;d<�Z#ed=d>��Z$ed?d@��Z%edAdB��Z&dCS)D�
AutoFileTestscCsttd�|_dS)N�w)�_FileIOr�f)�self�r�5/opt/alt/python34/lib64/python3.4/test/test_fileio.py�setUpszAutoFileTests.setUpcCs*|jr|jj�ntjt�dS)N)r�close�os�remover)rrrr�tearDowns	zAutoFileTests.tearDowncCswt|j�}|jttd���|j|jj�|j��|jj�d|_|jt	t
|d�dS)N�
�tell)rr�write�bytes�range�assertEqualrr�assertRaises�ReferenceError�getattr)r�prrr�testWeakRefss
	zAutoFileTests.testWeakRefscCs|jjttd���|j|jj�d�|jjd�|j|jj�d�|jjd�|j|jj�d�|jjdd�|j|jj�d�|jjdd�|j|jj�d�|jjd	d�|j|jj�d�dS)
N�rr�������r()rrrrrr�seek)rrrr�testSeekTell%szAutoFileTests.testSeekTellcCsc|j}|j|jd�|j|jd�x-dD]%}|jttft||d�q6WdS)N�wbF�mode�closedZoops)zmodezclosed)rrr,r-r�AttributeError�	TypeError�setattr)rr�attrrrr�testAttributes3s	
zAutoFileTests.testAttributescCs�|jjtddg��|jj�tdd�}ttd�|_|jj|�}|jtdddg�|d|��dS)Nr%r'�b�xr�rs
xxxxxxxxxx)	rrrrrrr�readintor)r�a�nrrr�testReadinto?s
zAutoFileTests.testReadintocCs^ddg}|jj|�|jj�ttd�|_|jj�}|j|d�dS)Ns123s456�rbs123456)r�
writelinesrrr�readr)r�l�bufrrr�testWritelinesListHs
z AutoFileTests.testWritelinesListcCsdtddg�}|jj|�|jj�ttd�|_|jj�}|j|d�dS)Ns123s456r:s123456)r
rr;rrrr<r)rr=r>rrr�testWritelinesUserListPs
z$AutoFileTests.testWritelinesUserListcCsX|jt|jjdddg�|jt|jjd�|jt|jjd�dS)Nr%r'��abc)rr/rr;)rrrr�testWritelinesErrorXs"z!AutoFileTests.testWritelinesErrorcCs�|jjd�|jj�ttd�|_|j|jjd�d�|jjd�|j|jjd�d�|j|jj	d�ddg�dS)Ns
hi
bye
abcr5rshi
sbye
sabc)
rrrrrrr<r)�readline�	readlines)rrrr�test_none_args]s
zAutoFileTests.test_none_argscCs|jt|jjd�dS)NzHello!)rr/rr)rrrr�test_rejectfszAutoFileTests.test_rejectcCs�|jt|j�d|jj|jjf�|j`|jt|j�d|jj�|jjf�|jj�|jt|j�d�dS)Nz<_io.FileIO name=%r mode=%r>z<_io.FileIO fd=%r mode=%r>z<_io.FileIO [closed]>)r�reprr�namer,�filenor)rrrr�testRepris	
zAutoFileTests.testReprcCs�|j}|j|j��|j|j�|jt|jd�|j�|j|j�t	t
d�}|jt|jd�|j|j�|j�|j|j�dS)Nrr5�)
rZassertFalse�isattyr-r�
ValueErrorr<r�
assertTruerrr/r6)rrrrr�
testErrorsrs	

zAutoFileTests.testErrorscCsCddddddddd	d
ddg}|jj�|j|jj�x0|D](}t|j|�}|jt|�qQW|jt|jj�|jt|jjtd
��|jt|jj	�|jt|jj	d�|jt|jj
�|jt|jj
d�|jt|jj�|jt|jjd�dS)NrJrM�seekable�readable�writabler<�readallrDrEr�truncate�flushr%r�)
rrrOr-r rrNr6�	bytearrayr)rr/r;)r�methodsZ
methodname�methodrrr�testMethods�s 

zAutoFileTests.testMethodscCspytdd�WnKtk
r^}z+|j|jd�|j|jd�WYdd}~XnX|jd�dS)N�.r5rzShould have raised OSError)r�OSErrorZassertNotEqual�errnor�filename�fail)r�errr�testOpendir�s&zAutoFileTests.testOpendir�ntz&test only works on a POSIX-like systemc
Csdtjdtj�}|jt��}t|d�WdQXtj|�|j|jj	t	j
�dS)Nr\r5)r�open�O_RDONLYrr]rrrZ	exceptionr^ZEISDIR)r�fd�cmrrr�
testOpenDirFD�s

zAutoFileTests.testOpenDirFDcs"t���fdd��}|S)Ncs[|j}tj|j��z�||�Wdy|jj�Wntk
rUYnXXdS)N)rrrrJr])rr)�funcrr�wrapper�s	
z'AutoFileTests.ClosedFD.<locals>.wrapper)r)rirjr)rir�ClosedFD�szAutoFileTests.ClosedFDcs"t���fdd��}|S)Nc s�|j}tj|j��z`y�||�Wn;tk
rm}z|j|jtj�WYdd}~XnX|jd�Wdy|jj�Wntk
r�YnXXdS)NzShould have raised OSError)	rrrrJr]rr^ZEBADFr`)rrra)rirrrj�s	)
z-AutoFileTests.ClosedFDRaises.<locals>.wrapper)r)rirjr)rir�ClosedFDRaises�szAutoFileTests.ClosedFDRaisescCs|j�dS)N)r)rrrrr�testErrnoOnClose�szAutoFileTests.testErrnoOnClosecCs|jd�dS)N�a)r)rrrrr�testErrnoOnClosedWrite�sz$AutoFileTests.testErrnoOnClosedWritecCs|jd�dS)Nr)r))rrrrr�testErrnoOnClosedSeek�sz#AutoFileTests.testErrnoOnClosedSeekcCs|j�dS)N)r)rrrrr�testErrnoOnClosedTell�sz#AutoFileTests.testErrnoOnClosedTellcCs|jd�dS)Nr)rU)rrrrr�testErrnoOnClosedTruncate�sz'AutoFileTests.testErrnoOnClosedTruncatecCs|j�dS)N)rQ)rrrrr�testErrnoOnClosedSeekable�sz'AutoFileTests.testErrnoOnClosedSeekablecCs|j�dS)N)rR)rrrrr�testErrnoOnClosedReadable�sz'AutoFileTests.testErrnoOnClosedReadablecCs|j�dS)N)rS)rrrrr�testErrnoOnClosedWritable�sz'AutoFileTests.testErrnoOnClosedWritablecCs|j�dS)N)rJ)rrrrr�testErrnoOnClosedFileno�sz%AutoFileTests.testErrnoOnClosedFilenocCs|j|j�d�dS)NF)rrM)rrrrr�testErrnoOnClosedIsatty�sz%AutoFileTests.testErrnoOnClosedIsattycCsUy|jj�Wntk
r%YnXttd�|_tj|jj��|jS)Nr5)rrr]rrrrJ)rrrr�
ReopenForRead�s
zAutoFileTests.ReopenForReadcCs|j�}|jd�dS)Nr%)rxr<)rrrrr�testErrnoOnClosedRead�sz#AutoFileTests.testErrnoOnClosedReadcCs|j�}|j�dS)N)rxrT)rrrrr�testErrnoOnClosedReadallsz&AutoFileTests.testErrnoOnClosedReadallcCs,|j�}tdd�}|j|�dS)Nr3r4rs
xxxxxxxxxx)rxrr6)rrr7rrr�testErrnoOnClosedReadinto	sz'AutoFileTests.testErrnoOnClosedReadintoN)'�__name__�
__module__�__qualname__rrr"r*r2r9r?r@rCrFrGrKrPr[rb�unittestZskipIfrrIrhrkrlrmrorprqrrrsrtrurvrwrxryrzr{rrrrrs@				'
	rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
dd��Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) �OtherFileTestscCsz�ttd�}|j|j�d�|j|j�d�|j|j�d�|j�ttd�}|j|j�d�|j|j�d�|j|j�d�|j�ttd�}|j|j�d�|j|j�d�|j|j�d�|j|j�d�|j�tj	dkr�ytdd�}Wnt
k
r`Yq�X|j|j�d�|j|j�d�tj	d	kr�d
tj	kr�tj	jd�r�|j|j�d�n|j|j�d�|j�nWdtj
t�XdS)Nr
FTr5za+�win32z/dev/ttyr7�darwinZbsd�sunos)rrrrRrSrQrrM�sys�platformr]�
startswithr�unlink)rrrrr�	testAbless>



zOtherFileTests.testAblescCsXxQdD]I}ytt|�}Wntk
r4YqX|j�|jd|�qWdS)NrL�aU�wU+�rw�rtz%r is an invalid file mode)rLr�r�r�r�)rrrNrr`)rr,rrrr�testInvalidModeStrings;s


z%OtherFileTests.testInvalidModeStringscCs�zlxeddddddddddddgD]9}tt|d
��}|j|j|d�WdQXq.WWdtjjt�r�tjt�nXdS)Nr
r+�wb+�rb+�w+br7�ab�ab+�a+br5r:�r+brr%)r
�wb)r�r�)r�r�)r�r�)r7r�)r�r�)r�r�)r�r�)r5�rb)r�r�)r�r�)r�r�)rrrr,r�path�existsr�)rZmodesrrrr�testModeStringsFs		%zOtherFileTests.testModeStringscCs0ttt�d�}|j�tjt�dS)Nr
)r�strrrrr�)rrrrr�testUnicodeOpenUs
zOtherFileTests.testUnicodeOpencCs�ytjd�}Wn#tk
r8|jdt�YnXt|d�}zI|jd�|j�ttd��}|j|j	�d�WdQXWdt
jt�XdS)N�asciizcould not encode %r to asciir
sabcr:)r�encode�UnicodeEncodeErrorZskipTestrrrrdrr<rr�)r�fnrrrr�
testBytesOpen[s


 zOtherFileTests.testBytesOpencCs?d}|jtt|d�|jttt|d�d�dS)NZfoobarr
r�)rr/rr)rZfn_with_NULrrr�testConstructorHandlesNULCharsjsz-OtherFileTests.testConstructorHandlesNULCharscCsd|jttd�|jttt��tjdkr`ddl}|jt|jt��ndS)Nrr�ri����)	rrNrr]rr�r��msvcrtZ
get_osfhandle)rr�rrr�
testInvalidFdos
zOtherFileTests.testInvalidFdcCsDddl}|jtt|jd�|jtt|jd�dS)Nrr%)�	_testcapirr/rZINT_MAXZINT_MIN)rr�rrr�testInvalidFd_overflowvsz%OtherFileTests.testInvalidFd_overflowcCs�d}ytt|�}Wnstk
r�}zS|jddkr|t|�}t|kse||kr||jd|�q|nWYdd}~XnX|j�|jd|�dS)NZqwertyrz&bad error message for invalid mode: %szno error for invalid mode: %s)rrrN�argsr�r`r)rZbad_moder�msg�srrr�testBadModeArgument}s*
z"OtherFileTests.testBadModeArgumentcCs�ttd�}|jtttd����|j|j�d�|jd�|j|j�d�|j|j	dt
j�d�|jd�|j|j�d�|j|j	dt
j�d�|j�dS)Nr
rr$rr&)
rrrrrXrrrrUr)�io�SEEK_ENDr)rrrrr�testTruncate�s

zOtherFileTests.testTruncatecs2�fdd�}z|�Wdtjt�XdS)Ncsttd�}|jttd���|j�ttd�}|jd�}|ttd��kr|�jd|�n|j�dkr��jd|j��n|j	�|j�dkr��jd|j��n|j�t
jjt�}|dkr�jd|�ndS)	Nr
�zr+r$z(Read on file opened for update failed %rzFile pos after read wrong %dz!File pos after ftruncate wrong %dz"File size after ftruncate wrong %d)
rrrrrrr<r`rrUrr��getsize)r�data�size)rrr�	bug801631�s 


z7OtherFileTests.testTruncateOnWindows.<locals>.bug801631)rr�r)rr�r)rr�testTruncateOnWindows�sz$OtherFileTests.testTruncateOnWindowscCs�z�ttd�}|jd�|j�ttd�}|jd�|j�ttd�}|j�}|j�|j|d�Wdytjt�WnYnXXdS)Nr+sspamr�seggsr:sspameggs)rdrrrr<rrr�)rr�drrr�
testAppend�s




zOtherFileTests.testAppendcCs|jttddd�dS)N�1r)rr/r)rrrr�testInvalidInit�szOtherFileTests.testInvalidInitcCs~tdd��i}|j|jg�|jttg�|j|jg�|jttdd�|j|jg�WdQXdS)N�quietTz/some/invalid/namer�)rr�warningsrr/rrN)rr
rrr�testWarnings�szOtherFileTests.testWarningscsnGdd�dt��G��fdd�dt��tjttj�}|j��|�tj|�dS)Nc@seZdZdS)z=OtherFileTests.testUnclosedFDOnException.<locals>.MyExceptionN)r|r}r~rrrr�MyException�sr�cs(eZdZ���fdd�Z�S)z:OtherFileTests.testUnclosedFDOnException.<locals>.MyFileIOcs4|dkr�d��nt�|�j||�S)NrIzblocked setting name)�super�__setattr__)rrI�value)r��MyFileIO�	__class__rrr��szFOtherFileTests.testUnclosedFDOnException.<locals>.MyFileIO.__setattr__)r|r}r~r�r)r�r�)r�rr��sr�)�	Exceptionrrrd�__file__rerr)rrfr)r�r�r�testUnclosedFDOnException�s
z(OtherFileTests.testUnclosedFDOnExceptionN)r|r}r~r�r�r�r�r�r�r�r	r�r�r�r�r�r�r�r�rrrrr�s*r�cCs;zttt�Wdtjjt�r6tjt�nXdS)N)rrr�rr�r�rr�rrrr�	test_main�sr��__main__)r�rr�r^rr�weakrefr�	functoolsrZtest.supportrrrrr	�collectionsr
�_iorrZTestCaserr�r�r|rrrr�<module>s(��