Your IP : 216.73.216.213


Current Path : /opt/alt/python310/lib64/python3.10/test/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/test/__pycache__/test_fileinput.cpython-310.opt-1.pyc

o

0�i���@stdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	zddl
Z
Wney7dZ
YnwzddlZWneyIdZYnwddlm
Z
mZddlmZmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddl	mZGd
d�d�ZGdd�d�ZGdd�dee	j �Z!Gdd�d�Z"Gdd�dee	j �Z#Gdd�d�Z$Gdd�de	j �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,e%�Z.Gd-d.�d.�Z/Gd/d0�d0e	j �Z0Gd1d2�d2e	j �Z1Gd3d4�d4e	j �Z2e3d5k�r8e	�4�dSdS)6z,
Tests for fileinput module.
Nick Mathewson
�N)�BytesIO�StringIO)�	FileInput�hook_encoded)�Path)�verbose)�TESTFN)�unlink)�	os_helper)�warnings_helper)�support)�mockc@seZdZdd�dd�ZdS)�	BaseTests�w��modecCsht��\}}|�tj|�d|vrdnd}t|||d��}|�|�Wd�|S1s-wY|S)N�b�utf-8��encoding)�tempfileZmkstemp�
addCleanupr
r	�open�write)�selfZcontentr�fd�namer�f�r�:/opt/alt/python310/lib64/python3.10/test/test_fileinput.py�writeTmp,s
��zBaseTests.writeTmpN)�__name__�
__module__�__qualname__r rrrrr)src@sDeZdZdd�Zedd��Zdd�Zddd	�Zddd�Zd
d�Z	dS)�
LineReadercCs
g|_dS�N��
_linesread�rrrr�__init__6�
zLineReader.__init__cCs z|jdd�Wg|_Sg|_wr%r&r(rrr�	linesread9szLineReader.linesreadcCst|�d��|_|S�NT)�iter�
splitlines�it)r�filenamerrrr�openhook@szLineReader.openhookNcCst|jd�}|j�|�|S)N�)�nextr/r'�append)r�size�linerrr�readlineDszLineReader.readline���cCs>g}d}	|��}|s
|S|�|�|t|�7}||kr|Sq�Nr)r7r4�len)rZhint�linesr5r6rrr�	readlinesIs
�zLineReader.readlinescC�dSr%rr(rrr�closeUszLineReader.closer%)r8)
r!r"r#r)�propertyr+r1r7r<r>rrrrr$4s


r$c@�eZdZdd�ZdS)�BufferSizesTestsc
Cs�|�d�dd�td�D���}|�d�dd�td�D���}|�d�dd�td�D���}|�d�d	d�td
�D���}t�d�}trGtd�t||||fd
d�}t|�}|�	�|�
t|�d�|�
|dd�|�
|dd�|�
|��d�|�
|�
�|�tr�td�t||||fd
d�}d}|r�|dkr�|��}|r�|dks�|�
|�
�|�|�
|��d�|�
|��d�|�|���|�|���tr�td�|��|�
|��d�|�
|��d�|�	�tr�td�t||||dfd
d�}tj}	z*td�t_t|�}|�
t|�d�|�
|d d!�|�
|�
�d"�|��W|	t_n|	t_wt�r1td#�t||||fd
d�}|�
|��d$�|�
|�
�d�|��|�
|��d$�|�
|�
�d�t�rftd%�tj}
z&t||||fd
d
d&�}|D]}|dd'���}t|��qw|�	�W|
t_n|
t_wt||||fd
d�}|D]'}|�
|d'd(�|�|dd'��}|�|d�|�
t|�d
��|����q�|�	�dS))Nr2cs��|]	}d|dVqdS)zLine %s of file 1
�Nr��.0�irrr�	<genexpr>[��z5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>�csrB)zLine %s of file 2
rCNrrDrrrrG\rH�
csrB)zLine %s of file 3
rCNrrDrrrrG]rH�csrB)zLine %s of file 4
rCNrrDrrrrG^rHrCzLINE (\d+) OF FILE (\d+)z1. Simple iterationr��filesr��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�rM�inplacerr8�
)r �join�range�re�compiler�printr�listr>�assertEqualr:�linenor0r7�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4Zpat�fir;�sZ	savestdinZ
savestdoutr6�mrrr�test_buffer_sizesYs�
�


z"BufferSizesTests.test_buffer_sizesN)r!r"r#rwrrrrrAXsrAc@�eZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS�NF)�exception_type�invoked)rr{rrrr)�s
zUnconditionallyRaise.__init__cOsd|_|���r,)r|r{�r�args�kwargsrrr�__call__�szUnconditionallyRaise.__call__N�r!r"r#r)r�rrrrry�sryc@seZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zejed�d d!��Zd"d#�Zejed�d$d%��Zejed�d&d'��Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Z d8S)9�FileInputTestscCs�|�d�}|�d�}|�d�}|�d�}t||||fdd�}|��}|�|d�|�|��d�|�|��d�|�|��|�|��}|�|�|�|��d�|�|��d�|�|��|�|��dS)Nr2zThe only line there is.
rrLrCr)	r rr7rarbrcr0rdr>)rrprqrrrsrtr6rrr�test_zero_byte_files�s 




z#FileInputTests.test_zero_byte_filescCs`|�d�}|�d�}t||fdd�}t|�}|�|gd��|�|��d�|�|��d�dS)N�A
B
C�D
E
FrrL��A
�B
�CzD
zE
�F�rS)r rr`rarcrb�rrprqrtr;rrr�%test_files_that_dont_end_with_newline�s

z4FileInputTests.test_files_that_dont_end_with_newlinecCs�|�d�}|�d�}t||fdd�}|�|��d�t|�}|�|��d�|��|�|��d�t|�}|�|��d�dS)NzA
BzC
DrrLr8)r rra�filenor3rmrgr`)rrprqrtr6rrr�test_fileno�s

zFileInputTests.test_filenocCs�z
tddd�}|�d�Wn	tyYnw|jddd�}t�dtf��t|d	dd
�}Wd�n1s7wYt�dtf��t|�}Wd�n1sRwY|�|gd��dS)Nrr)rrz-FileInput should reject invalid mode argument�A
B
C
D�wbrr2�U)rMrr)r�r��C
�D)	r�fail�
ValueErrorr rZcheck_warnings�DeprecationWarningr`ra)rrtrpr;rrr�test_opening_mode�s��
�z FileInputTests.test_opening_modecCs^t�d�� }td�|_tdgdd�}t|�}|�|dg�Wd�dS1s(wYdS)Nz	sys.stdin�spam, bacon, sausage, and spamrU�rb�rMr)r
Zpatchr�bufferrr`ra)rZm_stdinrtr;rrr�test_stdin_binary_mode�s
"�z%FileInputTests.test_stdin_binary_modecCs\tj}z&td�t_|�ttjd��tdgdd�}t|�}|�|dg�W|t_dS|t_w)Nr�r�rUr�r�)rhrirrd�hasattrrr`ra)rZ
orig_stdinrtr;rrr�test_detached_stdin_binary_mode�s
z.FileInputTests.test_detached_stdin_binary_modecCs�ztddd�d�}|�d�Wn	tyYnwztdd�}|�d�Wn	ty.YnwGdd	�d	�}|�d
�}|�}t|g|d��}|��Wd�n1sTwY|�|jd�dS)NrCcSr=r%r)rrvrrr�<lambda>
�z7FileInputTests.test_file_opening_hook.<locals>.<lambda>)rYr1zGFileInput should raise if both inplace and openhook arguments are given�r1z2FileInput should check openhook for being callablec@rx)z=FileInputTests.test_file_opening_hook.<locals>.CustomOpenHookcS�
d|_dSrz)r|r(rrrr)r*zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__c_sd|_t|ddi�S)NTrr)r|r)rr~Zkargsrrrr�szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__Nr�rrrr�CustomOpenHook�r�rZzopenhook not invoked)rr�r�r r7�
assertTruer|)rrtr��tZcustom_open_hookrrr�test_file_opening_hook
s&�
�

�z%FileInputTests.test_file_opening_hookc	Cs2ttd��}|�d�|�dd�|�d�Wd�n1s!wY|�tt�tttd�d��[}z|�|��d�|�|��d	�|�|��d
�Wnt	y]|�
d�Ynw|�t	��t|�Wd�n1srwY|�|��d�|�|��d�Wd�dS1s�wYdS)
Nr�sA
B
C
s
123456789
i����ascii�rMr1r�r�r�zRead to end of filer2)
rrrr�safe_unlinkrrrar7�UnicodeDecodeErrorr��assertRaisesr`�rrrtrrr�
test_readline%s.
���
�"�zFileInputTests.test_readlinecCs�ttd��
}|�d�Wd�n1swY|�tt�ttdd��1}|�|��d�|�|��d�|�|��d�|�|��d�|�|��d�Wd�dS1sZwYdS)	Nr�r�r�r�sA
sB
sC
D�)rrrrr�rrar7r�rrr�test_readline_binary_mode<s�"�z(FileInputTests.test_readline_binary_modecCs�|jddd�}t|ddd��}|��}|�|d�tj�d�Wd�n1s)wYt|d��}|�|��d�Wd�dS1sGwYdS)Ns
Initial text.r�rr�T)rrYs	New line.)	r rr7rarhrjrr�read�rZ	temp_fileZfobjr6rrrr�test_inplace_binary_write_modeIs�"�z-FileInputTests.test_inplace_binary_write_modecCs�|jddd�}t|dddd��}|��}|�|d�td	�Wd�n1s(wYt|d
��}|�|���d�d�Wd�dS1sIwYdS)
NsInitial text �r�rTr��replace)rYr�errorsuInitial text �uNew line ˆr�s
s
New line ?)r rr7rar_rr��rstripr�rrr�test_inplace_encoding_errorsSs�
�"�z+FileInputTests.test_inplace_encoding_errorscCsXdd�}|�d�}t|g|d��}|��}Wd�n1swY|�|d�dS)NcS�
t�d�S)N�(I used to receive only filename and mode)�ior�r0rrrr�old_hook^r*zFFileInputTests.test_file_hook_backward_compatibility.<locals>.old_hookrZr�r�)r rr7ra)rr�r�rt�resultrrr�%test_file_hook_backward_compatibility]s

�z4FileInputTests.test_file_hook_backward_compatibilitycCs�|�d�}|�d�}t||fdd��}t|�}Wd�n1s!wY|�|gd��|�|��d�|�|��d�|�|jd�dS)	Nr�r�rrLr�r�rSr)r rr`rarcrb�_filesr�rrr�test_context_manageres


�z#FileInputTests.test_context_managercCsV|�d�}zt|dd��}t�1swYWdSty*|�|jd�YdSw)Nr2rrLr)r r�OSErrorrar�)rrprtrrr�test_close_on_exceptionos
��z&FileInputTests.test_close_on_exceptioncCs@tgdd��}|�|jd�Wd�dS1swYdS)NrrL)rU)rrar�)rrtrrr�.test_empty_files_list_specified_to_constructorws"�z=FileInputTests.test_empty_files_list_specified_to_constructor)�categorycCsf|�d�}t|gdd��}|d}|�|d�|d}|�|d�Wd�dS1s,wYdS)	zNTests invoking FileInput.__getitem__() with the current
           line number�line1
line2
rrLr�line1
rCzline2
N)r rra)rr�rtZretval1Zretval2rrr�test__getitem__{s
"�zFileInputTests.test__getitem__c	Cs�|�d�}|�td��/t|gd��}|�|dd�Wd�n1s%wYWd�dSWd�dS1s=wYdS)Nr�zUse iterator protocol instead)rMrr�)r ZassertWarnsRegexr�rra)rr�rtrrr�test__getitem___deprecation�s
���"�z*FileInputTests.test__getitem___deprecationc	C�~|�d�}t|gdd��!}|�t��}|dWd�n1s!wYWd�n1s0wY|�|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberr�rrLrCN)zaccessing lines out of order)r rr��RuntimeErrorra�	exceptionr~�rr�rt�cmrrr�test__getitem__invalid_key��

���z)FileInputTests.test__getitem__invalid_keyc	Cr�)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputr2rrLrN)zend of input reached)r rr��
IndexErrorrar�r~r�rrr�test__getitem__eof�r�z!FileInputTests.test__getitem__eofcCs�tj}tt�}z5|�d�}|�t|d�t|gddd��}t|�|t_|�	�Wd�n1s3wYW|t_n|t_w|�
|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 ignoredrZz.bakTrrXNzos.unlink() was not invoked)�osr	ryr�r rr�rr3rgr�r|)rZos_unlink_origZos_unlink_replacementr�rtrrr�%test_nextfile_oserror_deleting_backup�s

���z4FileInputTests.test_nextfile_oserror_deleting_backupcC�|tj}tt�}z)|�d�}t|gddd��}|t_|��Wd�n1s'wYW|t_n|t_w|�|jd�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rZTrrXN�os.fstat() was not invoked)	r��fstatryr�r rr7r�r|)rZ
os_fstat_origZos_fstat_replacementr�rtrrr�%test_readline_os_fstat_raises_OSError��

���z4FileInputTests.test_readline_os_fstat_raises_OSErrorcCr�)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rZTrrXNr�)	r��chmodryr�r rr7r�r|)rZ
os_chmod_origZos_chmod_replacementr�rtrrr�%test_readline_os_chmod_raises_OSError�r�z4FileInputTests.test_readline_os_chmod_raises_OSErrorc	Cs�Gdd�dt�}|�}|�d�}t|gdd��}|j}z||_|��}W||_n||_wWd�n1s6wY|�|jd�|�|dd�dS)	Nc@rx)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcS�t�|t�dSr%)ryr)r�r(rrrr)��zZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|��dSr%)r�r(rrrr���zXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)r!r"r#r)r�rrrr�FilenoRaisesValueError�r�r�rZrrLz_file.fileno() was not invokedr8zfileno() should return -1)ryr r�_filer�r�r|ra)rr�Z unconditionally_raise_ValueErrorr�rtZfile_backupr�rrr�"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�dS1sowYdS�Nzline1
line2zline3
r�r�Zline2r2)r$rr1rar+r7�r�srcrtrrr�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�dS1smwYdSr�)r$rr1rar+r3r��
StopIterationr�rrr�test_iteration_bufferings"�"�z'FileInputTests.test_iteration_bufferingcCs�t|�d��}t|dd��.}|��}|�|d�|�|��d�|�|��d�|�|��t�	|��Wd�dS1s>wYdS)N�
Pathlib file.rrrC)
rr rr7rarbrcr0r��fspath)rrprtr6rrr�test_pathlib_files"�z FileInputTests.test_pathlib_filecCs�t|�d��}t|ddd��}|��}|�|d�td|�Wd�n1s)wYt|dd��}|�|��d�Wd�dS1sHwYdS)Nr�Tr)rYrzModified %srzModified Pathlib file.
)rr rr7rar_rr�)rrprtr6rrrr�test_pathlib_file_inplaces�"�z(FileInputTests.test_pathlib_file_inplaceN)!r!r"r#r�r�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��s>









	
		r�c@sfeZdZdZdddddd�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 testsNFr2�r)rr1rr�cCsJ||_||_||_||_||_||_||_d|_t�	dd��|_
i|_dS)NcSsdSr9rrrrrr�1r�z(MockFileInput.__init__.<locals>.<lambda>)rMrY�backuprr1rr�r��collections�defaultdict�invocation_counts�
return_values)rrMrYr�rr1rr�rrrr)'s
zMockFileInput.__init__cCs|jdd7<dS)Nr>rC)r�r(rrrr>4szMockFileInput.closecC�|jdd7<|jdS)NrgrC�r�r�r(rrrrg7�
zMockFileInput.nextfilecCr�)Nr0rCr�r(rrrr0;r�zMockFileInput.filenamecCr�)NrbrCr�r(rrrrb?r�zMockFileInput.linenocCr�)NrcrCr�r(rrrrcCr�zMockFileInput.filelinenocCr�)Nr�rCr�r(rrrr�Gr�zMockFileInput.filenocCr�)NrerCr�r(rrrreKr�zMockFileInput.isfirstlinecCr�)NrfrCr�r(rrrrfOr�zMockFileInput.isstdin)NFr2)
r!r"r#�__doc__r)r>rgr0rbrcr�rerfrrrrr�$s�
r�c@�(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�setUpWs
z$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dSr%)r�r�rr�r�r(rrr�tearDown\sz'BaseFileInputGlobalMethodsTest.tearDowncCs2|j|}|�|d|�t|j�}|�|d�dS)NrC)r�rar:)rZmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocation`s

z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)r!r"r#r�r�r�rrrrrr�Ss
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_fileinput_inputz Unit tests for fileinput.input()cCsjt�}t�|_|t_|�t��}t��Wd�n1swY|�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��inputrar�r~�assertIs)r�instancer�rrr�1test_state_is_not_None_and_state_file_is_not_Noneks
�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�rrrrr�-test_state_is_not_None_and_state_file_is_NonexszBTest_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�rr(rrr�test_state_is_None�sz'Test_fileinput_input.test_state_is_NonecCs�t�}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().)rMrYr�rr1rrrMrYr�rr1N)
rr�rrr�rMrYr�rr1)rrMrYr�rr1rr�rrrr�s
�z'Test_fileinput_input.do_test_call_inputN)r!r"r#r�rr
rrrrrrrhs
	rc@� 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�r>�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=Noner>N)r�r�r�r>rrr	rrr�test_state_is_not_None�s
z+Test_fileinput_close.test_state_is_not_NoneN�r!r"r#r�rrrrrrr
�sr
c@r)�Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()cC�Xdt_|�t��}t��Wd�n1swY|�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�rgrar�r~r�rr�rrrr��
�z*Test_fileinput_nextfile.test_state_is_NonecC�Nt�}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.rgN)rr�r�r�r�rgrr)rZnextfile_retvalr�retvalrrrr��
z.Test_fileinput_nextfile.test_state_is_not_NoneNrrrrrr��
rc@r)�Test_fileinput_filenamez#Unit tests for fileinput.filename()cCr)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�r0rar�r~rrrrrr�rz*Test_fileinput_filename.test_state_is_NonecCr)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.r0N)rr�r�r�r�r0rr)rZfilename_retvalrrrrrr�rz.Test_fileinput_filename.test_state_is_not_NoneNrrrrrr�rrc@r)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()cCr)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�rbrar�r~rrrrrr�rz(Test_fileinput_lineno.test_state_is_NonecCr)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.rbN)rr�r�r�r�rbrr)rZ
lineno_retvalrrrrrr�rz,Test_fileinput_lineno.test_state_is_not_NoneNrrrrrr�rrc@r)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()cCr)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�rcrar�r~rrrrrrrz,Test_fileinput_filelineno.test_state_is_NonecCr)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.rcN)rr�r�r�r�rcrr)rZfilelineno_retvalrrrrrrrz0Test_fileinput_filelineno.test_state_is_not_NoneNrrrrrrrrc@r)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()cCr)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�rar�r~rrrrrr)rz(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)	rr�r��
fileno_retvalr�r�r�rr)rrrrrrrr3s
z,Test_fileinput_fileno.test_state_is_not_NoneNrrrrrr&rrc@r)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()cCr)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�rerar�r~rrrrrrErz-Test_fileinput_isfirstline.test_state_is_NonecCr)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.reN)rr�r�r�r�rerr)rZisfirstline_retvalrrrrrrOrz1Test_fileinput_isfirstline.test_state_is_not_NoneNrrrrrrBrrc@r)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()cCr)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�rfrar�r~rrrrrr`rz)Test_fileinput_isstdin.test_state_is_NonecCr)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.rfN)rr�r�r�r�rfrr)rZisstdin_retvalrrrrrrjrz-Test_fileinput_isstdin.test_state_is_not_NoneNrrrrrr ]rr c@rx)�InvocationRecordercCr�r9)�invocation_countr(rrrr)zr*zInvocationRecorder.__init__cOs"|jd7_||f|_t�d�S)NrCs
some bytes)r"�last_invocationr�rr}rrrr�}s

zInvocationRecorder.__call__Nr�rrrrr!xsr!c@s�eZdZdZdd�Zdd�Zdd�Ze�e	d�d	d
��Z
e�e	d�dd��Ze�ed
�dd��Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��Zd S)!�Test_hook_compressedz*Unit tests for fileinput.hook_compressed()cCst�|_dSr%)r!�	fake_openr(rrrr��r�zTest_hook_compressed.setUpcC�|�dd�dS)Nr2r���do_test_use_builtin_open_textr(rrr�test_empty_string�r�z&Test_hook_compressed.test_empty_stringcCr&�N�abcdr�r'r(rrr�test_no_ext�r�z Test_hook_compressed.test_no_extzRequires gzip and zlibcC�Vtj}|jt_zt�dd�}W|t_n|t_w|�|jjd�|�|jjdif�dS)N�test.gzr�rC)r.r�)�gziprr%r��hook_compressedrar"r#�r�
original_openr�rrr�test_gz_ext_fake��z%Test_hook_compressed.test_gz_ext_fakecCsJtj}dd�t_z
tjdddd�}W|t_n|t_w|�t|�dg�dS)NcSr�)NsEx-binary string)r�rr�rrrr��s
zATest_hook_compressed.test_gz_with_encoding_fake.<locals>.<lambda>r.r�rrzEx-binary string)r/rr�r0rar`r1rrr�test_gz_with_encoding_fake�s
z/Test_hook_compressed.test_gz_with_encoding_fakezRequires bz2cCr-)N�test.bz2r�rC)r6r�)�bz2ZBZ2Filer%r�r0rar"r#r1rrr�test_bz2_ext_fake�r4z&Test_hook_compressed.test_bz2_ext_fakecCr&)Nz	abcd.blahr���do_test_use_builtin_open_binaryr(rrr�
test_blah_ext�r�z"Test_hook_compressed.test_blah_extcCr&)Nzabcd.Gzr�r9r(rrr�test_gz_ext_builtin�r�z(Test_hook_compressed.test_gz_ext_builtincCr&)Nzabcd.Bz2r�r9r(rrr�test_bz2_ext_builtin�r�z)Test_hook_compressed.test_bz2_ext_builtincCr&)Nr+r�r9r(rrr�test_binary_mode_encoding�r�z.Test_hook_compressed.test_binary_mode_encodingcCr&r*r'r(rrr�test_text_mode_encoding�r�z,Test_hook_compressed.test_text_mode_encodingc	Csf|�|j�}z
t�||�}W|�|�n|�|�w|�|jjd�|�|jj||fddd�f�dS)NrC�rr���replace_builtin_openr%r�r0rar"r#�rr0rr2r�rrrr:��
�z4Test_hook_compressed.do_test_use_builtin_open_binaryc	Csf|�|j�}z
t�||�}W|�|�n|�|�w|�|jjd�|�|jj||fddd�f�dS)NrC�localer@rArCrrrr(�rDz2Test_hook_compressed.do_test_use_builtin_open_textcCstj}|t_|Sr%)�builtinsr)Z
new_open_funcr2rrrrB�sz)Test_hook_compressed.replace_builtin_openN)r!r"r#r�r�r)r,�unittestZ
skipUnlessr/r3r5r7r8r;r<r=r>r?r:r(�staticmethodrBrrrrr$�s(




	
r$c@r�)	�Test_hook_encodedz'Unit tests for fileinput.hook_encoded()cCs�t�}t�}tj||d�}t�}tj}|t_zt�}t�}|||�}W|t_n|t_w|�|jd�|j\}	}
|�	|	d|�|�	|	d|�|�	|
�
d�|�|�	|
�
d�|�|�|
�dS)N�r�rCrrr�)rr�rr!rFrrar"r#r�poprd)rrr�r�r%r2r0rZopen_resultr~rrrr�test�s$
zTest_hook_encoded.testcs�ttd��
}|�d�Wd�n1swY��tt��fdd�}|ddg���t��|ddg�Wd�n1sBwY|dd	g�|d
dg�dS)Nr�s�abccsNttdtd|d�d��}t|�}Wd�n1swY��||�dS)Nr�rrJ�rMrr1�rrrr`ra)r��expected_linesrtr;r(rr�check�s
�
�z,Test_hook_encoded.test_errors.<locals>.check�ignore�abc�strictr�u�abc�backslashreplacez\x80abc)rrrrr�r�r��rrrPrr(r�test_errors�s��zTest_hook_encoded.test_errorscsttd��
}|�d�Wd�n1swY��tt��fdd�}|dgd����t��|dgd��Wd�n1sDwY��t��|dgd��Wd�n1s`wY��t��|d	gd
��Wd�dS1s}wYdS)Nr�s
A
B
C
D+IKw-csJtt|td�d��}t|�}Wd�n1swY��||�dS)Nzutf-7rMrN)rrOrtr;r(rrrPs�
�z+Test_hook_encoded.test_modes.<locals>.checkr�)r�r�r��D€ZrUr�r�)r�zB
zC
rW)	rrrrr�ZassertWarnsr�r�r�rUrr(r�
test_modess���"�zTest_hook_encoded.test_modesN)r!r"r#r�rLrVrXrrrrrI�s
rIc@r@)�MiscTestcCr�r%)rZcheck__all__r�r(rrr�test_allr�zMiscTest.test_allN)r!r"r#rZrrrrrYsrY�__main__)5r�r�r�rhr]r�r�rFrrGr7�ImportErrorr/rrrrZpathlibrZtest.supportrZtest.support.os_helperrr	r�r
rrLrr
rr$ZTestCaserAryr�r�r�rr
rrrrrrr r!r$rIrYr!�mainrrrr�<module>sn��$Ss/?YA
