Your IP : 216.73.216.196


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-2.pyc

o

0�i���@sr	ddlZddlZddlZddlZddlZddlZddlZddlZddlZzddl	Z	Wne
y6dZ	YnwzddlZWne
yHdZYnwddlmZm
Z
ddlmZmZddlmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddlmZGdd
�d
�ZGdd�d�ZGdd�deej�Z Gdd�d�Z!Gdd�deej�Z"Gdd�d�Z#Gdd�dej�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+e$�Z-Gd,d-�d-�Z.Gd.d/�d/ej�Z/Gd0d1�d1ej�Z0Gd2d3�d3ej�Z1e2d4k�r7e�3�dSdS)5�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)�categorycCsh	|�d�}t|gdd��}|d}|�|d�|d}|�|d�Wd�dS1s-wYdS)N�line1
line2
rrLr�line1
rCzline2
)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�n1s1wY|�|jjd�dS)Nr�rrLrC)zaccessing lines out of order)r rr��RuntimeErrorra�	exceptionr~�rr�rt�cmrrr�test__getitem__invalid_key��

���z)FileInputTests.test__getitem__invalid_keyc	Cr�)Nr2rrLr)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�n1s4wYW|t_n|t_w|�
|jd�dS)NrZz.bakTrrXzos.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�NrZTrrXzos.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�r�)	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@sdeZdZ	dddddd�dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Z	dd�Z
dd�ZdS)�
MockFileInputNFr2�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#r)r>rgr0rbrcr�rerfrrrrr�$s�
r�c@�&eZdZ	dd�Zdd�Zdd�ZdS)�BaseFileInputGlobalMethodsTestcCstj|_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�rrrrr�Ss
r�c@s.eZdZ	dd�Zdd�Zdd�Zdd�Zd	S)
�Test_fileinput_inputcCsl	t�}t�|_|t_|�t��}t��Wd�n1swY|�d|j	j
�|�|tjd�dS)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_NonecCs 	t�}d|_|t_|��dSr%)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_NonecCs	dt_|��dSr%)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)N)rMrYr�rr1rrrMrYr�rr1)
rr�rrr�rMrYr�rr1)rrMrYr�rr1rr�rrrr�s 
�z'Test_fileinput_input.do_test_call_inputN)r!r"r#rr	r
rrrrrrhs
	rc@�eZdZ	dd�Zdd�ZdS)�Test_fileinput_closecCs 	dt_t��|�tj�dSr%)r�r�r>�assertIsNoner(rrrr
�sz'Test_fileinput_close.test_state_is_NonecCs2	t�}|t_t��|�|d�|�tj�dS)Nr>)r�r�r�r>r�r
rrrr�test_state_is_not_None�sz+Test_fileinput_close.test_state_is_not_NoneN�r!r"r#r
rrrrrr�src@r)�Test_fileinput_nextfilecC�Z	dt_|�t��}t��Wd�n1swY|�d|jj�|�tj�dS�N)zno active input())	r�r�r�r�rgrar�r~r
�rr�rrrr
��
�z*Test_fileinput_nextfile.test_state_is_NonecC�P	t�}t�}||jd<|t_t��}|�|d�|�||�|�tj|�dS)Nrg)rr�r�r�r�rgr�r)rZnextfile_retvalr�retvalrrrr��
z.Test_fileinput_nextfile.test_state_is_not_NoneNrrrrrr��
rc@r)�Test_fileinput_filenamecCrr)	r�r�r�r�r0rar�r~r
rrrrr
�rz*Test_fileinput_filename.test_state_is_NonecCr)Nr0)rr�r�r�r�r0r�r)rZfilename_retvalrrrrrr�rz.Test_fileinput_filename.test_state_is_not_NoneNrrrrrr�rrc@r)�Test_fileinput_linenocCrr)	r�r�r�r�rbrar�r~r
rrrrr
�rz(Test_fileinput_lineno.test_state_is_NonecCr)Nrb)rr�r�r�r�rbr�r)rZ
lineno_retvalrrrrrr�rz,Test_fileinput_lineno.test_state_is_not_NoneNrrrrrr�rrc@r)�Test_fileinput_filelinenocCrr)	r�r�r�r�rcrar�r~r
rrrrr
rz,Test_fileinput_filelineno.test_state_is_NonecCr)Nrc)rr�r�r�r�rcr�r)rZfilelineno_retvalrrrrrrrz0Test_fileinput_filelineno.test_state_is_not_NoneNrrrrrrrrc@r)�Test_fileinput_filenocCrr)	r�r�r�r�r�rar�r~r
rrrrr
)rz(Test_fileinput_fileno.test_state_is_NonecCsV	t�}t�}||jd<||_|t_t��}|�|d�|�||�|�tj|�dS)Nr�)	rr�r��
fileno_retvalr�r�r�r�r)rrrrrrrr3s
z,Test_fileinput_fileno.test_state_is_not_NoneNrrrrrr&rrc@r)�Test_fileinput_isfirstlinecCrr)	r�r�r�r�rerar�r~r
rrrrr
Erz-Test_fileinput_isfirstline.test_state_is_NonecCr)Nre)rr�r�r�r�rer�r)rZisfirstline_retvalrrrrrrOrz1Test_fileinput_isfirstline.test_state_is_not_NoneNrrrrrrBrrc@r)�Test_fileinput_isstdincCrr)	r�r�r�r�rfrar�r~r
rrrrr
`rz)Test_fileinput_isstdin.test_state_is_NonecCr)Nrf)rr�r�r�r�rfr�r)rZisstdin_retvalrrrrrrjrz-Test_fileinput_isstdin.test_state_is_not_NoneNrrrrrr]rrc@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�eZdZ	dd�Zdd�Zdd�Ze�ed�dd	��Z	e�ed�d
d��Z
e�ed�d
d��Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zedd��ZdS) �Test_hook_compressedcCs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�r/rar`r0rrr�test_gz_with_encoding_fake�s
z/Test_hook_compressed.test_gz_with_encoding_fakezRequires bz2cCr,)N�test.bz2r�rC)r5r�)�bz2ZBZ2Filer$r�r/rar!r"r0rrr�test_bz2_ext_fake�r3z&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�r8r(rrr�test_gz_ext_builtin�r�z(Test_hook_compressed.test_gz_ext_builtincCr%)Nzabcd.Bz2r�r8r(rrr�test_bz2_ext_builtin�r�z)Test_hook_compressed.test_bz2_ext_builtincCr%)Nr*r�r8r(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�r/rar!r"�rr0rr1r�rrrr9��
�z4Test_hook_compressed.do_test_use_builtin_open_binaryc	Csf|�|j�}z
t�||�}W|�|�n|�|�w|�|jjd�|�|jj||fddd�f�dS)NrC�localer?r@rBrrrr'�rCz2Test_hook_compressed.do_test_use_builtin_open_textcCstj}|t_|Sr%)�builtinsr)Z
new_open_funcr1rrrrA�sz)Test_hook_compressed.replace_builtin_openN)r!r"r#r�r(r+�unittestZ
skipUnlessr.r2r4r6r7r:r;r<r=r>r9r'�staticmethodrArrrrr#�s(




	
r#c@r�)�Test_hook_encodedcCs�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 rErrar!r"r�poprd)rrr�r�r$r1r0rZopen_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�rrI�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��rrrOrr(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-7rLrM)rrNrtr;r(rrrOs�
�z+Test_hook_encoded.test_modes.<locals>.checkr�)r�r�r��D€ZrUr�r�)r�zB
zC
rV)	rrrrr�ZassertWarnsr�r�r�rTrr(r�
test_modess���"�zTest_hook_encoded.test_modesN)r!r"r#rKrUrWrrrrrH�s
rHc@r@)�MiscTestcCr�r%)rZcheck__all__r�r(rrr�test_allr�zMiscTest.test_allN)r!r"r#rYrrrrrXsrX�__main__)4r�r�rhr]r�r�rErrFr6�ImportErrorr.rrrrZpathlibrZtest.supportrZtest.support.os_helperrr	r�r
rrKrr
rr$ZTestCaserAryr�r�r�rrrrrrrrrr r#rHrXr!�mainrrrr�<module>sn��$Ss/?YA
