Your IP : 216.73.216.213


Current Path : /opt/alt/python38/lib64/python3.8/test/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/test/__pycache__/test_fileinput.cpython-38.pyc

U

i�fW��@sPdZddlZddlZddlZddlZddlZddlZddlZddlZzddl	Z	Wne
k
rhdZ	YnXzddlZWne
k
r�dZYnXddlm
Z
mZddlmZmZddlmZddlmZmZmZddlmZddlmZdd	lmZGd
d�d�ZGdd
�d
�ZGdd�deej�ZGdd�d�Z Gdd�deej�Z!Gdd�d�Z"Gdd�dej�Z#Gdd�de#�Z$Gdd�de#�Z%Gdd�de#�Z&Gdd�de#�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.d/�d/ej�Z/Gd0d1�d1ej�Z0e1d2k�rLe�2�dS)3z,
Tests for fileinput module.
Nick Mathewson
�N)�BytesIO�StringIO)�	FileInput�hook_encoded)�Path)�verbose�TESTFN�check_warnings)�unlink)�support)�mockc@seZdZdd�dd�ZdS)�	BaseTests�w��modec	Cs>t��\}}|�tj|�t||��}|�|�W5QRX|S�N)�tempfileZmkstemp�
addCleanuprr
�open�write)�selfZcontentr�fd�name�f�r�8/opt/alt/python38/lib64/python3.8/test/test_fileinput.py�writeTmp(s
zBaseTests.writeTmpN)�__name__�
__module__�__qualname__rrrrrr
%sr
c@sDeZdZdd�Zedd��Zdd�Zddd	�Zddd�Zd
d�Z	dS)�
LineReadercCs
g|_dSr��
_linesread�rrrr�__init__1szLineReader.__init__cCs z|jdd�W�Sg|_XdSrr!r#rrr�	linesread4szLineReader.linesreadcCst|�d��|_|S�NT)�iter�
splitlines�it)r�filenamerrrr�openhook;szLineReader.openhookNcCst|jd�}|j�|�|S)N�)�nextr)r"�append)r�size�linerrr�readline?szLineReader.readline���cCs@g}d}|��}|s|S|�|�|t|�7}||kr|SqdS�Nr)r1r.�len)rZhint�linesr/r0rrr�	readlinesDs
zLineReader.readlinescCsdSrrr#rrr�closePszLineReader.close)N)r2)
rrrr$�propertyr%r+r1r6r7rrrrr /s


r c@seZdZdd�ZdS)�BufferSizesTestsc
Cs�|�d�dd�td�D���}|�d�dd�td�D���}|�d�dd�td�D���}|�d�d	d�td
�D���}t�d�}tr�td�t||||fd
�}t|�}|�	�|�
t|�d�|�
|dd�|�
|dd�|�
|��d�|�
|�
�|�t�rtd�t||||fd
�}d}|�r@|dk�r@|��}�q$|�
|�
�|�|�
|��d�|�
|��d�|�|���|�|���t�r�td�|��|�
|��d�|�
|��d�|�	�t�r�td�t||||dfd
�}tj}	zNtd�t_t|�}|�
t|�d�|�
|dd �|�
|�
�d!�|��W5|	t_Xt�rXtd"�t||||fd
�}|�
|��d#�|�
|�
�d�|��|�
|��d#�|�
|�
�d�t�r�td$�tj}
zDt||||fd
d%�}|D]}|dd&���}t|��q�|�	�W5|
t_Xt||||fd
�}|D]N}|�
|d&d'�|�|dd&��}|�|d�|�
t|�d
��|����q*|�	�dS)(Nr,css|]}d|dVqdS)zLine %s of file 1
�Nr��.0�irrr�	<genexpr>Vsz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>�css|]}d|dVqdS)zLine %s of file 2
r:Nrr;rrrr>Ws�
css|]}d|dVqdS)zLine %s of file 3
r:Nrr;rrrr>Xs�css|]}d|dVqdS)zLine %s of file 4
r:Nrr;rrrr>Ysr:zLINE (\d+) OF FILE (\d+)z1. Simple iteration��files��zLine 5 of file 1
�zLine 1 of file 4
z2. Status variables�xzLine 6 of file 2
��z3. NextfilezLine 1 of file 3
�z4. Stdin�-z Line 1 of stdin
Line 2 of stdin
�!� zLine 2 of stdin
z<stdin>z5. Boundary conditionsrz
6. Inplace�rC�inplacer2�
)r�join�range�re�compiler�printr�listr7�assertEqualr4�linenor*r1�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4Zpat�fir5�sZ	savestdinZ
savestdoutr0�mrrr�test_buffer_sizesTs�

