Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_fileinput.cpython-39.opt-1.pyc

a

��gW��@sLdZddlZddlZddlZddlZddlZddlZddlZddlZzddl	Z	Wne
yfdZ	Yn0zddlZWne
y�dZYn0ddl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�rHe�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��modecCsRt��\}}|�tj|�t||��}|�|�Wd�n1sD0Y|S�N)�tempfile�mkstemp�
addCleanuprr
�open�write)�selfZcontentr�fd�name�f�r�//usr/local/lib/python3.9/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�Wg|_Sg|_0dSrr"r$rrr�	linesread4s
�zLineReader.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)r�hint�linesr0r1rrr�	readlinesDs
zLineReader.readlinescCsdSrrr$rrr�closePszLineReader.close)N)r3)
rrr r%�propertyr&r,r2r8r9rrrrr!/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}	zTtd�t_t|�}|�
t|�d�|�
|dd �|�
|�
�d!�|��W|	t_n|	t_0t�r^td"�t||||fd
�}|�
|��d#�|�
|�
�d�|��|�
|��d#�|�
|�
�d�t�r�td$�tj}
zJt||||fd
d%�}|D]}|dd&���}t|��q�|�	�W|
t_n|
t_0t||||fd
�}|D]N}|�
|d&d'�|�|dd&��}|�|d�|�
t|�d
��|����q6|�	�dS)(Nr-css|]}d|dVqdS)zLine %s of file 1
�Nr��.0�irrr�	<genexpr>V�z5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>�css|]}d|dVqdS)zLine %s of file 2
r<Nrr=rrrr@WrA�
css|]}d|dVqdS)zLine %s of file 3
r<Nrr=rrrr@XrA�css|]}d|dVqdS)zLine %s of file 4
r<Nrr=rrrr@YrAr<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�rF�inplacer3�
)r�join�range�re�compiler�printr�listr9�assertEqualr5�linenor+r2�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4�pat�fir7�sZ	savestdinZ
savestdoutr1�mrrr�test_buffer_sizesTs�



z"BufferSizesTests.test_buffer_sizesN)rrr rqrrrrr;Ssr;c@seZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS�NF)�exception_type�invoked)rrtrrrr%�szUnconditionallyRaise.__init__cOsd|_|���dSr')rurt�r�args�kwargsrrr�__call__�szUnconditionallyRaise.__call__N�rrr r%ryrrrrrr�srrc@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.
rEr<r)	rrr2rZr[r\r+r]r9)rrirjrkrlrnr1rrr�test_zero_byte_files�s 




