HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_fileinput.cpython-37.pyc
B

��g-��@sPdZddlZddlZddlZddlZddlZddlZddlZddlZyddl	Z	Wne
k
rhdZ	YnXy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||��}|�|�WdQRX|S)N)�tempfileZmkstemp�
addCleanuprr
�open�write)�selfZcontentr�fd�name�f�r�//usr/local/lib/python3.7/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|_dS)N)�
_linesread)rrrr�__init__1szLineReader.__init__cCsz|jdd�Sg|_XdS)N)r)rrrr�	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���cCsDg}d}x6|��}|s|S|�|�|t|�7}||kr
|Sq
WdS)Nr)r,r)�len)rZhint�linesr*r+rrr�	readlinesDs
zLineReader.readlinescCsdS)Nr)rrrr�closePszLineReader.close)N)r-)
rrrr �propertyr!r&r,r0r1rrrrr/s

rc@seZdZdd�Zddd�ZdS)�BufferSizesTestsc
Cs�x�dD]�\}}|�d�dd�td�D���}|�d�dd�td�D���}|�d�dd�td	�D���}|�d�d
d�td�D���}|r�|�t��|�||||||�WdQRXq|�||||||�qWdS)N))rr)��r'css|]}d|dVqdS)zLine %s of file 1
r4Nr)�.0�irrr�	<genexpr>Wsz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>�css|]}d|dVqdS)zLine %s of file 2
r4Nr)r6r7rrrr8Xs�
css|]}d|dVqdS)zLine %s of file 3
r4Nr)r6r7rrrr8Ys�css|]}d|dVqdS)zLine %s of file 4
r4Nr)r6r7rrrr8Zsr4)r�join�range�assertWarns�DeprecationWarning�buffer_size_test)r�round�bs�t1�t2�t3�t4rrr�test_buffer_sizesTs z"BufferSizesTests.test_buffer_sizesrcCsrt�d�}d|d}tr.td|d|f�t||||f|d�}	t|	�}
|	��|�t|
�d�|�|
dd	�|�|
d
d�|�|	�	�d�|�|	�
�|�tr�td|d|f�t||||f|d�}	d
}x|r�|dkr�|	��}q�W|�|	�
�|�|�|	�	�d�|�|	��d�|�
|	���|�
|	���t�rRtd|d|f�|	��|�|	��d�|�|	�	�d�|	��t�r�td|d|f�t||||df|d�}	tj}zNtd�t_t|	�}
|�t|
�d�|�|
dd�|�|	�
�d�|	��Wd|t_Xt�r*td|d|f�t||||f|d�}	|�|	�	�d�|�|	�
�d�|	��|�|	�	�d�|�|	�
�d�t�r�td|d|f�tj}
zJt||||fd|d�}	x&|	D]}|dd ���}t|��q�W|	��Wd|
t_Xt||||f|d�}	xV|	D]N}|�|d d!�|�|dd ��}|�|d�|�t|�d��|	����qW|	��dS)"NzLINE (\d+) OF FILE (\d+)r4�z%s. Simple iteration (bs=%s)r)�files�bufsize��zLine 5 of file 1
r5zLine 1 of file 4
z%s. Status variables (bs=%s)�xzLine 6 of file 2
�z%s. Nextfile (bs=%s)�zLine 1 of file 3
�z%s. Stdin (bs=%s)��-z Line 1 of stdin
Line 2 of stdin
�!� zLine 2 of stdin
z<stdin>z%s. Boundary conditions (bs=%s)z%s. Inplace (bs=%s)r;)rI�inplacerJr-�
)�re�compiler�printr�listr1�assertEqualr.�linenor%r,�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)rrCrDrErFrBrAZpat�start�fir/�sZ	savestdinZ
savestdoutr+�mrrrr@as�



 z!BufferSizesTests.buffer_size_testN)rr)rrrrGr@rrrrr3Ss
r3c@seZdZdd�Zdd�ZdS)�UnconditionallyRaisecCs||_d|_dS)NF)�exception_type�invoked)rrorrrr �szUnconditionallyRaise.__init__cOsd|_|���dS)NT)rpro)r�args�kwargsrrr�__call__�szUnconditionallyRaise.__call__N)rrrr rsrrrrrn�srnc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Ze�eed#�d$�d%d&��Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1S)2�FileInputTestscCs�|�d�}|�d�}|�d�}|�d�}t||||fd�}|��}|�|d�|�|��d�|�|��d�|�|��|�|��}|�|�|�|��d�|�|��d�|�|��|�|��dS)Nr'zThe only line there is.
)rIr4r)	rrr,r[r\r]r%r^r1)rrCrDrErFrkr+rrr�test_zero_byte_files�s 