z"BufferSizesTests.test_buffer_sizesN)rrrrmrrrrr9Ssr9c@seZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS�NF)�exception_type�invoked)rrprrrr$�szUnconditionallyRaise.__init__cOsd|_|���dSr&)rqrp�r�args�kwargsrrr�__call__�szUnconditionallyRaise.__call__N�rrrr$rurrrrrn�srnc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zejed�dd��Zdd�Zejed�d d!��Zejed�d"d#��Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4S)5�FileInputTestscCs�|�d�}|�d�}|�d�}|�d�}t||||fd�}|��}|�|d�|�|��d�|�|��d�|�|��|�|��}|�|�|�|��d�|�|��d�|�|��|�|��dS)Nr,zThe only line there is.
rBr:r)	rrr1rWrXrYr*rZr7)rrfrgrhrirjr0rrr�test_zero_byte_files�s 




z#FileInputTests.test_zero_byte_filesc	Csf|�d�}|�d�}t||fd�}t|�}|�|dddddd	g�|�|��d
�|�|��d�dS)N�A
B
C�D
E
FrB�A
�B
�C�D
�E
�F�rI)rrrVrWrYrX�rrfrgrjr5rrr�%test_files_that_dont_end_with_newline�s

z4FileInputTests.test_files_that_dont_end_with_newlinecCs~|�d�}|�d�}t||fd�}|�|��d�t|�}|�|��d�|��|�|��d�t|�}|�|��d�dS)NzA
BzC
DrBr2)rrrW�filenor-rcr]rV)rrfrgrjr0rrr�test_fileno�s

zFileInputTests.test_filenoc	Cs�ztdd�}|�d�Wntk
r,YnX|jddd�}tdtf��t|dd�}W5QRXtdtf��t|�}W5QRX|�|d	d
ddg�dS)
Nrrz-FileInput should reject invalid mode argument�A
B
C
D�wbr,�U�rCrr{r|�C
�D)r�fail�
ValueErrorrr	�DeprecationWarningrVrW)rrjrfr5rrr�test_opening_mode�s
z FileInputTests.test_opening_modec	CsHt�d��4}td�|_tdgdd�}t|�}|�|dg�W5QRXdS)Nz	sys.stdin�spam, bacon, sausage, and spamrK�rbr�)rZpatchr�bufferrrVrW)rZm_stdinrjr5rrr�test_stdin_binary_mode�s

z%FileInputTests.test_stdin_binary_modecCsXtj}zDtd�t_|�ttjd��tdgdd�}t|�}|�|dg�W5|t_XdS)Nr�r�rKr�r�)r^r_rrZ�hasattrrrVrW)rZ
orig_stdinrjr5rrr�test_detached_stdin_binary_mode�s
z.FileInputTests.test_detached_stdin_binary_modec	Cs�ztddd�d�}|�d�Wntk
r2YnXztdd�}|�d�Wntk
r`YnXGdd	�d	�}|�d
�}|�}t|g|d��}|��W5QRX|�|jd�dS)Nr:cSsdSrr)rrlrrr�<lambda>�z7FileInputTests.test_file_opening_hook.<locals>.<lambda>)rOr+zGFileInput should raise if both inplace and openhook arguments are given)r+z2FileInput should check openhook for being callablec@seZdZdd�Zdd�ZdS)z=FileInputTests.test_file_opening_hook.<locals>.CustomOpenHookcSs
d|_dSro)rqr#rrrr$szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�Sr&)rqr)rrsrrrruszFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__Nrvrrrr�CustomOpenHooksr�rPzopenhook not invoked)rr�r�rr1�
assertTruerq)rrjr��tZcustom_open_hookrrr�test_file_opening_hooks 

z%FileInputTests.test_file_opening_hookc
Cs�ttd��(}|�d�|�dd�|�d�W5QRX|�tt�tttd�d���}z4|�|��d�|�|��d	�|�|��d
�Wnt	k
r�|�
d�YnX|�t	��t|�W5QRX|�|��d�|�|��d�W5QRXdS)
Nr�sA
B
C
s
123456789
i����ascii�rCr+r{r|r�zRead to end of filer,)
rrrr�safe_unlinkrrrWr1�UnicodeDecodeErrorr��assertRaisesrV�rrrjrrr�
test_readline s&
�zFileInputTests.test_readlinec	Cs�ttd��}|�d�W5QRX|�tt�ttdd��V}|�|��d�|�|��d�|�|��d�|�|��d�|�|��d�W5QRXdS)	Nr�r�r�r�sA
sB
sC
Dr�)rrrrr�rrWr1r�rrr�test_readline_binary_mode7sz(FileInputTests.test_readline_binary_modec	Csr|jddd�}t|ddd��&}|��}|�|d�tj�d�W5QRXt|d��}|�|��d�W5QRXdS)Ns
Initial text.r�rr�T)rrOs	New line.)	rrr1rWr^r`rr�read)rZ	temp_fileZfobjr0rrrr�test_inplace_binary_write_modeDsz-FileInputTests.test_inplace_binary_write_modec	Cs�|�d�}|�d�}t||fd��}t|�}W5QRX|�|dddddd	g�|�|��d
�|�|��d�|�|jd�dS)
NryrzrBr{r|r}r~rr�r�rIr)rrrVrWrYrX�_filesr�rrr�test_context_managerNs

z#FileInputTests.test_context_managerc	CsP|�d�}zt|d��
}t�W5QRXWn"tk
rJ|�|jd�YnXdS)Nr,rBr)rr�OSErrorrWr�)rrfrjrrr�test_close_on_exceptionXs
z&FileInputTests.test_close_on_exceptionc	Cs(tgd��}|�|jd�W5QRXdS)NrB)rK)rrWr�)rrjrrr�.test_empty_files_list_specified_to_constructor`sz=FileInputTests.test_empty_files_list_specified_to_constructor)�categoryc	CsN|�d�}t|gd��.}|d}|�|d�|d}|�|d�W5QRXdS)zNTests invoking FileInput.__getitem__() with the current
           line number�line1
line2
rBr�line1
r:zline2
N)rrrW)rr�rjZretval1Zretval2rrr�test__getitem__ds
zFileInputTests.test__getitem__c
CsN|�d�}|�td��.t|gd��}|�|dd�W5QRXW5QRXdS)Nr�zUse iterator protocol insteadrBrr�)rZassertWarnsRegexr�rrW)rr�rjrrr�test__getitem___deprecationos
�z*FileInputTests.test__getitem___deprecationc
CsT|�d�}t|gd��$}|�t��}|dW5QRXW5QRX|�|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberr�rBr:)zaccessing lines out of orderN)rrr��RuntimeErrorrW�	exceptionrs�rr�rj�cmrrr�test__getitem__invalid_keyvs

z)FileInputTests.test__getitem__invalid_keyc
CsT|�d�}t|gd��$}|�t��}|dW5QRXW5QRX|�|jjd�dS)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputr,rBr)zend of input reachedN)rrr��
IndexErrorrWr�rsr�rrr�test__getitem__eof�s

z!FileInputTests.test__getitem__eofc	Csztj}tt�}zP|�d�}|�tj|d�t|gdd��}t|�|t_|�	�W5QRXW5|t_X|�
|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 ignoredrPz.bakTrNzos.unlink() was not invokedN)�osr
rnr�rrrrr-r]r�rq)rZos_unlink_origZos_unlink_replacementr�rjrrr�%test_nextfile_oserror_deleting_backup�s
�z4FileInputTests.test_nextfile_oserror_deleting_backupc	Cs`tj}tt�}z6|�d�}t|gdd��}|t_|��W5QRXW5|t_X|�|jd�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rPTrN�os.fstat() was not invokedN)	r��fstatrnr�rrr1r�rq)rZ
os_fstat_origZos_fstat_replacementr�rjrrr�%test_readline_os_fstat_raises_OSError�s
�z4FileInputTests.test_readline_os_fstat_raises_OSErrorc	Cs`tj}tt�}z6|�d�}t|gdd��}|t_|��W5QRXW5|t_X|�|jd�dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rPTrNr�N)	r��chmodrnr�rrr1r�rq)rZ
os_chmod_origZos_chmod_replacementr�rjrrr�%test_readline_os_chmod_raises_OSError�s
�z4FileInputTests.test_readline_os_chmod_raises_OSErrorc	CszGdd�dt�}|�}|�d�}t|gd��(}|j}z||_|��}W5||_XW5QRX|�|jd�|�|dd�dS)Nc@seZdZdd�Zdd�ZdS)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcSst�|t�dSr)rnr$r�r#rrrr$�szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|��dSr)rur#rrrr��szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)rrrr$r�rrrr�FilenoRaisesValueError�sr�rPrBz_file.fileno() was not invokedr2zfileno() should return -1)rnrr�_filer�r�rqrW)rr�Z unconditionally_raise_ValueErrorr�rjZfile_backup�resultrrr�"test_fileno_when_ValueError_raised�s
�z1FileInputTests.test_fileno_when_ValueError_raisedc	Cs�t�}tddg|jd���}|�|jg�|�|��d�|�|jdg�|�|��d�|�|jdg�|�|��d�|�|jddg�|�|��d�|�|jdg�|�|��d�|�|jg�W5QRXdS�Nzline1
line2zline3
r�r�Zline2r,)r rr+rWr%r1�r�srcrjrrr�test_readline_buffering�s �z&FileInputTests.test_readline_bufferingc	Cs�t�}tddg|jd���}|�|jg�|�t|�d�|�|jdg�|�t|�d�|�|jdg�|�t|�d�|�|jddg�|�tt|�|�|jdg�|�tt|�|�|jg�W5QRXdSr�)r rr+rWr%r-r��
StopIterationr�rrr�test_iteration_buffering�s �z'FileInputTests.test_iteration_bufferingc	Cspt|�d��}t|��P}|��}|�|d�|�|��d�|�|��d�|�|��t�	|��W5QRXdS)N�
Pathlib file.r:)
rrrr1rWrXrYr*r��fspath)rrfrjr0rrr�test_pathlib_file�s
z FileInputTests.test_pathlib_filec	Csnt|�d��}t|dd��&}|��}|�|d�td|�W5QRXt|��}|�|��d�W5QRXdS)Nr�T)rOzModified %szModified Pathlib file.
)rrrr1rWrUrr�)rrfrjr0rrrr�test_pathlib_file_inplaces
z(FileInputTests.test_pathlib_file_inplaceN)rrrrxr�r�r�r�r�r�r�r�r�r�r�r�rZignore_warningsr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrw�s8







	

		rwc@sbeZdZdZdddd�dd�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)rr+cCs>||_||_||_||_||_d|_t�dd��|_i|_	dS)NcSsdSr3rrrrrr�r�z(MockFileInput.__init__.<locals>.<lambda>)
rCrO�backuprr+r��collections�defaultdict�invocation_counts�
return_values)rrCrOr�rr+rrrr$szMockFileInput.__init__cCs|jdd7<dS)Nr7r:)r�r#rrrr7szMockFileInput.closecCs|jdd7<|jdS)Nr]r:�r�r�r#rrrr]szMockFileInput.nextfilecCs|jdd7<|jdS)Nr*r:r�r#rrrr*"szMockFileInput.filenamecCs|jdd7<|jdS)NrXr:r�r#rrrrX&szMockFileInput.linenocCs|jdd7<|jdS)NrYr:r�r#rrrrY*szMockFileInput.filelinenocCs|jdd7<|jdS)Nr�r:r�r#rrrr�.szMockFileInput.filenocCs|jdd7<|jdS)Nr[r:r�r#rrrr[2szMockFileInput.isfirstlinecCs|jdd7<|jdS)Nr\r:r�r#rrrr\6szMockFileInput.isstdin)NFr,)
rrr�__doc__r$r7r]r*rXrYr�r[r\rrrrr�
s�r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BaseFileInputGlobalMethodsTestzQBase class for unit tests for the global function of
       the fileinput module.cCstj|_tj|_tt_dSr)�	fileinput�_state�_orig_stater�_orig_FileInputr�r#rrr�setUp>sz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dSr)r�r�rr�r�r#rrr�tearDownCsz'BaseFileInputGlobalMethodsTest.tearDowncCs2|j|}|�|d|�t|j�}|�|d�dS�Nr:)r�rWr4)rZmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocationGs

z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)rrrr�r�r�r�rrrrr�:sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_fileinput_inputz Unit tests for fileinput.input()c	CsVt�}t�|_|t_|�t��}t��W5QRX|�d|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.)zinput() already active�fileinput._stateN)r��objectr�r�r�r�r��inputrWr�rs�assertIs)r�instancer�rrr�1test_state_is_not_None_and_state_file_is_not_NoneRszFTest_fileinput_input.test_state_is_not_None_and_state_file_is_not_NonecCst�}d|_|t_|��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_None_szBTest_fileinput_input.test_state_is_not_None_and_state_file_is_NonecCsdt_|��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_Nonejsz'Test_fileinput_input.test_state_is_NonecCs�t�}t�}t�}t�}t�}tj|||||d�}|�|tjd�|�||jd�|�||jd�|�||jd�|�||jd�|�||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().)rCrOr�rr+r�rCrOr�rr+N)
r�r�r�r�r�rCrOr�rr+)rrCrOr�rr+r�rrrr�ss
�z'Test_fileinput_input.do_test_call_inputN)rrrr�r�r�r�r�rrrrr�Os

	r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_closez Unit tests for fileinput.close()cCsdt_t��|�tj�dS)zPTests that fileinput.close() does nothing if fileinput._state
           is NoneN)r�r�r7�assertIsNoner#rrrr��sz'Test_fileinput_close.test_state_is_NonecCs0t�}|t_t��|�|d�|�tj�dS)z`Tests that fileinput.close() invokes close() on fileinput._state
           and sets _state=Noner7N)r�r�r�r7r�r�r�rrr�test_state_is_not_None�s
z+Test_fileinput_close.test_state_is_not_NoneN�rrrr�r�r�rrrrr��sr�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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�zno active input())	r�r�r�r�r]rWr�rsr��rr�rrrr��s
z*Test_fileinput_nextfile.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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_NoneNr�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenamez#Unit tests for fileinput.filename()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�r*rWr�rsr�r�rrrr��s
z*Test_fileinput_filename.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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_NoneNr�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�rXrWr�rsr�r�rrrr��s
z(Test_fileinput_lineno.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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.rXN)r�r�r�r�r�rXr�r�)rZ
lineno_retvalr�r�rrrr��s
z,Test_fileinput_lineno.test_state_is_not_NoneNr�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�rYrWr�rsr�r�rrrr��s
z,Test_fileinput_filelineno.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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.rYN)r�r�r�r�r�rYr�r�)rZfilelineno_retvalr�r�rrrr��s
z0Test_fileinput_filelineno.test_state_is_not_NoneNr�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�r�rWr�rsr�r�rrrr�s
z(Test_fileinput_fileno.test_state_is_NonecCsTt�}t�}||jd<||_|t_t��}|�|d�|�||�|�tj|�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.r�N)	r�r�r��
fileno_retvalr�r�r�r�r�)rr�r�r�rrrr�s
z,Test_fileinput_fileno.test_state_is_not_NoneNr�rrrrr�s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�r[rWr�rsr�r�rrrr�+s
z-Test_fileinput_isfirstline.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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�5s
z1Test_fileinput_isfirstline.test_state_is_not_NoneNr�rrrrr�(s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()c	CsDdt_|�t��}t��W5QRX|�d|jj�|�tj�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._stateNr�)	r�r�r�r�r\rWr�rsr�r�rrrr�Fs
z)Test_fileinput_isstdin.test_state_is_NonecCsNt�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�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�Ps
z-Test_fileinput_isstdin.test_state_is_not_NoneNr�rrrrr�Cs
r�c@seZdZdd�Zdd�ZdS)�InvocationRecordercCs
d|_dSr3)�invocation_countr#rrrr$_szInvocationRecorder.__init__cOs|jd7_||f|_dSr�)r��last_invocationrrrrrruaszInvocationRecorder.__call__Nrvrrrrr�^sr�c@s|eZdZdZdd�Zdd�Zdd�Ze�e	d�d	d
��Z
e�ed�dd
��Zdd�Z
dd�Zdd�Zdd�Zedd��ZdS)�Test_hook_compressedz*Unit tests for fileinput.hook_compressed()cCst�|_dSr)r��	fake_openr#rrrr�hszTest_hook_compressed.setUpcCs|�dd�dS)Nr,r:��do_test_use_builtin_openr#rrr�test_empty_stringksz&Test_hook_compressed.test_empty_stringcCs|�dd�dS)NZabcd�r�r#rrr�test_no_extnsz Test_hook_compressed.test_no_extzRequires gzip and zlibcCsPtj}|jt_zt�dd�}W5|t_X|�|jjd�|�|jjdif�dS)N�test.gzr�r:)rr�)�gziprr�r��hook_compressedrWr�r��r�
original_openr�rrr�test_gz_ext_fakeqsz%Test_hook_compressed.test_gz_ext_fakezRequires bz2cCsPtj}|jt_zt�dd�}W5|t_X|�|jjd�|�|jjdif�dS)N�test.bz2rEr:)r	rE)�bz2ZBZ2Filer�r�rrWr�r�rrrr�test_bz2_ext_fake}sz&Test_hook_compressed.test_bz2_ext_fakecCs|�dd�dS)Nz	abcd.blahrAr�r#rrr�
test_blah_ext�sz"Test_hook_compressed.test_blah_extcCs|�dd�dS)Nzabcd.GzrIr�r#rrr�test_gz_ext_builtin�sz(Test_hook_compressed.test_gz_ext_builtincCs|�dd�dS)Nzabcd.Bz2�r�r#rrr�test_bz2_ext_builtin�sz)Test_hook_compressed.test_bz2_ext_builtinc	CsV|�|j�}zt�||�}W5|�|�X|�|jjd�|�|jj||fif�dSr�)�replace_builtin_openr�r�rrWr�r�)rr*rrr�rrrr��s