z#FileInputTests.test_zero_byte_filescCs^|�d�}|�d�}t||fd�}t|�}|�|gd��|�|��d�|�|��d�dS)N�A
B
C�D
E
FrE��A
�B
�CzD
zE
�F�rL)rrrYrZr\r[�rrirjrnr7rrr�%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
DrEr3)rrrZ�filenor.rfr`rY)rrirjrnr1rrr�test_fileno�s

zFileInputTests.test_filenocCs�ztdd�}|�d�Wnty*Yn0|jddd�}tdtf��t|dd�}Wd�n1sh0Ytdtf��t|�}Wd�n1s�0Y|�|gd	��dS)
Nrrz-FileInput should reject invalid mode argument�A
B
C
D�wbr-�U�rFr)r�r��C
�D)r�fail�
ValueErrorrr	�DeprecationWarningrYrZ)rrnrir7rrr�test_opening_mode�s
*&z FileInputTests.test_opening_modecCs\t�d��>}td�|_tdgdd�}t|�}|�|dg�Wd�n1sN0YdS)Nz	sys.stdin�spam, bacon, sausage, and spamrN�rbr�)rZpatchr�bufferrrYrZ)rZm_stdinrnr7rrr�test_stdin_binary_mode�s

z%FileInputTests.test_stdin_binary_modecCs^tj}zJtd�t_|�ttjd��tdgdd�}t|�}|�|dg�W|t_n|t_0dS)Nr�r�rNr�r�)rarbrr]�hasattrrrYrZ)rZ
orig_stdinrnr7rrr�test_detached_stdin_binary_mode�s
z.FileInputTests.test_detached_stdin_binary_modecCs�ztddd�d�}|�d�Wnty0Yn0ztdd�}|�d�Wnty\Yn0Gdd	�d	�}|�d
�}|�}t|g|d��}|��Wd�n1s�0Y|�|jd�dS)Nr<cSsdSrr)rrprrr�<lambda>rAz7FileInputTests.test_file_opening_hook.<locals>.<lambda>)rRr,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|_dSrs)rur$rrrr%szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�Sr')rur)rrwrrrryszFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__Nrzrrrr�CustomOpenHooksr�rSzopenhook not invoked)rr�r�rr2�
assertTrueru)rrnr��tZcustom_open_hookrrr�test_file_opening_hooks 

&z%FileInputTests.test_file_opening_hookc	Cs2ttd��2}|�d�|�dd�|�d�Wd�n1sB0Y|�tt�tttd�d���}z4|�|��d�|�|��d	�|�|��d
�Wnt	y�|�
d�Yn0|�t	��t|�Wd�n1s�0Y|�|��d�|�|��d�Wd�n1�s$0YdS)
Nr�sA
B
C
s
123456789
i����ascii�rFr,r�r�r�zRead to end of filer-)
rrrr�safe_unlinkrrrZr2�UnicodeDecodeErrorr��assertRaisesrY�rrrnrrr�
test_readline s&
(�&zFileInputTests.test_readlinecCs�ttd��}|�d�Wd�n1s*0Y|�tt�ttdd��`}|�|��d�|�|��d�|�|��d�|�|��d�|�|��d�Wd�n1s�0YdS)	Nr�r�r�r�sA
sB
sC
DrA)rrrrr�rrZr2r�rrr�test_readline_binary_mode7s(z(FileInputTests.test_readline_binary_modecCs�|jddd�}t|ddd��0}|��}|�|d�tj�d�Wd�n1sR0Yt|d�� }|�|��d�Wd�n1s�0YdS)Ns
Initial text.r�rr�T)rrRs	New line.)	rrr2rZrarcrr�read)rZ	temp_fileZfobjr1rrrr�test_inplace_binary_write_modeDs*z-FileInputTests.test_inplace_binary_write_modecCs�|�d�}|�d�}t||fd��}t|�}Wd�n1s@0Y|�|gd��|�|��d�|�|��d�|�|jd�dS)Nr}r~rErr�rLr)rrrYrZr\r[�_filesr�rrr�test_context_managerNs

&z#FileInputTests.test_context_managercCsb|�d�}z2t|d��}t�Wd�n1s00YWn ty\|�|jd�Yn0dS)Nr-rEr)rr�OSErrorrZr�)rrirnrrr�test_close_on_exceptionXs
&z&FileInputTests.test_close_on_exceptioncCs<tgd��}|�|jd�Wd�n1s.0YdS)NrE)rN)rrZr�)rrnrrr�.test_empty_files_list_specified_to_constructor`sz=FileInputTests.test_empty_files_list_specified_to_constructor)�categorycCsb|�d�}t|gd��8}|d}|�|d�|d}|�|d�Wd�n1sT0YdS)zNTests invoking FileInput.__getitem__() with the current
           line number�line1
line2
rEr�line1
r<zline2
N)rrrZ)rr�rnZretval1Zretval2rrr�test__getitem__ds
zFileInputTests.test__getitem__c	Csv|�d�}|�td��Lt|gd�� }|�|dd�Wd�n1sJ0YWd�n1sh0YdS)Nr�zUse iterator protocol insteadrErr�)rZassertWarnsRegexr�rrZ)rr�rnrrr�test__getitem___deprecationos
�z*FileInputTests.test__getitem___deprecationc	Cs||�d�}t|gd��B}|�t��}|dWd�n1s@0YWd�n1s^0Y|�|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberr�rEr<N)zaccessing lines out of order)rrr��RuntimeErrorrZ�	exceptionrw�rr�rn�cmrrr�test__getitem__invalid_keyvs

Dz)FileInputTests.test__getitem__invalid_keyc	Cs||�d�}t|gd��B}|�t��}|dWd�n1s@0YWd�n1s^0Y|�|jjd�dS)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputr-rErN)zend of input reached)rrr��
IndexErrorrZr�rwr�rrr�test__getitem__eof�s

Dz!FileInputTests.test__getitem__eofcCs�tj}tt�}zj|�d�}|�tj|d�t|gdd��&}t|�|t_|�	�Wd�n1sf0YW|t_n|t_0|�
|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 ignoredrSz.bakTrQNzos.unlink() was not invoked)�osr
rrr�rrrrr.r`r�ru)rZos_unlink_origZos_unlink_replacementr�rnrrr�%test_nextfile_oserror_deleting_backup�s
(�z4FileInputTests.test_nextfile_oserror_deleting_backupcCsztj}tt�}zP|�d�}t|gdd��}|t_|��Wd�n1sL0YW|t_n|t_0|�|jd�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rSTrQN�os.fstat() was not invoked)	r��fstatrrr�rrr2r�ru)rZ
os_fstat_origZos_fstat_replacementr�rnrrr�%test_readline_os_fstat_raises_OSError�s
(�z4FileInputTests.test_readline_os_fstat_raises_OSErrorcCsztj}tt�}zP|�d�}t|gdd��}|t_|��Wd�n1sL0YW|t_n|t_0|�|jd�dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rSTrQNr�)	r��chmodrrr�rrr2r�ru)rZ
os_chmod_origZos_chmod_replacementr�rnrrr�%test_readline_os_chmod_raises_OSError�s
(�z4FileInputTests.test_readline_os_chmod_raises_OSErrorc	Cs�Gdd�dt�}|�}|�d�}t|gd��8}|j}z||_|��}W||_n||_0Wd�n1sj0Y|�|jd�|�|dd�dS)Nc@seZdZdd�Zdd�ZdS)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcSst�|t�dSr)rrr%r�r$rrrr%�szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|��dSr)ryr$rrrr��szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)rrr r%r�rrrr�FilenoRaisesValueError�sr�rSrEz_file.fileno() was not invokedr3zfileno() should return -1)rrrr�_filer�r�rurZ)rr�Z unconditionally_raise_ValueErrorr�rnZfile_backup�resultrrr�"test_fileno_when_ValueError_raised�s

