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_fileinput.cpython-35.opt-1.pyc



��Yf��@s�dZddlZddlZddlZddlZddlZddlZddlZyddlZWne	k
r�dZYnXyddl
Z
Wne	k
r�dZ
YnXddlmZm
Z
ddlmZmZddlmZmZmZmZddlmZddlmZdd	d
�Zdd�ZGd
d�d�ZGdd�dej�ZGdd�d�ZGdd�dej�ZGdd�d�ZGdd�dej�Z Gdd�de �Z!Gdd�de �Z"Gdd�de �Z#Gdd �d e �Z$Gd!d"�d"e �Z%Gd#d$�d$e �Z&Gd%d&�d&e �Z'Gd'd(�d(e �Z(Gd)d*�d*e �Z)Gd+d,�d,�Z*Gd-d.�d.ej�Z+Gd/d0�d0ej�Z,e-d1kr�ej.�dS)2z,
Tests for fileinput module.
Nick Mathewson
�N)�BytesIO�StringIO)�	FileInput�hook_encoded)�verbose�TESTFN�run_unittest�check_warnings)�unlink)�mock�wcCsKtt|�}t||�}x|D]}|j|�q&W|j�|S)N)r�str�open�write�close)�i�lines�mode�name�f�line�r�8/opt/alt/python35/lib64/python3.5/test/test_fileinput.py�writeTmp$s