�z-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|Sr)�builtinsr)Z
new_open_funcrrrrr�sz)Test_hook_compressed.replace_builtin_openN)rrrr�r�rr�unittestZ
skipUnlessrrr
rrr
rr��staticmethodrrrrrr�es



r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Test_hook_encodedz'Unit tests for fileinput.hook_encoded()cCs�t�}t�}tj||d�}t�}tj}|t_zt�}t�}|||�}W5|t_X|�|jd�|j\}	}
|�	|	d|�|�	|	d|�|�	|
�
d�|�|�	|
�
d�|�|�|
�dS)N��errorsr:r�encodingr)r�r�rr�rrrWr�r�r��poprZ)rrrr�r�rr*rZopen_resultrsrtrrr�test�s$
zTest_hook_encoded.testc	s�ttd��}|�d�W5QRX��tt��fdd�}|ddg���t��|ddg�W5QRX|dd	g�|d
dg�dS)Nr�s�abcc	s:ttdtd|d�d��}t|�}W5QRX��||�dS)Nr�zutf-8r�rCrr+�rrrrVrW)r�expected_linesrjr5r#rr�check�s
�z,Test_hook_encoded.test_errors.<locals>.check�ignore�abc�strict�replaceu�abc�backslashreplacez\x80abc)rrrrr�r�r��rrrrr#r�test_errors�szTest_hook_encoded.test_errorsc	s�ttd��}|�d�W5QRX��tt��fdd�}|ddddd	g���t��|d
dddd	g�W5QRX��t��|ddddd	g�W5QRX��t��|ddd
dd	g�W5QRXdS)Nr�s
A
B
C
D+IKw-c	s6tt|td�d��}t|�}W5QRX��||�dS)Nzutf-7rr)rrrjr5r#rrr�s�z+Test_hook_encoded.test_modes.<locals>.checkr�r{r|r�uD€ZrUr�r�zB
zC
)	rrrrr�ZassertWarnsr�r�r�r#rr#r�
test_modes�szTest_hook_encoded.test_modesN)rrrr�rr$r%rrrrr�src@seZdZdd�ZdS)�MiscTestcCst�|t�dSr)rZcheck__all__r�r#rrr�test_all�szMiscTest.test_allN)rrrr'rrrrr&�sr&�__main__)3r�r�r^rSr�r�rrrr
�ImportErrorr�iorrrr�pathlibrZtest.supportrrr	r
r�rrrr
r ZTestCaser9rnrwr�r�r�r�r�r�r�r�r�r�r�r�r�rr&r�mainrrrr�<module>s^


$Sa->>A