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

�
g f���@s�dZddlZddlZddlZddlZddlZddlZddlZyddlZWne	k
r�dZYnXyddl
Z
Wne	k
r�dZ
YnXddlmZm
Z
ddlmZmZddlmZmZmZmZddlmZddlmZdd	d
�Zdd�ZGd
d�dej�ZGdd�d�ZGdd�dej�ZGdd�d�ZGdd�dej�ZGdd�de�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*�Z)Gd+d,�d,ej�Z*Gd-d.�d.ej�Z+e,d/kr�ej-�ndS)0z,
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/python34/lib64/python3.4/test/test_fileinput.py�writeTmp$s

rcGs(x!|D]}|rt|�qqWdS)N)�safe_unlink)�namesrrrr�remove_tempfiles,s
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)Nr��cSsg|]}d|d�qS)zLine %s of file 1
rr)�.0rrrr�
<listcomp>7s	z6BufferSizesTests.test_buffer_sizes.<locals>.<listcomp>��cSsg|]}d|d�qS)zLine %s of file 2
rr)r rrrrr!8s	�
�cSsg|]}d|d�qS)zLine %s of file 3
rr)r rrrrr!9s	��cSsg|]}d|d�qS)zLine %s of file 4
rr)r rrrrr!:s	�rr�rr)r(r))r�range�buffer_size_testr)�self�round�bs�t1�t2�t3�t4rrr�test_buffer_sizes2s"""" z"BufferSizesTests.test_buffer_sizesrcCs�tjd�}d|d}tr>td|d|f�ntd||||fd|�}	t|	�}
|	j�|jt|
�d�|j|
d	d
�|j|
dd�|j|	j	�d�|j|	j
�|�trtd
|d|f�ntd||||fd|�}	d}x"|rK|dkrK|	j�}q*W|j|	j
�|�|j|	j	�d�|j|	j�d�|j
|	j��|j
|	j��tr�td|d|f�n|	j�|j|	j�d�|j|	j	�d�|	j�tr6td|d|f�ntd||||dfd|�}	tj}zitd�t_t|	�}
|jt|
�d�|j|
dd�|j|	j
�d�|	j�Wd|t_Xtr�td|d	|f�ntd||||fd|�}	|j|	j	�d�|j|	j
�d�|	j�|j|	j	�d�|j|	j
�d�tr�td|d|f�ntj}
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��qBW|	j�dS)%NzLINE (\d+) OF FILE (\d+)r�z%s. Simple iteration (bs=%s)r�files�bufsize�r'zLine 5 of file 1
rzLine 1 of file 4
z%s. Status variables (bs=%s)�xzLine 6 of file 2
�z%s. Nextfile (bs=%s)r#zLine 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@)�re�compiler�printr�listr�assertEqual�len�lineno�filename�readline�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)r,r/r0r1r2r.r-Zpat�start�fir�sZ	savestdinZ
savestdoutr�mrrrr+?s�!
!

$	
!
	'

!
)z!BufferSizesTests.buffer_size_testN)�__name__�
__module__�__qualname__r3r+rrrrr1s
rc@s(eZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS)NF)�exception_type�invoked)r,r_rrr�__init__�s	zUnconditionallyRaise.__init__cOsd|_|j��dS)NT)r`r_)r,�args�kwargsrrr�__call__�s	zUnconditionallyRaise.__call__N)r[r\r]rardrrrrr^�sr^c@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zejeed!�d"�d#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#r%zThe only line there is.
r'r5r)
rrrIrErGrJrHrKrr)r,r/r0r1r2rXrrrr�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)NrzA
B
Cr#zD
E
Fr5zA
zB
�CzD
zE
�Fr%r4)rrrDrErJrGr)r,r/r0rXrrrr�%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)
NrzA
Br#zC
Dr5r@r@r@r@)	rrrE�fileno�nextrTrNrDr)r,r/r0rXrrrr�test_fileno�s

zFileInputTests.test_filenoc Cs�y tdd�}|jd�Wntk
r4YnXd}z�tddgdd�}tdtf��td|dd	�}WdQXtdtf��t|�}WdQX|j|d
ddd
g�Wdt|�XdS)Nrrz-FileInput should reject invalid mode argumentrsA
B
C
D�wbrfr5�UzA
zB
zC
�D)	r�fail�
ValueErrorrr	�DeprecationWarningrDrEr)r,rXr/rrrr�test_opening_mode�s
 z FileInputTests.test_opening_modecCsbtjd��M}td�|_tddgdd�}t|�}|j|dg�WdQXdS)Nz	sys.stdinsspam, bacon, sausage, and spamr5r;r�rb)rZpatchr�bufferrrDrE)r,Zm_stdinrXrrrr�test_stdin_binary_mode�s
z%FileInputTests.test_stdin_binary_modecCs�y,tddddd��}|jd�Wntk
r@YnXy tdd�}|jd�Wntk
ruYnXGdd	�d	�}tdd
g�}|jt|�|�}t|gd|��}|j�WdQX|j|jd�dS)Nr>r�openhookcSsdS)Nr)rrZrrr�<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)r`)r,rrrraszFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�S)NT)r`r)r,rbrrrrds	zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__N)r[r\r]rardrrrr�CustomOpenHooksrzr?zopenhook not invoked)	rrqrrr�
addCleanuprrI�
assertTruer`)r,rXrz�tZcustom_open_hookrrr�test_file_opening_hook�s"

	z%FileInputTests.test_file_opening_hookcCs5ttd��2}|jd�|jdd�|jd�WdQX|jtt�tdtdtd�d	d
���}yF|j|j�d�|j|j�d�|j|j�d
�Wnt	k
r�|j
d�YnX|jt	��t|�WdQX|j|j�d�|j|j�d�WdQXdS)NrnsA
B
C
s
123456789
i�s�r5rx�asciir6�zA
zB
zC
zRead to end of filerf)
rrrr{rrrrErI�UnicodeDecodeErrorrq�assertRaisesrD)r,rrXrrr�
test_readlines"

zFileInputTests.test_readlinecCs�ttd��}|jd�WdQX|jtt�tdtdd��u}|j|j�d�|j|j�d�|j|j�d�|j|j�d	�|j|j�d	�WdQXdS)
NrnsA
B
C
Dr5rrusA
sB
sC
D�)rrrr{rrrErI)r,rrXrrr�test_readline_binary_mode&sz(FileInputTests.test_readline_binary_modecCs�z�tddg�}tddg�}td||f��}t|�}WdQX|j|dddd	d
dg�|j|j�d�|j|j�d
�|j|jf�Wdt||�XdS)NrzA
B
Cr#zD
E
Fr5zA
zB
rhzD
zE
rir%r4)rrrDrErJrG�_filesr)r,r/r0rXrrrr�test_context_manager3s"z#FileInputTests.test_context_managercCsrz`y4tddg�}td|��
}t�WdQXWn%tk
r^|j|jf�YnXWdt|�XdS)Nrrfr5)rr�OSErrorrEr�r)r,r/rXrrr�test_close_on_exception@s
z&FileInputTests.test_close_on_exceptionc
Cs/tdg��}|j|jd�WdQXdS)Nr5r;)r;)rrEr�)r,rXrrr�.test_empty_files_list_specified_to_constructorJsz=FileInputTests.test_empty_files_list_specified_to_constructorc
Csxtdddg�}|jt|�td|g��;}|d}|j|d�|d}|j|d�WdQXdS)zNTests invoking FileInput.__getitem__() with the current
           line numberrzline1
zline2
r5rN)rr{rrrE)r,r}rXZretval1Zretval2rrr�test__getitem__Ns

zFileInputTests.test__getitem__cCsztdddg�}|jt|�td|g��'}|jt��}|dWdQXWdQX|j|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberrzline1
zline2
r5N�accessing lines out of order)r�)	rr{rrr��RuntimeErrorrE�	exceptionrb)r,r}rX�cmrrr�test__getitem__invalid_keyYsz)FileInputTests.test__getitem__invalid_keycCsttdg�}|jt|�td|g��'}|jt��}|dWdQXWdQX|j|jjd�dS)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputrr5rN�end of input reached)r�)	rr{rrr��
IndexErrorrEr�rb)r,r}rXr�rrr�test__getitem__eofcsz!FileInputTests.test__getitem__eofcCs�tj}tt�}zdtddg�}|jt|�td|gdd��$}t|�|t_|j	�WdQXWd|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 ignoredrr?r5r>TNzos.unlink() was not invoked)�osr
r^r�rr{rrrlrNr|r`)r,Zos_unlink_origZos_unlink_replacementr}rXrrr�%test_nextfile_oserror_deleting_backupms	
	
z4FileInputTests.test_nextfile_oserror_deleting_backupcCs�tj}tt�}zZtddg�}|jt|�td|gdd��}|t_|j�WdQXWd|t_X|j	|j
d�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rr?r5r>TNzos.fstat() was not invoked)r��fstatr^r�rr{rrrIr|r`)r,Z
os_fstat_origZos_fstat_replacementr}rXrrr�%test_readline_os_fstat_raises_OSError�s		
z4FileInputTests.test_readline_os_fstat_raises_OSError�chmodzos.chmod does not existcCs�tj}tt�}zZtddg�}|jt|�td|gdd��}|t_|j�WdQXWd|t_X|j	|j
d�dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rr?r5r>TNzos.fstat() was not invoked)r�r�r^r�rr{rrrIr|r`)r,Z
os_chmod_origZos_chmod_replacementr}rXrrr�%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||_XWdQX|j|jd�|j	|dd�dS)	Nc@s(eZdZdd�Zdd�ZdS)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcSstj|t�dS)N)r^rarr)r,rrrra�szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|j�dS)N)rd)r,rrrrk�szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)r[r\r]rarkrrrr�FilenoRaisesValueError�sr�rr?r5z_file.fileno() was not invokedzfileno() should return -1r@)
r^rr{rr�_filerkr|r`rE)r,r�Z unconditionally_raise_ValueErrorr}rXZfile_backup�resultrrr�"test_fileno_when_ValueError_raised�s			z1FileInputTests.test_fileno_when_ValueError_raisedN)r[r\r]rgrjrmrtrwr~r�r�r�r�r�r�r�r�r�r��unittestZskipIf�hasattrr�r�r�rrrrre�s$




(rec@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 testsNFrfr�rcCsd||_||_||_||_||_||_d|_tjdd��|_	i|_
dS)NcSsdS)Nrrrrrrry�sz(MockFileInput.__init__.<locals>.<lambda>)r5r>�backupr6rrxr��collections�defaultdict�invocation_counts�
return_values)r,r5r>r�r6rrxrrrra�s							zMockFileInput.__init__cCs|jdd7<dS)Nrr)r�)r,rrrr�szMockFileInput.closecCs|jdd7<|jdS)NrNr)r�r�)r,rrrrN�szMockFileInput.nextfilecCs|jdd7<|jdS)NrHr)r�r�)r,rrrrH�szMockFileInput.filenamecCs|jdd7<|jdS)NrGr)r�r�)r,rrrrG�szMockFileInput.linenocCs|jdd7<|jdS)NrJr)r�r�)r,rrrrJ�szMockFileInput.filelinenocCs|jdd7<|jdS)Nrkr)r�r�)r,rrrrk�szMockFileInput.filenocCs|jdd7<|jdS)NrLr)r�r�)r,rrrrL�szMockFileInput.isfirstlinecCs|jdd7<|jdS)NrMr)r�r�)r,rrrrM�szMockFileInput.isstdin)
r[r\r]�__doc__rarrNrHrGrJrkrLrMrrrrr��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�)r,rrr�setUp�sz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dS)N)r�r�rr�r�)r,rrr�tearDown�sz'BaseFileInputGlobalMethodsTest.tearDowncCsC|j|}|j|d|�t|j�}|j|d�dS)Nr)r�rErF)r,Zmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocation�s
z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)r[r\r]r�r�r�r�rrrrr��sr�c@sFeZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_fileinput_inputz Unit tests for fileinput.input()c
Cspt�}t�|_|t_|jt��}tj�WdQX|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��inputrEr�rb�assertIs)r,�instancer�rrr�1test_state_is_not_None_and_state_file_is_not_Nones		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)r,r�rrr�-test_state_is_not_None_and_state_file_is_Nones			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�)r,rrr�test_state_is_Nones	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().r5r>r�r6rrxzfileinput._stateN)r�r�r�r�r�r5r>r�r6rrx)r,r5r>r�r6rrxr�rrrr�(s 						z'Test_fileinput_input.do_test_call_inputN)r[r\r]r�r�r�r�r�rrrrr�s

	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)r,rrrr�Hs	
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�)r,r�rrr�test_state_is_not_NoneOs
		
z+Test_fileinput_close.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr�Esr�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()c	CsUdt_|jt��}tj�WdQX|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�rNrEr�rbr�)r,r�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.rNN)r�r�r�r�r�rNr�r�)r,Znextfile_retvalr��retvalrrrr�es		
	z.Test_fileinput_nextfile.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr�Xs
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenamez#Unit tests for fileinput.filename()c	CsUdt_|jt��}tj�WdQX|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�rHrEr�rbr�)r,r�rrrr�vs
	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.rHN)r�r�r�r�r�rHr�r�)r,Zfilename_retvalr�r�rrrr��s		
	z.Test_fileinput_filename.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr�ss
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()c	CsUdt_|jt��}tj�WdQX|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�rGrEr�rbr�)r,r�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.rGN)r�r�r�r�r�rGr�r�)r,Z
lineno_retvalr�r�rrrr��s		
	z,Test_fileinput_lineno.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()c	CsUdt_|jt��}tj�WdQX|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�rJrEr�rbr�)r,r�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.rJN)r�r�r�r�r�rJr�r�)r,Zfilelineno_retvalr�r�rrrr��s		
	z0Test_fileinput_filelineno.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()c	CsUdt_|jt��}tj�WdQX|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�rkrEr�rbr�)r,r�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.rkN)	r�r�r��
fileno_retvalr�r�rkr�r�)r,r�r�r�rrrr��s		
		z,Test_fileinput_fileno.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()c	CsUdt_|jt��}tj�WdQX|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�rLrEr�rbr�)r,r�rrrr��s
	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.rLN)r�r�r�r�r�rLr�r�)r,Zisfirstline_retvalr�r�rrrr��s		
	z1Test_fileinput_isfirstline.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr��s
r�c@s.eZdZdZdd�Zdd�ZdS)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()c	CsUdt_|jt��}tj�WdQX|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�rMrEr�rbr�)r,r�rrrr��s
	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.rMN)r�r�r�r�r�rMr�r�)r,Zisstdin_retvalr�r�rrrr�s		
	z-Test_fileinput_isstdin.test_state_is_not_NoneN)r[r\r]r�r�r�rrrrr��s
r�c@s(eZdZdd�Zdd�ZdS)�InvocationRecordercCs
d|_dS)Nr)�invocation_count)r,rrrraszInvocationRecorder.__init__cOs"|jd7_||f|_dS)Nr)r��last_invocation)r,rbrcrrrrdszInvocationRecorder.__call__N)r[r\r]rardrrrrr�s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)r,rrrr� szTest_hook_compressed.setUpcCs|jdd�dS)Nrfr)�do_test_use_builtin_open)r,rrr�test_empty_string#sz&Test_hook_compressed.test_empty_stringcCs|jdd�dS)NZabcdr#)r�)r,rrr�test_no_ext&sz 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_compressedrEr�r�)r,�
original_openr�rrr�test_gz_ext_fake)s	
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�rEr�r�)r,r�r�rrr�test_bz2_ext_fake5s	
z&Test_hook_compressed.test_bz2_ext_fakecCs|jdd�dS)Nz	abcd.blahr&)r�)r,rrr�
test_blah_extAsz"Test_hook_compressed.test_blah_extcCs|jdd�dS)Nzabcd.Gzr4)r�)r,rrr�test_gz_ext_builtinDsz(Test_hook_compressed.test_gz_ext_builtincCs|jdd�dS)Nzabcd.Bz2�)r�)r,rrr�test_bz2_ext_builtinGsz)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�rEr�r�)r,rHrr�r�rrrr�Jsz-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|S)N)�builtinsr)Z
new_open_funcr�rrrr�Us		z)Test_hook_compressed.replace_builtin_openN)r[r\r]r�r�r�r�r�Z
skipUnlessr�r�r�r�r�r�r�r��staticmethodr�rrrrr�s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)Nrr�encoding)r�r�rr�r�rrEr�r�r��poprK)
r,r�r�r�r�rHrZopen_resultrbrcrrr�test^s 						
zTest_hook_encoded.testcs�ttd��}|jd�WdQX�jtt��fdd�}|ddddd	g��jt��|d
dddd	g�WdQX�jt��|ddddd	g�WdQX�jt��|ddd
dd	g�WdQXdS)Nrns
A
B
C
D+IKw-c	sJtdtd|dtd���}t|�}WdQX�j||�dS)Nr5rrxzutf-7)rrrrDrE)rZexpected_linesrXr)r,rr�checkzsz+Test_hook_encoded.test_modes.<locals>.checkr�zA
zB
zC
uD€ZrUroruzB
zC
)	rrrr{rZassertWarnsrsr�rr)r,rr�r)r,r�
test_modestszTest_hook_encoded.test_modesN)r[r\r]r�r�r�rrrrr�[sr��__main__).r�r�rOrAr�r�r�r�r��ImportErrorr��iorrrrZtest.supportrrrr	r
rrrrZTestCaserr^rer�r�r�r�r�r�r�r�r�r�r�r�r�r�r[�mainrrrr�<module>sT

"	[�..A>.