z#FileInputTests.test_zero_byte_filesc	Csf|�d�}|�d�}t||fd�}t|�}|�|dddddd	g�|�|��d
�|�|��d�dS)NzA
B
CzD
E
F)rIzA
zB
�CzD
zE
�FrQrH)rrrZr[r]r\)rrCrDrkr/rrr�%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
D)rIr-)rrr[�filenor(rgrarZ)rrCrDrkr+rrr�test_fileno�s

zFileInputTests.test_filenoc	Cs�ytdd�}|�d�Wntk
r,YnX|jddd�}tdtf��t|dd�}WdQRXtdtf��t|�}WdQRX|�|d	d
ddg�dS)
Nr)rz-FileInput should reject invalid mode argumentsA
B
C
D�wbr'�U)rIrzA
zB
zC
�D)r�fail�
ValueErrorrr	r?rZr[)rrkrCr/rrr�test_opening_mode�s
z FileInputTests.test_opening_modec	CsHt�d��4}td�|_tdgdd�}t|�}|�|dg�WdQRXdS)Nz	sys.stdinsspam, bacon, sausage, and spamrR�rb)rIr)rZpatchr�bufferrrZr[)rZm_stdinrkr/rrr�test_stdin_binary_mode�s

z%FileInputTests.test_stdin_binary_modecCsXtj}zDtd�t_|�ttjd��tdgdd�}t|�}|�|dg�Wd|t_XdS)Nsspam, bacon, sausage, and spamr�rRr�)rIr)rbrcrr^�hasattrrrZr[)rZ
orig_stdinrkr/rrr�test_detached_stdin_binary_modes
z.FileInputTests.test_detached_stdin_binary_modec	Cs�ytddd�d�}|�d�Wntk
r2YnXytdd�}|�d�Wntk
r`YnXGdd	�d	�}|�d
�}|�}t|g|d��}|��WdQRX|�|jd�dS)Nr4cSsdS)Nr)rrmrrr�<lambda>�z7FileInputTests.test_file_opening_hook.<locals>.<lambda>)rUr&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|_dS)NF)rp)rrrrr szFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__cWsd|_t|�S)NT)rpr)rrqrrrrsszFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__N)rrrr rsrrrr�CustomOpenHooksr�rVzopenhook not invoked)rr~rrr,�
assertTruerp)rrkr��tZcustom_open_hookrrr�test_file_opening_hook
s 

z%FileInputTests.test_file_opening_hookc
Cs�ttd��(}|�d�|�dd�|�d�WdQRX|�tt�tttd�d���}y4|�|��d�|�|��d	�|�|��d
�Wnt	k
r�|�
d�YnX|�t	��t|�WdQRX|�|��d�|�|��d�WdQRXdS)
Nr{sA
B
C
s
123456789
i����ascii)rIr&zA
zB
zC
zRead to end of filer')
rrrr�safe_unlinkrrr[r,�UnicodeDecodeErrorr~�assertRaisesrZ)rrrkrrr�
test_readline(s"
zFileInputTests.test_readlinec	Cs�ttd��}|�d�WdQRX|�tt�ttdd��V}|�|��d�|�|��d�|�|��d�|�|��d�|�|��d�WdQRXdS)	Nr{sA
B
C
Dr�)rIrsA
sB
sC
Dr�)rrrrr�rr[r,)rrrkrrr�test_readline_binary_mode?sz(FileInputTests.test_readline_binary_modec	Cs�|�d�}|�d�}t||fd��}t|�}WdQRX|�|dddddd	g�|�|��d
�|�|��d�|�|jd�dS)
NzA
B
CzD
E
F)rIzA
zB
rvzD
zE
rwrQrHr)rrrZr[r]r\�_files)rrCrDrkr/rrr�test_context_managerLs

z#FileInputTests.test_context_managerc	CsP|�d�}yt|d��
}t�WdQRXWn"tk
rJ|�|jd�YnXdS)Nr')rIr)rr�OSErrorr[r�)rrCrkrrr�test_close_on_exceptionVs
z&FileInputTests.test_close_on_exceptionc	Cs(tgd��}|�|jd�WdQRXdS)N)rI)rR)rr[r�)rrkrrr�.test_empty_files_list_specified_to_constructor^sz=FileInputTests.test_empty_files_list_specified_to_constructorc	CsN|�d�}t|gd��.}|d}|�|d�|d}|�|d�WdQRXdS)zNTests invoking FileInput.__getitem__() with the current
           line numberzline1
line2
)rIrzline1
r4zline2
N)rrr[)rr�rkZretval1Zretval2rrr�test__getitem__bs
zFileInputTests.test__getitem__c
CsT|�d�}t|gd��$}|�t��}|dWdQRXWdQRX|�|jjd�dS)zZTests invoking FileInput.__getitem__() with an index unequal to
           the line numberzline1
line2
)rIr4N)zaccessing lines out of order)rrr��RuntimeErrorr[�	exceptionrq)rr�rk�cmrrr�test__getitem__invalid_keyls

z)FileInputTests.test__getitem__invalid_keyc
CsT|�d�}t|gd��$}|�t��}|dWdQRXWdQRX|�|jjd�dS)zZTests invoking FileInput.__getitem__() with the line number but at
           end-of-inputr')rIrN)zend of input reached)rrr��
IndexErrorr[r�rq)rr�rkr�rrr�test__getitem__eofus

z!FileInputTests.test__getitem__eofc	Csztj}tt�}zP|�d�}|�tj|d�t|gdd��}t|�|t_|�	�WdQRXWd|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 ignoredrVz.bakT)rIrUNzos.unlink() was not invoked)�osr
rnr�rrrrr(rar�rp)rZos_unlink_origZos_unlink_replacementr�rkrrr�%test_nextfile_oserror_deleting_backup~s
z4FileInputTests.test_nextfile_oserror_deleting_backupc	Cs`tj}tt�}z6|�d�}t|gdd��}|t_|��WdQRXWd|t_X|�|jd�dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rVT)rIrUNzos.fstat() was not invoked)	r��fstatrnr�rrr,r�rp)rZ
os_fstat_origZos_fstat_replacementr�rkrrr�%test_readline_os_fstat_raises_OSError�s
z4FileInputTests.test_readline_os_fstat_raises_OSError�chmodzos.chmod does not existc	Cs`tj}tt�}z6|�d�}t|gdd��}|t_|��WdQRXWd|t_X|�|jd�dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rVT)rIrUNzos.fstat() was not invoked)	r�r�rnr�rrr,r�rp)rZ
os_chmod_origZos_chmod_replacementr�rkrrr�%test_readline_os_chmod_raises_OSError�s
z4FileInputTests.test_readline_os_chmod_raises_OSErrorc	CszGdd�dt�}|�}|�d�}t|gd��(}|j}z||_|��}Wd||_XWdQRX|�|jd�|�|dd�dS)Nc@seZdZdd�Zdd�ZdS)zQFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorcSst�|t�dS)N)rnr r)rrrrr �szZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__cSs|��dS)N)rs)rrrrry�szXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.filenoN)rrrr ryrrrr�FilenoRaisesValueError�sr�rV)rIz_file.fileno() was not invokedr-zfileno() should return -1)rnrr�_fileryr�rpr[)rr�Z unconditionally_raise_ValueErrorr�rkZfile_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�WdQRXdS)Nzline1
line2zline3
)rIr&zline1
�line2r')rrr&r[r!r,)r�srcrkrrr�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�WdQRXdS)Nzline1
line2zline3
)rIr&zline1
r�r')rrr&r[r!r(r��
StopIteration)rr�rkrrr�test_iteration_buffering�sz'FileInputTests.test_iteration_bufferingc	Cspt|�d��}t|��P}|��}|�|d�|�|��d�|�|��d�|�|��t�	|��WdQRXdS)Nz
Pathlib file.r4)
rrrr,r[r\r]r%r��fspath)rrCrkr+rrr�test_pathlib_file�s
z FileInputTests.test_pathlib_filec	Csnt|�d��}t|dd��&}|��}|�|d�td|�WdQRXt|��}|�|��d�WdQRXdS)Nz
Pathlib file.T)rUzModified %szModified Pathlib file.
)rrrr,r[rYr�read)rrCrkr+rrrr�test_pathlib_file_inplace�s
z(FileInputTests.test_pathlib_file_inplaceN)rrrrurxrzr�r�r�r�r�r�r�r�r�r�r�r�r�r��unittestZskipIfr�r�r�r�r�r�r�r�rrrrrt�s.


			rtc@sZeZdZdZddd�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�rcCsD||_||_||_||_||_||_d|_t�dd��|_	i|_
dS)NcSsdS)Nrrrrrrr�r�z(MockFileInput.__init__.<locals>.<lambda>)rIrU�backuprJrr&r��collections�defaultdict�invocation_counts�
return_values)rrIrUr�rJrr&rrrr szMockFileInput.__init__cCs|jdd7<dS)Nr1r4)r�)rrrrr1szMockFileInput.closecCs|jdd7<|jdS)Nrar4)r�r�)rrrrraszMockFileInput.nextfilecCs|jdd7<|jdS)Nr%r4)r�r�)rrrrr%szMockFileInput.filenamecCs|jdd7<|jdS)Nr\r4)r�r�)rrrrr\szMockFileInput.linenocCs|jdd7<|jdS)Nr]r4)r�r�)rrrrr] szMockFileInput.filelinenocCs|jdd7<|jdS)Nryr4)r�r�)rrrrry$szMockFileInput.filenocCs|jdd7<|jdS)Nr_r4)r�r�)rrrrr_(szMockFileInput.isfirstlinecCs|jdd7<|jdS)Nr`r4)r�r�)rrrrr`,szMockFileInput.isstdin)NFr'rr�N)
rrr�__doc__r r1rar%r\r]ryr_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_dS)N)�	fileinput�_state�_orig_stater�_orig_FileInputr�)rrrr�setUp4sz$BaseFileInputGlobalMethodsTest.setUpcCs|jt_|jt_dS)N)r�r�rr�r�)rrrr�tearDown9sz'BaseFileInputGlobalMethodsTest.tearDowncCs2|j|}|�|d|�t|j�}|�|d�dS)Nr4)r�r[r.)rZmock_file_inputZmethod_nameZactual_countZactual_total_countrrr�assertExactlyOneInvocation=s

z9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocationN)rrrr�r�r�r�rrrrr�0sr�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�Test_fileinput_inputz Unit tests for fileinput.input()c	CsVt�}t�|_|t_|�t��}t��WdQRX|�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 activezfileinput._state)r��objectr�r�r�r�r��inputr[r�rq�assertIs)r�instancer�rrr�1test_state_is_not_None_and_state_file_is_not_NoneHs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_NoneUszBTest_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�)rrrr�test_state_is_None`sz'Test_fileinput_input.test_state_is_NonecCs�t�}t�}t�}t�}t�}t�}tj||||||d�}|�|tjd�|�||jd�|�||jd�|�||jd�|�||jd�|�||j	d�|�||j
d�d	S)
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().)rIrUr�rJrr&zfileinput._staterIrUr�rJrr&N)r�r�r�r�r�rIrUr�rJrr&)rrIrUr�rJrr&r�rrrr�is 

