Your IP : 216.73.216.213


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



���]CJ�@s{ddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZddlmZddlZddlZGdd�d�ZGd	d
�d
eej�ZGdd�deej�ZGd
d�d�ZGdd�deej�ZGdd�deej�Zdd�Zedkrwe�dS)�N)�array)�proxy)�wraps)�TESTFN�check_warnings�run_unittest�make_bad_fd�cpython_only�	swap_attr)�UserListc@s5eZdZdd�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(�Zejejd)kd*�d+d,��Zd-d.�Zd/d0�Zed1d2��Zed3d4��Zed5d6��Z ed7d8��Z!ed9d:��Z"ed;d<��Z#ed=d>��Z$ed?d@��Z%edAdB��Z&edCdD��Z'dEdF�Z(edGdH��Z)edIdJ��Z*edKdL��Z+dMS)N�
AutoFileTestscCs|jtd�|_dS)N�w)�FileIOr�f)�self�r�0/opt/alt/python35/lib64/python3.5/test_fileio.py�setUpszAutoFileTests.setUpcCs'|jr|jj�tjt�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)r,r-)rrr,r-r�AttributeError�	TypeError�setattr)rr�attrrrr�testAttributes6s	
zAutoFileTests.testAttributescCs\tj}ttd�rBtj|jj��}t|d|�}|j|jj	|�dS)N�fstat�
st_blksize)
�io�DEFAULT_BUFFER_SIZE�hasattrrr3r�filenor r�_blksize)rZblksizeZfstrrr�testBlksizeBs
	zAutoFileTests.testBlksizec
Cs�|jjtddddg��|jj�td�}|jtd��}|j|�}WdQRX|j|d�|j|d�dS)	Nr%r'r�sabcdefgh�rs�efgh�)	rrrr�	bytearrayrr�readintor)rZbar�nrrr�testReadintoByteArrayLs"
z#AutoFileTests.testReadintoByteArraycCs|jjtddddg��|jj�ttd��}|jtd��}|j|�}WdQRX|j	|d�|j	|d�ttd��j
d	d
ddg�}|jtd��}|j|�}WdQRX|j	t|�d�|j	|d�dS)Nr%r'rr;sabcdefghr<s�efghr=�H�shape)rrrr�
memoryviewr>rrr?r�cast)r�mrr@rrr�_testReadintoMemoryviewVs"
'z%AutoFileTests._testReadintoMemoryviewcCs�|jjtddddg��|jj�tdd�}|jtd��}|j|�}WdQRX|j|tddddddd	d
dg��|j|d�td
d�}|jtd��}|j|�}WdQRX|j|td
dddddd	d
dg��|j|d�tdd�}|jtd��}|j|�}WdQRX|j|tdd��|j|d�dS)Nr%r'rr;�Bsabcdefghr<�e�f�g�hr=�b�Is�efgh���)	rrrrrrrr?r)r�arr@rrr�_testReadintoArrayfs""
11z AutoFileTests._testReadintoArraycCsaddg}|jj|�|jj�|jtd�|_|jj�}|j|d�dS)Ns123s456�rbs123456)r�
writelinesrrr�readr)r�l�bufrrr�testWritelinesList|s
z AutoFileTests.testWritelinesListcCsgtddg�}|jj|�|jj�|jtd�|_|jj�}|j|d�dS)Ns123s456rRs123456)rrrSrrrrTr)rrUrVrrr�testWritelinesUserList�s
z$AutoFileTests.testWritelinesUserListcCsX|jt|jjdddg�|jt|jjd�|jt|jjd�dS)Nr%r'��abc)rr/rrS)rrrr�testWritelinesError�s"z!AutoFileTests.testWritelinesErrorcCs�|jjd�|jj�|jtd�|_|j|jjd�d�|jjd�|j|jjd�d�|j|jj	d�ddg�dS)Ns
hi
bye
abcr<rshi
sbye
sabc)
rrrrrrrTr)�readline�	readlines)rrrr�test_none_args�s
zAutoFileTests.test_none_argscCs|jt|jjd�dS)NzHello!)rr/rr)rrrr�test_reject�szAutoFileTests.test_rejectcCs�|jt|j�d|j|jj|jjf�|j`|jt|j�d|j|jj�|jjf�|jj�|jt|j�d|jf�dS)Nz(<%s.FileIO name=%r mode=%r closefd=True>z&<%s.FileIO fd=%r mode=%r closefd=True>z<%s.FileIO [closed]>)r�reprr�
modulename�namer,r8r)rrrr�testRepr�s 	#
zAutoFileTests.testReprcCs|tjttj�}zR|j|ddd��3}|jt|�d|j|j|j	f�WdQRXWdtj
|�XdS)Nr<�closefdFz)<%s.FileIO name=%r mode=%r closefd=False>)r�openr�O_RDONLYrrr`rarbr,r)r�fdrrrr�testReprNoCloseFD�s%zAutoFileTests.testReprNoCloseFDcCsHt|jd|j��)|jt��t|j�WdQRXWdQRXdS)Nrb)r
rr�RuntimeErrorr`)rrrr�testRecursiveRepr�szAutoFileTests.testRecursiveReprcCs�|j}|j|j��|j|j�|jt|jd�|j�|j|j�|j	t
d�}|jt|jd�|j|j�|j�|j|j�dS)Nrr<�)
rZassertFalse�isattyr-r�
ValueErrorrTr�
assertTruerrr/r?)rrrrr�
testErrors�s	

zAutoFileTests.testErrorscCsCddddddddd	d
ddg}|jj�|j|jj�x0|D](}t|j|�}|jt|�qQW|jt|jj�|jt|jjt	d
��|jt|jj
�|jt|jj
d�|jt|jj�|jt|jjd�|jt|jj�|jt|jjd�dS)Nr8rl�seekable�readable�writablerT�readallr\r]r�truncate�flushr%r�)
rrrnr-r rrmr/r?r>r)rrS)r�methodsZ
methodname�methodrrr�testMethods�s 

zAutoFileTests.testMethodscCssy|jdd�WnKtk
ra}z+|j|jd�|j|jd�WYdd}~XnX|jd�dS)N�.r<rzShould have raised OSError)r�OSErrorZassertNotEqual�errnor�filename�fail)r�errr�testOpendir�s&zAutoFileTests.testOpendir�ntz&test only works on a POSIX-like systemc
Cshtjdtj�}|jt��}|j|d�WdQRXtj|�|j|jj	t	j
�dS)Nrzr<)rrerfrr{rrr�	exceptionr|ZEISDIR)rrg�cmrrr�
testOpenDirFD�s

zAutoFileTests.testOpenDirFDcs"t���fdd��}|S)Ncs[|j}tj|j��z�||�Wdy|jj�Wntk
rUYnXXdS)N)rrrr8r{)rr)�funcrr�wrapper�s	
z'AutoFileTests.ClosedFD.<locals>.wrapper)r)r�r�r)r�r�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)	rrrr8r{rr|�EBADFr~)rrr)r�rrr�s	)
z-AutoFileTests.ClosedFDRaises.<locals>.wrapper)r)r�r�r)r�r�ClosedFDRaisesszAutoFileTests.ClosedFDRaisescCs|j�dS)N)r)rrrrr�testErrnoOnCloseszAutoFileTests.testErrnoOnClosecCs|jd�dS)N�a)r)rrrrr�testErrnoOnClosedWritesz$AutoFileTests.testErrnoOnClosedWritecCs|jd�dS)Nr)r))rrrrr�testErrnoOnClosedSeeksz#AutoFileTests.testErrnoOnClosedSeekcCs|j�dS)N)r)rrrrr�testErrnoOnClosedTell!sz#AutoFileTests.testErrnoOnClosedTellcCs|jd�dS)Nr)rt)rrrrr�testErrnoOnClosedTruncate%sz'AutoFileTests.testErrnoOnClosedTruncatecCs|j�dS)N)rp)rrrrr�testErrnoOnClosedSeekable)sz'AutoFileTests.testErrnoOnClosedSeekablecCs|j�dS)N)rq)rrrrr�testErrnoOnClosedReadable-sz'AutoFileTests.testErrnoOnClosedReadablecCs|j�dS)N)rr)rrrrr�testErrnoOnClosedWritable1sz'AutoFileTests.testErrnoOnClosedWritablecCs|j�dS)N)r8)rrrrr�testErrnoOnClosedFileno5sz%AutoFileTests.testErrnoOnClosedFilenocCs|j|j�d�dS)NF)rrl)rrrrr�testErrnoOnClosedIsatty9sz%AutoFileTests.testErrnoOnClosedIsattycCsXy|jj�Wntk
r%YnX|jtd�|_tj|jj��|jS)Nr<)rrr{rrrr8)rrrr�
ReopenForRead=s
zAutoFileTests.ReopenForReadcCs|j�}|jd�dS)Nr%)r�rT)rrrrr�testErrnoOnClosedReadFsz#AutoFileTests.testErrnoOnClosedReadcCs|j�}|j�dS)N)r�rs)rrrrr�testErrnoOnClosedReadallKsz&AutoFileTests.testErrnoOnClosedReadallcCs,|j�}tdd�}|j|�dS)NrM�xrs
xxxxxxxxxx)r�rr?)rrrPrrr�testErrnoOnClosedReadintoPsz'AutoFileTests.testErrnoOnClosedReadintoN),�__name__�
__module__�__qualname__rrr"r*r2r:rArGrQrWrXr[r^r_rcrhrjroryr��unittestZskipIfrrbr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrsJ	

	
'
	rc@seZdZejZdZdS)�CAutoFileTests�_ioN)r�r�r�r�rrarrrrr�Vs	r�c@seZdZejZdZdS)�PyAutoFileTests�_pyioN)r�r�r�r�rrarrrrr�Zs	r�c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�OtherFileTestscCsz|jtd�}|j|j�d�|j|j�d�|j|j�d�|j�|jtd�}|j|j�d�|j|j�d�|j|j�d�|j�|jtd�}|j|j�d�|j|j�d�|j|j�d�|j|j�d�|j�tj	dkry|jdd�}Wnt
k
rlYn�X|j|j�d�|j|j�d�tj	d	kr�d
tj	kr�tj	jd
�r�|j|j�d�|j|j�d�|j�Wdtj
t�XdS)Nr
FTr<za+�win32z/dev/ttyrP�darwinZbsd�sunos�aix)r�r�)rrrrqrrrprrl�sys�platformr{�
startswithr�unlink)rrrrr�	testAblesas>



zOtherFileTests.testAblescCs[xTdD]L}y|jt|�}Wntk
r7YqX|j�|jd|�qWdS)Nrk�aU�wU+�rw�rtz%r is an invalid file mode)rkr�r�r�r�)rrrmrr~)rr,rrrr�testInvalidModeStrings�s


z%OtherFileTests.testInvalidModeStringscCs�zpxiddddddddddddgD]=}|jt|d
��}|j|j|d�WdQRXq.WWdtjjt�r�tjt�XdS)Nr
r+�wb+�rb+�w+brP�ab�ab+�a+br<rR�r+brr%)r
r+)r+r+)r�r�)r�r�)rPr�)r�r�)r�r�)r�r�)r<rR)rRrR)r�r�)r�r�)rrrr,r�path�existsr�)rZmodesrrrr�testModeStrings�s		&zOtherFileTests.testModeStringscCs3|jtt�d�}|j�tjt�dS)Nr
)r�strrrrr�)rrrrr�testUnicodeOpen�s
zOtherFileTests.testUnicodeOpencCs�ytjd�}Wn#tk
r8|jdt�YnX|j|d�}zJ|jd�|j�ttd��}|j|j	�d�WdQRXWdt
jt�XdS)N�asciizcould not encode %r to asciir
sabcrR)r�encode�UnicodeEncodeErrorZskipTestrrrrerrTrr�)r�fnrrrr�
testBytesOpen�s


!zOtherFileTests.testBytesOpencCsEd}|jt|j|d�|jt|jt|d�d�dS)Nzfoobarr
r�)rrmrr)rZfn_with_NULrrr�testConstructorHandlesNULChars�sz-OtherFileTests.testConstructorHandlesNULCharscCsg|jt|jd�|jt|jt��tjdkrcddl}|jt|jt��dS)Nrr�ri����)	rrmrr{rr�r��msvcrtZ
get_osfhandle)rr�rrr�
testInvalidFd�s
zOtherFileTests.testInvalidFdcCs�d}y|jt|�}Wnmtk
r�}zM|jddkryt|�}t|ksh||kry|jd|�WYdd}~XnX|j�|jd|�dS)NZqwertyrz&bad error message for invalid mode: %szno error for invalid mode: %s)rrrm�argsr�r~r)rZbad_moder�msg�srrr�testBadModeArgument�s$
z"OtherFileTests.testBadModeArgumentcCs�|jtd�}|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&)
rrrrr>rrrrtr)r5�SEEK_ENDr)rrrrr�testTruncate�s

zOtherFileTests.testTruncatecs2�fdd�}z|�Wdtjt�XdS)Ncs�jtd�}|jttd���|j��jtd�}|jd�}|ttd��kr�jd|�|j�dkr��jd|j��|j	�|j�dkr��jd|j��|j�t
jjt�}|dkr�jd|�dS)	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)
rrrrrrrTr~rrtrr��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�seggsrRsspameggs)rerrrrTrrr�)rr�drrr�
testAppend�s




zOtherFileTests.testAppendcCs |jt|jddd�dS)N�1r)rr/r)rrrr�testInvalidInitszOtherFileTests.testInvalidInitcCs�tdd��o}|j|jg�|jt|jg�|j|jg�|jt|jdd�|j|jg�WdQRXdS)N�quietTz/some/invalid/namer�)rr�warningsrr/rrm)rr
rrr�testWarningsszOtherFileTests.testWarningscsqGdd�dt��G��fdd�d|j��tjttj�}|j��|�tj|�dS)Nc@seZdZdS)z=OtherFileTests.testUnclosedFDOnException.<locals>.MyExceptionN)r�r�r�rrrr�MyExceptionsr�cs(eZdZ���fdd�Z�S)z:OtherFileTests.testUnclosedFDOnException.<locals>.MyFileIOcs1|dkr�d��t�|�j||�S)Nrbzblocked setting name)�super�__setattr__)rrb�value)r��MyFileIO�	__class__rrr�szFOtherFileTests.testUnclosedFDOnException.<locals>.MyFileIO.__setattr__)r�r�r�r�r)r�r�)r�rr�sr�)�	Exceptionrrre�__file__rfrr)rrgr)r�r�r�testUnclosedFDOnExceptions
"z(OtherFileTests.testUnclosedFDOnExceptionN)r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�_s*r�c@s1eZdZejZdZedd��ZdS)�COtherFileTestsr�cCsJddl}|jt|j|jd�|jt|j|jd�dS)Nrr%)�	_testcapirr/rZINT_MAXZINT_MIN)rr�rrr�testInvalidFd_overflow+sz&COtherFileTests.testInvalidFd_overflowN)r�r�r�r�rrar	r�rrrrr�'s	r�c@seZdZejZdZdS)�PyOtherFileTestsr�N)r�r�r�r�rrarrrrr�2s	r�cCs>zttttt�Wdtjjt�r9tj	t�XdS)N)
rr�r�r�r�rr�r�rr�rrrr�	test_main7s
	r��__main__)r�rr5r|r�r�weakrefr�	functoolsrZtest.supportrrrrr	r
�collectionsrr�r�rZTestCaser�r�r�r�r�r�r�rrrr�<module>s*.�C