rcGs%x|D]}|rt|�qWdS)N)�safe_unlink)�namesrrrr�remove_tempfiles,s
rc@sdeZdZdd�Zedd��Zdd�Zddd	�Zddd�Zd
d�Z	dS)�
LineReadercCs
g|_dS)N)�
_linesread)�selfrrr�__init__3szLineReader.__init__cCs&z|jdd�SWdg|_XdS)N)r)rrrr�	linesread6szLineReader.linesreadcCst|jd��|_|S)NT)�iter�
splitlines�it)r�filenamerrrr�openhook=szLineReader.openhookNcCs&t|jd�}|jj|�|S)N�)�nextr$r�append)r�sizerrrr�readlineAszLineReader.readline�cCsZg}d}xG|j�}|s%|S|j|�|t|�7}||kr|SqWdS)Nr)r+r)�len)rZhintrr*rrrr�	readlinesFs
zLineReader.readlinescCsdS)Nr)rrrrrRszLineReader.close���)
�__name__�
__module__�__qualname__r �propertyr!r&r+r.rrrrrr1src@s.eZdZdd�Zdddd�ZdS)�BufferSizesTestscCs�x�dD]�\}}d}}}}z�tddd�td�D��}tddd�td	�D��}td
dd�td�D��}td
dd�td�D��}|j||||||�Wdt||||�XqWdS)Nrr,�cSsg|]}d|d�qS)zLine %s of file 1
r,r)�.0rrrr�
<listcomp>[s	z6BufferSizesTests.test_buffer_sizes.<locals>.<listcomp>��cSsg|]}d|d�qS)zLine %s of file 2
r,r)r6rrrrr7\s	�
�cSsg|]}d|d�qS)zLine %s of file 3
r,r)r6rrrrr7]s	��cSsg|]}d|d�qS)zLine %s of file 4
r,r)r6rrrrr7^s	�rr�r,r5)r>r?)r�range�buffer_size_testr)r�round�bs�t1�t2�t3�t4rrr�test_buffer_sizesVs"""" z"BufferSizesTests.test_buffer_sizesrcCs�tjd�}d|d}tr;td|d|f�td||||fd|�}	t|	�}
|	j�|jt|
�d�|j|
d	d
�|j|
dd�|j|	j	�d�|j|	j
�|�tr�td
|d|f�td||||fd|�}	d}x"|rE|dkrE|	j�}q$W|j|	j
�|�|j|	j	�d�|j|	j�d�|j
|	j��|j
|	j��tr�td|d|f�|	j�|j|	j�d�|j|	j	�d�|	j�tr*td|d|f�td||||dfd|�}	tj}zitd�t_t|	�}
|jt|
�d�|j|
dd�|j|	j
�d�|	j�Wd|t_Xtr�td|d	|f�td||||fd|�}	|j|	j	�d�|j|	j
�d�|	j�|j|	j	�d�|j|	j
�d�tr�td|d|f�tj}
zftd||||fd dd|�}	x.|	D]&}|dd"�j�}t|�q�W|	j�Wd|
t_Xtd||||fd|�}	xp|	D]h}|j|d#d!�|j|dd$��}|j|d�|jt|jd��|	j��q0W|	j�dS)%NzLINE (\d+) OF FILE (\d+)r,�z%s. Simple iteration (bs=%s)r�files�bufsize�r=zLine 5 of file 1
r5zLine 1 of file 4
z%s. Status variables (bs=%s)�xzLine 6 of file 2
�z%s. Nextfile (bs=%s)r9zLine 1 of file 3
�z%s. Stdin (bs=%s)r;�-z Line 1 of stdin
Line 2 of stdin
�!� zLine 2 of stdin
z<stdin>z%s. Boundary conditions (bs=%s)z%s. Inplace (bs=%s)r<�inplace�
r/r/r/)�re�compiler�printr�listr�assertEqualr-�linenor%r+�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)rrDrErFrGrCrBZpat�start�fir�sZ	savestdinZ
savestdoutr�mrrrrAcs�!
!

$	
!
	'

!
)z!BufferSizesTests.buffer_size_testN)r0r1r2rHrArrrrr4Us
r4c@s(eZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS)NF)�exception_type�invoked)rrmrrrr �s	zUnconditionallyRaise.__init__cOsd|_|j��dS)NT)rnrm)r�args�kwargsrrr�__call__�s	zUnconditionallyRaise.__call__N)r0r1r2r rqrrrrrl�srlc@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"�Zejeed#�d$�d%d&��Zd'd(�Zd)d*�Zd+d,�Zd-S).�FileInputTestscCsWd}}}}z*tddg�}tddg�}tddg�}tddg�}td||||f�}|j�}|j|d�|j|j�d�|j|j�d�|j|j�|�|j�}|j|�|j|j�d�|j|j�d�|j|j�|�|j�Wdt	||||�XdS)	Nr,r'r9r;zThe only line there is.
r=rJr)
rrr+rYrZr[r%r\rr)rrDrErFrGrirrrr�test_zero_byte_files�s&
z#FileInputTests.test_zero_byte_filescCs�d}}z�tddg�}tddg�}td||f�}t|�}|j|dddd	d
dg�|j|j�d�|j|j�d
�Wdt||�XdS)Nr,zA
B
Cr9zD
E
FrJzA
zB
�CzD
zE
�Fr;rI)rrrXrYr[rZr)rrDrErirrrr�%test_files_that_dont_end_with_newline�s
"z4FileInputTests.test_files_that_dont_end_with_newlinecCs�d}}z�tddg�}tddg�}td||f�}|j|j�d�t|�}|j|j�d�|j�|j|j�d�t|�}|j|j�d	�Wdt||�XdS)
Nr,zA
Br9zC
DrJr/r/r/r/)	rrrY�filenor(rer_rXr)rrDrErirrrr�test_fileno�s

zFileInputTests.test_filenoc"Cs�y tdd�}|jd�Wntk
r4YnXd}z�tddgdd�}tdtf��td|dd	�}WdQRXtdtf��t|�}WdQRX|j|d
ddd
g�Wdt|�XdS)Nrrz-FileInput should reject invalid mode argumentr,sA
B
C
D�wbr'rJ�UzA
zB
zC
�D)	r�fail�
ValueErrorrr	�DeprecationWarningrXrYr)rrirDrrrr�test_opening_mode�s
 z FileInputTests.test_opening_modecCsctjd��M}td�|_tddgdd�}t|�}|j|dg�WdQRXdS)Nz	sys.stdinsspam, bacon, sausage, and spamrJrPr�rb)rZpatchr�bufferrrXrY)rZm_stdinrirrrr�test_stdin_binary_modes
z%FileInputTests.test_stdin_binary_modecCs}tj}zctd�t_|jttjd��tddgdd�}t|�}|j|dg�Wd|t_XdS)Nsspam, bacon, sausage, and spamr�rJrPrr�)r`rarr\�hasattrrrXrY)rZ
orig_stdinrirrrr�test_detached_stdin_binary_modes	z.FileInputTests.test_detached_stdin_binary_modecCs�y,tddddd��}|jd�Wntk
r@YnXy tdd�}|jd�Wntk
ruYnXGdd	�d	�}tdd
g�}|jt|�|�}t|gd|��}|j�WdQRX|j|jd�dS)NrSr,r&cSsdS)Nr)rrkrrr�<lambda>%sz7FileInputTests.test_file_opening_hook.<locals>.<lambda>zGFileInput should raise if both inplace and openhook arguments are givenz2FileInput should check openhook for being callablec@s(eZdZdd�Zdd�ZdS)z=FileInputTests.test_file_opening_hook.<locals>.CustomOpenHookcSs
d|_dS)NF)rn)rrrrr 1szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�S)NT)rnr)rrorrrrq3s	zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__N)r0r1r2r rqrrrr�CustomOpenHook0sr�rTzopenhook not invoked)	rr|r}r�
addCleanuprr+�
assertTruern)rrir��tZcustom_open_hookrrr�test_file_opening_hook"s"

	z%FileInputTests.test_file_opening_hookc Cs2ttd��2}|jd�|jdd�|jd�WdQRX|jtt�tdtdtd����}yF|j|j�d	�|j|j�d
�|j|j�d�Wnt	k
r�|j
d�YnX|jt	��t|�WdQRX|j|j�d
�|j|j�d
�WdQRXdS)NrysA
B
C
s
123456789
i�s�rJr&�asciizA
zB
zC
zRead to end of filer')
rrrr�rrrrYr+�UnicodeDecodeErrorr|�assertRaisesrX)rrrirrr�
test_readline>s"

zFileInputTests.test_readlinecCs�ttd��}|jd�WdQRX|jtt�tdtdd��u}|j|j�d�|j|j�d�|j|j�d�|j|j�d	�|j|j�d	�WdQRXdS)
NrysA
B
C
DrJrr�sA
sB
sC
D�)rrrr�rrrYr+)rrrirrr�test_readline_binary_modeUsz(FileInputTests.test_readline_binary_modecCs�z�tddg�}tddg�}td||f��}t|�}WdQRX|j|dddd	d
dg�|j|j�d�|j|j�d
�|j|jf�Wdt||�XdS)Nr,zA
B
Cr9zD
E
FrJzA
zB
rtzD
zE
rur;rI)rrrXrYr[rZ�_filesr)rrDrErirrrr�test_context_managerbs"z#FileInputTests.test_context_managercCsszay5tddg�}td|��
}t�WdQRXWn%tk
r_|j|jf�YnXWdt|�XdS)Nr,r'rJ)rr�OSErrorrYr�r)rrDrirrr�test_close_on_exceptionos
z&FileInputTests.test_close_on_exceptionc
Cs0tdg��}|j|jd�WdQRXdS)NrJrP)rP)rrYr�)rrirrr�.test_empty_files_list_specified_to_constructorysz=FileInputTests.test_empty_files_list_specified_to_constructorc
Csytdddg�}|jt|�td|g��;}|d}|j|d�|d}|j|d�WdQRXdS)zNTests invoking FileInput.__getitem__() with the current
           line numberr,zline1
zline2
rJrN)rr�rrrY)rr�riZretval1Zretval2rrr�test__getitem__}s

zFileInputTests.test__getitem__cCs|tdddg�}|jt|�td|g��(}|jt��}|dWdQRXWdQRX|j|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberr,zline1
zline2
rJN�accessing lines out of order)r�)	rr�rrr��RuntimeErrorrY�	exceptionro)rr�ri�cmrrr�test__getitem__invalid_key�sz)FileInputTests.test__getitem__invalid_keycCsvtdg�}|jt|�td|g��(}|jt��}|dWdQRXWdQRX|j|jjd�dS)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputr,rJrN�end of input reached)r�)	rr�rrr��
IndexErrorrYr�ro)rr�rir�rrr�test__getitem__eof�sz!FileInputTests.test__getitem__eofcCs�tj}tt�}zetddg�}|jt|�td|gdd��$}t|�|t_|j	�WdQRXWd|t_X|j
|jd�dS)z�Tests invoking FileInput.nextfile() when the attempt to delete
           the backup file would raise OSError.  This error is expected to be
           silently ignoredr,rTrJrSTNzos.unlink() was not invoked)�osr
rlr�rr�rrr(r_r�rn)rZos_unlink_origZos_unlink_replacementr�rirrr�%test_nextfile_oserror_deleting_backup�s	
	
z4FileInputTests.test_nextfile_oserror_deleting_backupcCs�tj}tt�}z[tddg�}|jt|�td|gdd��}|t_|j�WdQRXWd|t_X|j	|j
d�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.r,rTrJrSTNzos.fstat() was not invoked)r��fstatrlr�rr�rrr+r�rn)rZ
os_fstat_origZos_fstat_replacementr�rirrr�%test_readline_os_fstat_raises_OSError�s		
z4FileInputTests.test_readline_os_fstat_raises_OSError�chmodzos.chmod does not existcCs�tj}tt�}z[tddg�}|jt|�td|gdd��}|t_|j�WdQRXWd|t_X|j	|j
d�dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.r,rTrJrSTNzos.fstat() was not invoked)r�r�rlr�rr�rrr+r�rn)rZ
os_chmod_origZos_chmod_replacementr�rirrr�%test_readline_os_chmod_raises_OSError�s		
z4FileInputTests.test_readline_os_chmod_raises_OSErrorcCs�Gdd�dt�}|�}tddg�}|jt|�td|g��6}|j}z||_|j�}Wd||_XWdQRX|j|jd�|j	|dd�dS)	Nc@s(eZdZdd�Zdd�ZdS)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcSstj|t�dS)N)rlr r})rrrrr �szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|j�dS)N)rq)rrrrrw�szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)r0r1r2r rwrrrr�FilenoRaisesValueError�sr�r,rTrJz_file.fileno() was not invokedzfileno() should return -1r/)
rlrr�rr�_filerwr�rnrY)rr�Z unconditionally_raise_ValueErrorr�riZfile_backup�resultrrr�"test_fileno_when_ValueError_raised�s			z1FileInputTests.test_fileno_when_ValueError_raisedcCs$t�}tdddgd|j���}|j|jg�|j|j�d�|j|jdg�|j|j�d�|j|jdg�|j|j�d�|j|jddg�|j|j�d�|j|jdg�|j|j�d�|j|jg�WdQRXdS)NrJzline1
line2zline3
r&zline1
�line2r')rrr&rYr!r+)r�srcrirrr�test_readline_buffering�s	z&FileInputTests.test_readline_bufferingcCst�}tdddgd|j���}|j|jg�|jt|�d�|j|jdg�|jt|�d�|j|jdg�|jt|�d�|j|jddg�|jtt|�|j|jdg�|jtt|�|j|jg�WdQRXdS)NrJzline1
line2zline3
r&zline1
r�r')rrr&rYr!r(r��
StopIteration)rr�rirrr�test_iteration_bufferings	z'FileInputTests.test_iteration_bufferingN)r0r1r2rsrvrxrr�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfr�r�r�r�r�r�rrrrrr�s*




(rrc@s�eZdZdZdddddddd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�ZdS)�
MockFileInputzDA class that mocks out fileinput.FileInput for use during unit testsNFr'r�rcCsd||_||_||_||_||_||_d|_tjdd��|_	i|_
dS)NcSsdS)Nrrrrrrr�sz(MockFileInput.__init__.<locals>.<lambda>)rJrS�backuprKrr&r��collections�defaultdict�invocation_counts�
return_values)rrJrSr�rKrr&rrrr s							zMockFileInput.__init__cCs|jdd7<dS)Nrr,)r�)rrrrrszMockFileInput.closecCs|jdd7<|jdS)Nr_r,)r�r�)rrrrr_"szMockFileInput.nextfilecCs|jdd7<|jdS)Nr%r,)r�r�)rrrrr%&szMockFileInput.filenamecCs|jdd7<|jdS)NrZr,)r�r�)rrrrrZ*szMockFileInput.linenocCs|jdd7<|jdS)Nr[r,)r�r�)rrrrr[.szMockFileInput.filelinenocCs|jdd7<|jdS)Nrwr,)r�r�)rrrrrw2szMockFileInput.filenocCs|jdd7<|jdS)Nr]r,)r�r�)rrrrr]6szMockFileInput.isfirstlinecCs|jdd7<|jdS)Nr^r,)r�r�)rrrrr^:szMockFileInput.isstdin)
r0r1r2�__doc__r rr_r%rZr[rwr]r^rrrrr�sr�c@s:eZdZdZdd�Zdd�Zdd�ZdS)	�BaseFileInputGlobalMethodsTestzQBase class for unit tests for the global function of
       the fileinput module.cCs%tj|_tj|_tt_dS)N)�	fileinput�_state�_orig_stater�_orig_FileInputr�)rrrr�setUpBsz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dS)N)r�r�rr�r�)rrrr�tearDownGsz'BaseFileInputGlobalMethodsTest.tearDowncCsC|j|}|j|d|�t|j�}|j|d�dS)Nr,)r�rYr-)rZmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocationKs
z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)r0r1r2r�r�r�r�rrrrr�>sr�c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_fileinput_inputz Unit tests for fileinput.input()cCsqt�}t�|_|t_|jt��}tj�WdQRX|jd|j	j
�|j|tjd�dS)z�Tests invoking fileinput.input() when fileinput._state is not None
           and its _file attribute is also not None.  Expect RuntimeError to
           be raised with a meaningful error message and for fileinput._state
           to *not* be modified.N�input() already activezfileinput._state)r�)r��objectr�r�r�r�r��inputrYr�ro�assertIs)r�instancer�rrr�1test_state_is_not_None_and_state_file_is_not_NoneVs		zFTest_fileinput_input.test_state_is_not_None_and_state_file_is_not_NonecCs)t�}d|_|t_|j�dS)a\Tests invoking fileinput.input() when fileinput._state is not None
           but its _file attribute *is* None.  Expect it to create and return
           a new fileinput.FileInput object with all method parameters passed
           explicitly to the __init__() method; also ensure that
           fileinput._state is set to the returned instance.N)r�r�r�r��do_test_call_input)rr�rrr�-test_state_is_not_None_and_state_file_is_Nonecs			zBTest_fileinput_input.test_state_is_not_None_and_state_file_is_NonecCsdt_|j�dS)a4Tests invoking fileinput.input() when fileinput._state is None
           Expect it to create and return a new fileinput.FileInput object
           with all method parameters passed explicitly to the __init__()
           method; also ensure that fileinput._state is set to the returned
           instance.N)r�r�r�)rrrr�test_state_is_Nonens	z'Test_fileinput_input.test_state_is_Nonec
Cst�}t�}t�}t�}t�}t�}tjd|d|d|d|d|d|�}|j|tjd�|j||jd�|j||jd�|j||jd�|j||jd�|j||j	d�|j||j
d�dS)	aTests that fileinput.input() creates a new fileinput.FileInput
           object, passing the given parameters unmodified to
           fileinput.FileInput.__init__().  Note that this test depends on the
           monkey patching of fileinput.FileInput done by setUp().rJrSr�rKrr&zfileinput._stateN)r�r�r�r�r�rJrSr�rKrr&)rrJrSr�rKrr&r�rrrr�ws 						z'Test_fileinput_input.do_test_call_inputN)r0r1r2r�r�r�r�r�rrrrr�Ss

	r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_closez Unit tests for fileinput.close()cCs'dt_tj�|jtj�dS)zPTests that fileinput.close() does nothing if fileinput._state
           is NoneN)r�r�r�assertIsNone)rrrrr��s	
z'Test_fileinput_close.test_state_is_NonecCs@t�}|t_tj�|j|d�|jtj�dS)z`Tests that fileinput.close() invokes close() on fileinput._state
           and sets _state=NonerN)r�r�r�rr�r�)rr�rrr�test_state_is_not_None�s
		
z+Test_fileinput_close.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr��sr�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.nextfile() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�r_rYr�ror�)rr�rrrr��s
	z*Test_fileinput_nextfile.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)aTests fileinput.nextfile() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.nextfile() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.r_N)r�r�r�r�r�r_r�r�)rZnextfile_retvalr��retvalrrrr��s		
	z.Test_fileinput_nextfile.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenamez#Unit tests for fileinput.filename()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.filename() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�r%rYr�ror�)rr�rrrr��s
	z*Test_fileinput_filename.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)aTests fileinput.filename() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.filename() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.r%N)r�r�r�r�r�r%r�r�)rZfilename_retvalr�r�rrrr��s		
	z.Test_fileinput_filename.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.lineno() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�rZrYr�ror�)rr�rrrr��s
	z(Test_fileinput_lineno.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)z�Tests fileinput.lineno() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.lineno() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.rZN)r�r�r�r�r�rZr�r�)rZ
lineno_retvalr�r�rrrr��s		
	z,Test_fileinput_lineno.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.filelineno() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�r[rYr�ror�)rr�rrrr��s
	z,Test_fileinput_filelineno.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)aTests fileinput.filelineno() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.filelineno() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.r[N)r�r�r�r�r�r[r�r�)rZfilelineno_retvalr�r�rrrr�s		
	z0Test_fileinput_filelineno.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.fileno() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�rwrYr�ror�)rr�rrrr�s
	z(Test_fileinput_fileno.test_state_is_NonecCstt�}t�}||jd<||_|t_tj�}|j|d�|j||�|jtj|�dS)z�Tests fileinput.fileno() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.fileno() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.rwN)	r�r�r��
fileno_retvalr�r�rwr�r�)rr�r�r�rrrr� s		
		z,Test_fileinput_fileno.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr�s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.isfirstline() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�r]rYr�ror�)rr�rrrr�2s
	z-Test_fileinput_isfirstline.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)aTests fileinput.isfirstline() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.isfirstline() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.r]N)r�r�r�r�r�r]r�r�)rZisfirstline_retvalr�r�rrrr�<s		
	z1Test_fileinput_isfirstline.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr�/s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()c
CsVdt_|jt��}tj�WdQRX|jd|jj�|jtj�dS)z�Tests fileinput.isstdin() when fileinput._state is None.
           Ensure that it raises RuntimeError with a meaningful error message
           and does not modify fileinput._stateN�no active input())r�)	r�r�r�r�r^rYr�ror�)rr�rrrr�Ms
	z)Test_fileinput_isstdin.test_state_is_NonecCskt�}t�}||jd<|t_tj�}|j|d�|j||�|jtj|�dS)z�Tests fileinput.isstdin() when fileinput._state is not None.
           Ensure that it invokes fileinput._state.isstdin() exactly once,
           returns whatever it returns, and does not modify fileinput._state
           to point to a different object.r^N)r�r�r�r�r�r^r�r�)rZisstdin_retvalr�r�rrrr�Ws		
	z-Test_fileinput_isstdin.test_state_is_not_NoneN)r0r1r2r�r�r�rrrrr�Js
r�c@s(eZdZdd�Zdd�ZdS)�InvocationRecordercCs
d|_dS)Nr)�invocation_count)rrrrr fszInvocationRecorder.__init__cOs"|jd7_||f|_dS)Nr,)r��last_invocation)rrorprrrrqhszInvocationRecorder.__call__N)r0r1r2r rqrrrrr�esr�c@s�eZdZdZdd�Zdd�Zdd�Zeje	d�d	d
��Z
ejed�dd
��Zdd�Z
dd�Zdd�Zdd�Zedd��ZdS)�Test_hook_compressedz*Unit tests for fileinput.hook_compressed()cCst�|_dS)N)r��	fake_open)rrrrr�oszTest_hook_compressed.setUpcCs|jdd�dS)Nr'r,)�do_test_use_builtin_open)rrrr�test_empty_stringrsz&Test_hook_compressed.test_empty_stringcCs|jdd�dS)NZabcdr9)r�)rrrr�test_no_extusz Test_hook_compressed.test_no_extzRequires gzip and zlibcCsntj}|jt_ztjdd�}Wd|t_X|j|jjd�|j|jjdif�dS)N�test.gzr;r,)r�r;)�gziprr�r��hook_compressedrYr�r�)r�
original_openr�rrr�test_gz_ext_fakexs	
z%Test_hook_compressed.test_gz_ext_fakezRequires bz2cCsntj}|jt_ztjdd�}Wd|t_X|j|jjd�|j|jjdif�dS)N�test.bz2r=r,)r�r=)�bz2ZBZ2Filer�r�r�rYr�r�)rr�r�rrr�test_bz2_ext_fake�s	
z&Test_hook_compressed.test_bz2_ext_fakecCs|jdd�dS)Nz	abcd.blahr<)r�)rrrr�
test_blah_ext�sz"Test_hook_compressed.test_blah_extcCs|jdd�dS)Nzabcd.GzrI)r�)rrrr�test_gz_ext_builtin�sz(Test_hook_compressed.test_gz_ext_builtincCs|jdd�dS)Nzabcd.Bz2�)r�)rrrr�test_bz2_ext_builtin�sz)Test_hook_compressed.test_bz2_ext_builtincCsu|j|j�}ztj||�}Wd|j|�X|j|jjd�|j|jj||fif�dS)Nr,)�replace_builtin_openr�r�r�rYr�r�)rr%rr�r�rrrr��sz-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|S)N)�builtinsr)Z
new_open_funcr�rrrr��s		z)Test_hook_compressed.replace_builtin_openN)r0r1r2r�r�r�r�r�Z
skipUnlessr�r�r�r�r�r�r�r��staticmethodr�rrrrr�lsr�c@s.eZdZdZdd�Zdd�ZdS)�Test_hook_encodedz'Unit tests for fileinput.hook_encoded()c
Cs�t�}tj|�}t�}tj}|t_z%t�}t�}|||�}Wd|t_X|j|jd�|j\}}	|j	|d|�|j	|d|�|j	|	j
d�|�|j|	�dS)Nr,r�encoding)r�r�rr�r�rrYr�r�r��popr\)
rr�r�r�r�r%rZopen_resultrorprrr�test�s 						
zTest_hook_encoded.testc"s�ttd��}|jd�WdQRX�jtt��fdd�}|ddddd	g��jt��|d
dddd	g�WdQRX�jt��|ddddd	g�WdQRX�jt��|ddd
dd	g�WdQRXdS)Nrys
A
B
C
D+IKw-c
sKtdtd|dtd���}t|�}WdQRX�j||�dS)NrJrr&zutf-7)rrrrXrY)rZexpected_linesrir)rrr�check�sz+Test_hook_encoded.test_modes.<locals>.checkr�zA
zB
zC
uD€ZrUrzr�zB
zC
)	rrrr�rZassertWarnsr~r�r})rrr�r)rr�
test_modes�s  zTest_hook_encoded.test_modesN)r0r1r2r�r�r�rrrrr��sr��__main__)/r�r�r`rUr�r�r�r�r��ImportErrorr��iorrrrZtest.supportrrrr	r
rrrrrZTestCaser4rlrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r0�mainrrrr�<module>sV

"	$[�Y.A>.