z'Test_fileinput_input.do_test_call_inputN)rrrr�r�r�r�r�rrrrr�Es

	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�r1�assertIsNone)rrrrr��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=Noner1N)r�r�r�r1r�r�)rr�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��WdQRX|�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�rar[r�rqr�)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.raN)r�r�r�r�r�rar�r�)rZnextfile_retvalr��retvalrrrr��s
z.Test_fileinput_nextfile.test_state_is_not_NoneN)rrrr�r�r�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenamez#Unit tests for fileinput.filename()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�r%r[r�rqr�)rr�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_NoneN)rrrr�r�r�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�r\r[r�rqr�)rr�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_NoneN)rrrr�r�r�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�r]r[r�rqr�)rr�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_NoneN)rrrr�r�r�rrrrr��s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�ryr[r�rqr�)rr�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.ryN)	r�r�r��
fileno_retvalr�r�ryr�r�)rr�r�r�rrrr�s
z,Test_fileinput_fileno.test_state_is_not_NoneN)rrrr�r�r�rrrrr�s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�r_r[r�rqr�)rr�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�.s
z1Test_fileinput_isfirstline.test_state_is_not_NoneN)rrrr�r�r�rrrrr�!s
r�c@s eZdZdZdd�Zdd�ZdS)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()c	CsDdt_|�t��}t��WdQRX|�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._stateN)zno active input())	r�r�r�r�r`r[r�rqr�)rr�rrrr�?s
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�Is
z-Test_fileinput_isstdin.test_state_is_not_NoneN)rrrr�r�r�rrrrr�<s
r�c@seZdZdd�Zdd�ZdS)�InvocationRecordercCs
d|_dS)Nr)�invocation_count)rrrrr XszInvocationRecorder.__init__cOs|jd7_||f|_dS)Nr4)r��last_invocation)rrqrrrrrrsZszInvocationRecorder.__call__N)rrrr rsrrrrr�Wsr�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�|_dS)N)r��	fake_open)rrrrr�aszTest_hook_compressed.setUpcCs|�dd�dS)Nr'r4)�do_test_use_builtin_open)rrrr�test_empty_stringdsz&Test_hook_compressed.test_empty_stringcCs|�dd�dS)NZabcdrO)r�)rrrr�test_no_extgsz Test_hook_compressed.test_no_extzRequires gzip and zlibcCsPtj}|jt_zt�dd�}Wd|t_X|�|jjd�|�|jjdif�dS)Nztest.gzrQr4)ztest.gzrQ)�gziprr�r��hook_compressedr[r�r�)r�
original_openr�rrr�test_gz_ext_fakejsz%Test_hook_compressed.test_gz_ext_fakezRequires bz2cCsPtj}|jt_zt�dd�}Wd|t_X|�|jjd�|�|jjdif�dS)Nztest.bz2rLr4)ztest.bz2rL)�bz2ZBZ2Filer�r�r�r[r�r�)rr�r�rrr�test_bz2_ext_fakevsz&Test_hook_compressed.test_bz2_ext_fakecCs|�dd�dS)Nz	abcd.blahr;)r�)rrrr�
test_blah_ext�sz"Test_hook_compressed.test_blah_extcCs|�dd�dS)Nzabcd.GzrH)r�)rrrr�test_gz_ext_builtin�sz(Test_hook_compressed.test_gz_ext_builtincCs|�dd�dS)Nzabcd.Bz2�)r�)rrrr�test_bz2_ext_builtin�sz)Test_hook_compressed.test_bz2_ext_builtinc	CsV|�|j�}zt�||�}Wd|�|�X|�|jjd�|�|jj||fif�dS)Nr4)�replace_builtin_openr�r�r�r[r�r�)rr%rr�r�rrrr��s
z-Test_hook_compressed.do_test_use_builtin_opencCstj}|t_|S)N)�builtinsr)Z
new_open_funcr�rrrr��sz)Test_hook_compressed.replace_builtin_openN)rrrr�r�r�r�r�Z
skipUnlessr�r�r�r�r�r�r�r��staticmethodr�rrrrr�^s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�}|||�}Wd|t_X|�|jd�|j\}	}
|�	|	d|�|�	|	d|�|�	|
�
d�|�|�	|
�
d�|�|�|
�dS)N)�errorsr4r�encodingr�)r�r�rr�r�rr[r�r�r��popr^)rr�r�r�r�r�r%rZopen_resultrqrrrrr�test�s$
zTest_hook_encoded.testc	s�ttd��}|�d�WdQRX��tt��fdd�}|ddg���t��|ddg�WdQRX|dd	g�|d
dg�dS)Nr{s�abcc	s:ttdtd|d�d��}t|�}WdQRX��||�dS)Nr�zutf-8)r�)rIrr&)rrrrZr[)r��expected_linesrkr/)rrr�check�sz,Test_hook_encoded.test_errors.<locals>.check�ignore�abc�strict�replaceu�abc�backslashreplacez\x80abc)rrrrr�r�r�)rrr�r)rr�test_errors�szTest_hook_encoded.test_errorsc	s�ttd��}|�d�WdQRX��tt��fdd�}|ddddd	g���t��|d
dddd	g�WdQRX��t��|ddddd	g�WdQRX��t��|ddd
dd	g�WdQRXdS)Nr{s
A
B
C
D+IKw-c	s6tt|td�d��}t|�}WdQRX��||�dS)Nzutf-7)rIrr&)rrrrZr[)rr�rkr/)rrrr��sz+Test_hook_encoded.test_modes.<locals>.checkr�zA
zB
zC
uD€ZrUr|r�zB
zC
)	rrrrr�r>r?r�r)rrr�r)rr�
test_modes�szTest_hook_encoded.test_modesN)rrrr�r�r�r�rrrrr��sr�c@seZdZdd�ZdS)�MiscTestcCst�|t�dS)N)rZcheck__all__r�)rrrr�test_all�szMiscTest.test_allN)rrrr�rrrrr��sr��__main__)3r�r�rbrWr�r�r�rr�r��ImportErrorr��iorrrrZpathlibrZtest.supportrrr	r
r�r�rrr
rZTestCaser3rnrtr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�mainrrrr�<module>s^


$[N.A>A