.�z1FileInputTests.test_fileno_when_ValueError_raisedcCs�t�}tddg|jd���}|�|jg�|�|��d�|�|jdg�|�|��d�|�|jdg�|�|��d�|�|jddg�|�|��d�|�|jdg�|�|��d�|�|jg�Wd�n1s�0YdS�Nzline1
line2zline3
r�r�Zline2r-)r!rr,rZr&r2�r�srcrnrrr�test_readline_buffering�s �z&FileInputTests.test_readline_bufferingcCs�t�}tddg|jd���}|�|jg�|�t|�d�|�|jdg�|�t|�d�|�|jdg�|�t|�d�|�|jddg�|�tt|�|�|jdg�|�tt|�|�|jg�Wd�n1s�0YdSr�)r!rr,rZr&r.r��
StopIterationr�rrr�test_iteration_buffering�s �z'FileInputTests.test_iteration_bufferingcCs�t|�d��}t|��Z}|��}|�|d�|�|��d�|�|��d�|�|��t�	|��Wd�n1sv0YdS)N�
Pathlib file.r<)
rrrr2rZr[r\r+r��fspath)rrirnr1rrr�test_pathlib_file�s
z FileInputTests.test_pathlib_filecCs�t|�d��}t|dd��0}|��}|�|d�td|�Wd�n1sP0Yt|�� }|�|��d�Wd�n1s�0YdS)Nr�T)rRzModified %szModified Pathlib file.
)rrrr2rZrXrr�)rrirnr1rrrr�test_pathlib_file_inplaces*
z(FileInputTests.test_pathlib_file_inplaceN)rrr r|r�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�rrrrr{�s8







	

		r{c@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�rAz(MockFileInput.__init__.<locals>.<lambda>)
rFrR�backuprr,r��collections�defaultdict�invocation_counts�
return_values)rrFrRr�rr,rrrr%szMockFileInput.__init__cCs|jdd7<dS)Nr9r<)r�r$rrrr9szMockFileInput.closecCs|jdd7<|jdS)Nr`r<�r�r�r$rrrr`szMockFileInput.nextfilecCs|jdd7<|jdS)Nr+r<r�r$rrrr+"szMockFileInput.filenamecCs|jdd7<|jdS)Nr[r<r�r$rrrr[&szMockFileInput.linenocCs|jdd7<|jdS)Nr\r<r�r$rrrr\*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%r9r`r+r[r\r�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�rZr5)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()cCsjt�}t�|_|t_|�t��}t��Wd�n1s<0Y|�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.N)zinput() already active�fileinput._state)r��objectr�r�r�r�r��inputrZr�rw�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().)rFrRr�rr,r�rFrRr�rr,N)
r�r�r�r�r�rFrRr�rr,)rrFrRr�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�r9�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=Noner9N)r�r�r�r9r�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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`rZr�rwr��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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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+rZr�rwr�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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�r[rZr�rwr�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.r[N)r�r�r�r�r�r[r�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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�r\rZr�rwr�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.r\N)r�r�r�r�r�r\r�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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�rZr�rwr�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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^rZr�rwr�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()cCsXdt_|�t��}t��Wd�n1s.0Y|�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_rZr�rwr�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_invocationrvrrrryaszInvocationRecorder.__call__Nrzrrrrr�^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 zlibcCsVtj}|jt_zt�dd�}W|t_n|t_0|�|jjd�|�|jjdif�dS)N�test.gzr�r<)rr�)�gziprr�r��hook_compressedrZr�r��r�
original_openr�rrr�test_gz_ext_fakeqsz%Test_hook_compressed.test_gz_ext_fakezRequires bz2cCsVtj}|jt_zt�dd�}W|t_n|t_0|�|jjd�|�|jjdif�dS)N�test.bz2rHr<)rrH)�bz2�BZ2Filer�r�rrZr�r�rrrr�test_bz2_ext_fake}sz&Test_hook_compressed.test_bz2_ext_fakecCs|�dd�dS)Nz	abcd.blahrDrr$rrr�
test_blah_ext�sz"Test_hook_compressed.test_blah_extcCs|�dd�dS)Nzabcd.GzrLrr$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	Cs`|�|j�}zt�||�}W|�|�n|�|�0|�|jjd�|�|jj||fif�dSr�)�replace_builtin_openr�r�rrZr�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_z t�}t�}|||�}W|t_n|t_0|�|jd�|j\}	}
|�	|	d|�|�	|	d|�|�	|
�
d�|�|�	|
�
d�|�|�|
�dS)N��errorsr<r�encodingr)r�r�rr�rrrZr�r�r��popr])rrrr�r�r	r+rZopen_resultrwrxrrr�test�s$
zTest_hook_encoded.testcs�ttd��}|�d�Wd�n1s*0Y��tt��fdd�}|ddg���t��|ddg�Wd�n1s�0Y|dd	g�|d
dg�dS)Nr�s�abccsNttdtd|d�d��}t|�}Wd�n1s40Y��||�dS)Nr�zutf-8r�rFrr,�rrrrYrZ)r�expected_linesrnr7r$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_errorscsttd��}|�d�Wd�n1s*0Y��tt��fdd�}|dgd����t��|dgd��Wd�n1s�0Y��t��|dgd��Wd�n1s�0Y��t��|d	gd
��Wd�n1s�0YdS)Nr�s
A
B
C
D+IKw-csJtt|td�d��}t|�}Wd�n1s00Y��||�dS)Nzutf-7rr)rrrnr7r$rrr �s�&z+Test_hook_encoded.test_modes.<locals>.checkr�)r�r�r��D€ZrUr�r�)r�zB
zC
r()	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�rarVr�r�rrrr�ImportErrorr�iorrrr�pathlibrZtest.supportrrr	r
r�rrrr
r!ZTestCaser;rrr{r�r�r�r�r�r�r�r�r�r�r�r�r�rr*r�mainrrrr�<module>s^


$Sa->>A


Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists