Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/test/__pycache__/test_fileinput.cpython-38.opt-1.pyc
U

>��gW��@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)�tempfile�mkstemp�
addCleanuprr
�open�write)�selfZcontentr�fd�name�f�r�2/opt/cppython/lib/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)r2r/�len)rZhint�linesr0r1rrr�	readlinesDs
zLineReader.readlinescCsdSrrr$rrr�closePszLineReader.close)N)r3)
rrr r%�propertyr&r,r2r7r8rrrrr!/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�rD�inplacer3�
)r�join�range�re�compiler�printr�listr8�assertEqualr5�linenor+r2�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4�pat�fir6�sZ	savestdinZ
savestdoutr1�mrrr�test_buffer_sizesTs�

z"BufferSizesTests.test_buffer_sizesN)rrr rorrrrr:Ssr:c@seZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS�NF)�exception_type�invoked)rrrrrrr%�szUnconditionallyRaise.__init__cOsd|_|���dSr')rsrr�r�args�kwargsrrr�__call__�szUnconditionallyRaise.__call__N�rrr r%rwrrrrrp�srpc@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.
rCr;r)	rrr2rXrYrZr+r[r8)rrgrhrirjrlr1rrr�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
FrC�A
�B
�C�D
�E
�F�rJ)rrrWrXrZrY�rrgrhrlr6rrr�%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
DrCr3)rrrX�filenor.rdr^rW)rrgrhrlr1rrr�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�rDrr}r~�C
�D)r�fail�
ValueErrorrr	�DeprecationWarningrWrX)rrlrgr6rrr�test_opening_mode�s
z FileInputTests.test_opening_modec	CsHt�d��4}td�|_tdgdd�}t|�}|�|dg�W5QRXdS)Nz	sys.stdin�spam, bacon, sausage, and spamrL�rbr�)rZpatchr�bufferrrWrX)rZm_stdinrlr6rrr�test_stdin_binary_mode�s

z%FileInputTests.test_stdin_binary_modecCsXtj}zDtd�t_|�ttjd��tdgdd�}t|�}|�|dg�W5|t_XdS)Nr�r�rLr�r�)r_r`rr[�hasattrrrWrX)rZ
orig_stdinrlr6rrr�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)rrnrrr�<lambda>�z7FileInputTests.test_file_opening_hook.<locals>.<lambda>)rPr,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|_dSrq)rsr$rrrr%szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�Sr')rsr)rrurrrrwszFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__Nrxrrrr�CustomOpenHooksr�rQzopenhook not invoked)rr�r�rr2�
assertTruers)rrlr��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�rDr,r}r~r�zRead to end of filer-)
rrrr�safe_unlinkrrrXr2�UnicodeDecodeErrorr��assertRaisesrW�rrrlrrr�
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�rrXr2r�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)rrPs	New line.)	rrr2rXr_rarr�read)rZ	temp_fileZfobjr1rrrr�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)
Nr{r|rCr}r~rr�r�r�r�rJr)rrrWrXrZrY�_filesr�rrr�test_context_managerNs

z#FileInputTests.test_context_managerc	CsP|�d�}zt|d��
}t�W5QRXWn"tk
rJ|�|jd�YnXdS)Nr-rCr)rr�OSErrorrXr�)rrgrlrrr�test_close_on_exceptionXs
z&FileInputTests.test_close_on_exceptionc	Cs(tgd��}|�|jd�W5QRXdS)NrC)rL)rrXr�)rrlrrr�.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
rCr�line1
r;zline2
N)rrrX)rr�rlZretval1Zretval2rrr�test__getitem__ds
zFileInputTests.test__getitem__c
CsN|�d�}|�td��.t|gd��}|�|dd�W5QRXW5QRXdS)Nr�zUse iterator protocol insteadrCrr�)rZassertWarnsRegexr�rrX)rr�rlrrr�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�rCr;)zaccessing lines out of orderN)rrr��RuntimeErrorrX�	exceptionru�rr�rl�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-rCr)zend of input reachedN)rrr��
IndexErrorrXr�rur�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 ignoredrQz.bakTrOzos.unlink() was not invokedN)�osr
rpr�rrrrr.r^r�rs)rZos_unlink_origZos_unlink_replacementr�rlrrr�%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.rQTrO�os.fstat() was not invokedN)	r��fstatrpr�rrr2r�rs)rZ
os_fstat_origZos_fstat_replacementr�rlrrr�%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.rQTrOr�N)	r��chmodrpr�rrr2r�rs)rZ
os_chmod_origZos_chmod_replacementr�rlrrr�%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)rpr%r�r$rrrr%�szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|��dSr)rwr$rrrr��szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)rrr r%r�rrrr�FilenoRaisesValueError�sr�rQrCz_file.fileno() was not invokedr3zfileno() should return -1)rprr�_filer�r�rsrX)rr�Z unconditionally_raise_ValueErrorr�rlZfile_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,rXr&r2�r�srcrlrrr�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,rXr&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;)
rrrr2rXrYrZr+r��fspath)rrgrlr1rrr�test_pathlib_file�s
z FileInputTests.test_pathlib_filec	Csnt|�d��}t|dd��&}|��}|�|d�td|�W5QRXt|��}|�|��d�W5QRXdS)Nr�T)rPzModified %szModified Pathlib file.
)rrrr2rXrVrr�)rrgrlr1rrrr�test_pathlib_file_inplaces
z(FileInputTests.test_pathlib_file_inplaceN)rrr rzr�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�rrrrry�s8







	

		ryc@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)NcSsdSr4rrrrrr�r�z(MockFileInput.__init__.<locals>.<lambda>)
rDrP�backuprr,r��collections�defaultdict�invocation_counts�
return_values)rrDrPr�rr,rrrr%szMockFileInput.__init__cCs|jdd7<dS)Nr8r;)r�r$rrrr8szMockFileInput.closecCs|jdd7<|jdS)Nr^r;�r�r�r$rrrr^szMockFileInput.nextfilecCs|jdd7<|jdS)Nr+r;r�r$rrrr+"szMockFileInput.filenamecCs|jdd7<|jdS)NrYr;r�r$rrrrY&szMockFileInput.linenocCs|jdd7<|jdS)NrZr;r�r$rrrrZ*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%r8r^r+rYrZr�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�rXr5)rZmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocationGs

z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)rrr r�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��inputrXr�ru�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().)rDrPr�rr,r�rDrPr�rr,N)
r�r�r�r�r�rDrPr�rr,)rrDrPr�rr,r�rrrr�ss
�z'Test_fileinput_input.do_test_call_inputN)rrr r�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�r8�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=Noner8N)r�r�r�r8r�r�r�rrr�test_state_is_not_None�s
z+Test_fileinput_close.test_state_is_not_NoneN�rrr r�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^rXr�rur��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+rXr�rur�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�rYrXr�rur�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.rYN)r�r�r�r�r�rYr�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�rZrXr�rur�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.rZN)r�r�r�r�r�rZr�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�rXr�rur�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\rXr�rur�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]rXr�rur�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|_dSr4)�invocation_countr$rrrr%_szInvocationRecorder.__init__cOs|jd7_||f|_dSr�)r��last_invocationrtrrrrwaszInvocationRecorder.__call__Nrxrrrrr�^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�rr$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_compressedrXr�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.bz2rFr;)rrF)�bz2�BZ2Filer�r�rrXr�r�rrrr�test_bz2_ext_fake}sz&Test_hook_compressed.test_bz2_ext_fakecCs|�dd�dS)Nz	abcd.blahrBrr$rrr�
test_blah_ext�sz"Test_hook_compressed.test_blah_extcCs|�dd�dS)Nzabcd.GzrJrr$rrr�test_gz_ext_builtin�sz(Test_hook_compressed.test_gz_ext_builtincCs|�dd�dS)Nzabcd.Bz2�rr$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�rrXr�r�)rr+rr	r�rrrr�s

�z-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|Sr)�builtinsr)Z
new_open_funcr	rrrr�sz)Test_hook_compressed.replace_builtin_openN)rrr r�r�rr�unittestZ
skipUnlessrr
rrrrrr�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�rrrXr�r�r��popr[)rrrr�r�r	r+rZopen_resultrurvrrr�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�rDrr,�rrrrWrX)r�expected_linesrlr6r$rr�check�s
�z,Test_hook_encoded.test_errors.<locals>.check�ignore�abc�strict�replaceu�abc�backslashreplacez\x80abc)rrrrr�r�r��rrr rr$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)rrrlr6r$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)rrr r�rr'r(rrrrr�src@seZdZdd�ZdS)�MiscTestcCst�|t�dSr)rZcheck__all__r�r$rrr�test_all�szMiscTest.test_allN)rrr r*rrrrr)�sr)�__main__)3r�r�r_rTr�r�rrrr�ImportErrorr�iorrrr�pathlibrZtest.supportrrr	r
r�rrrr
r!ZTestCaser:rpryr�r�r�r�r�r�r�r�r�r�r�r�r�rr)r�mainrrrr�<module>s^


$Sa->>A


F1le Man4ger