Current File : //usr/local/apps/python3/lib/python3.11/test/__pycache__/test_fileinput.cpython-311.opt-1.pyc
�

�Kej����dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z		ddl
Z
n
#e$rdZ
YnwxYw	ddlZn
#e$rdZYnwxYwddlm
Z
mZddlmZmZddlmZddlmZddlmZddlmZdd	lmZdd
lmZddl	mZGd�d
��ZGd�d��ZGd�dee	j��Z Gd�d��Z!Gd�dee	j��Z"Gd�d��Z#Gd�de	j��Z$Gd�de$��Z%Gd�de$��Z&Gd�de$��Z'Gd �d!e$��Z(Gd"�d#e$��Z)Gd$�d%e$��Z*Gd&�d'e$��Z+Gd(�d)e$��Z,Gd*�d+e$��Z-Gd,�d-��Z.Gd.�d/e	j��Z/Gd0�d1e	j��Z0Gd2�d3e	j��Z1e2d4kre	j3��dSdS)5z,
Tests for fileinput module.
Nick Mathewson
�N)�BytesIO�StringIO)�	FileInput�hook_encoded)�Path)�verbose)�TESTFN)�unlink)�	os_helper)�support)�mockc��eZdZdd�d�ZdS)�	BaseTests�w��modec��tj��\}}|�tj|��d|vrdnd}t|||���5}|�|��ddd��n#1swxYwY|S)N�b�utf-8��encoding)�tempfile�mkstemp�
addCleanuprr
�open�write)�self�contentr�fd�namer�fs       �=/usr/local/apps/python3/lib/python3.11/test/test_fileinput.py�writeTmpzBaseTests.writeTmp+s����#�%�%���D����	�(�$�/�/�/��$�;�;�4�4�G��
�"�d�X�
.�
.�
.�	�!�
�G�G�G����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��s�A3�3A7�:A7N)�__name__�
__module__�__qualname__r#��r"rr(s2������),�������r(rc�F�eZdZd�Zed���Zd�Zd	d�Zd
d�Zd�Z	dS)�
LineReaderc��g|_dS�N��
_linesread�rs r"�__init__zLineReader.__init__5s
������r(c�H�	|jdd�g|_S#g|_wxYwr,r-r/s r"�	linesreadzLineReader.linesread8s1��	!��?�1�1�1�%� �D�O�O��b�D�O� � � � s��	!c�T�t|�d����|_|S�NT)�iter�
splitlines�it)r�filenamers   r"�openhookzLineReader.openhook?s$���x�*�*�4�0�0�1�1����r(Nc�d�t|jd��}|j�|��|S)N�)�nextr7r.�append)r�size�lines   r"�readlinezLineReader.readlineCs.���D�G�R� � ������t�$�$�$��r(���c��g}d}	|���}|s|S|�|��|t|��z
}||kr|S�H�Nr)r@r=�len)r�hint�linesr>r?s     r"�	readlineszLineReader.readlinesHs`������	��=�=�?�?�D��
����L�L������C��I�I��D��t�|�|���	r(c��dSr,r'r/s r"�closezLineReader.closeTs���r(r,)rA)
r$r%r&r0�propertyr2r9r@rGrIr'r(r"r*r*3s�����������!�!��X�!��������

�
�
�
�
�
�
�
�
r(r*c��eZdZd�ZdS)�BufferSizesTestsc��
�|�d�d�td��D������}|�d�d�td��D������}|�d�d�td��D������}|�d�d�td	��D������}tjd
��}t
rt
d��t||||fd�
��}t|��}|�	��|�
t|��d��|�
|dd��|�
|dd��|�
|���d��|�
|�
��|��t
rt
d��t||||fd�
��}d}|r"|dkr|���}|r|dk�|�
|�
��|��|�
|���d��|�
|���d��|�|�����|�|�����t
rt
d��|���|�
|���d��|�
|���d��|�	��t
rt
d��t||||dfd�
��}t(j}		t-d��t(_t|��}|�
t|��d��|�
|dd ��|�
|�
��d!��|���|	t(_n#|	t(_wxYwt
rt
d"��t||||fd�
��}|�
|���d#��|�
|�
��d��|���|�
|���d#��|�
|�
��d��t
rt
d$��t(j}
	t||||fd	d�%��}|D]-}|dd&����}t
|���.|�	��|
t(_n#|
t(_wxYwt||||fd�
��}|D]�}|�
|d&d'��|�|dd&���}|�|d��|�
t7|�d	����|�������|�	��dS)(Nr;c3�&K�|]}d|dzzV��
dS)zLine %s of file 1
�Nr'��.0�is  r"�	<genexpr>z5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>Z�,����"T�"T�Q�#8�A�a�C�#@�"T�"T�"T�"T�"T�"Tr(�c3�&K�|]}d|dzzV��
dS)zLine %s of file 2
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>[rTr(�
c3�&K�|]}d|dzzV��
dS)zLine %s of file 3
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>\�,����"S�"S�Q�#8�A�a�C�#@�"S�"S�"S�"S�"S�"Sr(�c3�&K�|]}d|dzzV��
dS)zLine %s of file 4
rONr'rPs  r"rSz5BufferSizesTests.test_buffer_sizes.<locals>.<genexpr>]rYr(rOzLINE (\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�r]�inplacerrA�
)r#�join�range�re�compiler�printr�listrI�assertEqualrD�linenor8r@�
filelineno�assertFalse�isfirstline�isstdin�nextfile�sys�stdinr�stdout�upper�match�assertNotEqual�int�group)
r�t1�t2�t3�t4�pat�firF�s�	savestdin�
savestdoutr?�ms
             r"�test_buffer_sizesz"BufferSizesTests.test_buffer_sizesXs��
�]�]�2�7�7�"T�"T�%�PR�)�)�"T�"T�"T�T�T�
U�
U��
�]�]�2�7�7�"T�"T�%�PR�)�)�"T�"T�"T�T�T�
U�
U��
�]�]�2�7�7�"S�"S�%�PQ�(�(�"S�"S�"S�S�S�
T�
T��
�]�]�2�7�7�"S�"S�%�PQ�(�(�"S�"S�"S�S�S�
T�
T���j�4�5�5���	)��'�(�(�(�
�b�"�b�"�-��
@�
@�
@���R����
���
�
�
�����U���R�(�(�(�����q��#7�8�8�8�����r��$8�9�9�9���������b�)�)�)����������+�+�+��	)��'�(�(�(�
�b�"�b�"�-��
@�
@�
@�����	�A�-�-�-����
�
�A��	�A�-�-�-����������+�+�+���������b�)�)�)���������!�,�,�,�������)�)�*�*�*���������&�&�&��	!��-� � � �
���
�
�
���������(<�=�=�=���������b�)�)�)�
���
�
�
��	��*����
�b�"�b�"�c�2�W�
E�
E�
E���I�	�	"� �!E�F�F�C�I���H�H�E����S��Z�Z��,�,�,����U�2�Y�(;�<�<�<����R�[�[�]�]�I�6�6�6��K�K�M�M�M�!�C�I�I��	�C�I�!�!�!�!��	,��*�+�+�+�
�b�"�b�"�-��
@�
@�
@����������a�(�(�(����������-�-�-�
���
�
�
���������a�(�(�(����������-�-�-��	 ��,�����Z�
�	$��"�b�"�b�!1�1�w�O�O�O�B��
�
���C�R�C�y���(�(���d������H�H�J�J�J�#�C�J�J���C�J�#�#�#�#�
�b�"�b�"�-��
@�
@�
@���	?�	?�D����T�"�X�t�,�,�,��	�	�$�s��s�)�$�$�A�����4�(�(�(����S�������_�_�b�m�m�o�o�>�>�>�>�
���
�
�
�
�
s�(B#R�R&�+AX�X N)r$r%r&r�r'r(r"rLrLWs(������P�P�P�P�Pr(rLc��eZdZd�Zd�ZdS)�UnconditionallyRaisec�"�||_d|_dS�NF)�exception_type�invoked)rr�s  r"r0zUnconditionallyRaise.__init__�s��,�������r(c�8�d|_|����r4)r�r��r�args�kwargss   r"�__call__zUnconditionallyRaise.__call__�s������!�!�#�#�#r(N�r$r%r&r0r�r'r(r"r�r��s2���������$�$�$�$�$r(r�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�FileInputTestsc��|�d��}|�d��}|�d��}|�d��}t||||fd���}|���}|�|d��|�|���d��|�|���d��|�|���|��|���}|�|��|�|���d��|�|���d��|�|���|��|���dS)Nr;zThe only line there is.
rr\rOr)	r#rr@rqrrrsr8rtrI)rr�r�r�r�r�r?s       r"�test_zero_byte_filesz#FileInputTests.test_zero_byte_files�sl��
�]�]�2�
�
��
�]�]�2�
�
��
�]�]�6�
7�
7��
�]�]�2�
�
��
�b�"�b�"�-��
@�
@�
@���{�{�}�}������:�;�;�;���������a�(�(�(���������!�,�,�,����������+�+�+��{�{�}�}�����������������a�(�(�(���������!�,�,�,����������+�+�+�
���
�
�
�
�
r(c�n�|�d��}|�d��}t||fd���}t|��}|�|gd���|�|���d��|�|���d��dS)N�A
B
C�D
E
Frr\��A
�B
�CzD
zE
�F�rc)r#rrprqrsrr�rr�r�r�rFs     r"�%test_files_that_dont_end_with_newlinez4FileInputTests.test_files_that_dont_end_with_newline�s���
�]�]�9�
%�
%��
�]�]�9�
%�
%��
�b�"�X��
8�
8�
8���R�������� F� F� F�G�G�G���������!�,�,�,���������a�(�(�(�(�(r(c�$�|�d��}|�d��}t||fd���}|�|���d��t	|��}|�|���d��|���|�|���d��t|��}|�|���d��dS)NzA
BzC
Drr\rA)r#rrq�filenor<r}rwrp)rr�r�r�r?s     r"�test_filenozFileInputTests.test_fileno�s���
�]�]�6�
"�
"��
�]�]�6�
"�
"��
�b�"�X��
8�
8�
8����������b�)�)�)��B�x�x�����B�I�I�K�K��,�,�,�
���
�
�
���������b�)�)�)��B�x�x����������b�)�)�)�)�)r(c���dD]r}|�|���5|�t��5t|���ddd��n#1swxYwYddd��n#1swxYwY�sdS)N)r�rU�Ur)�subTest�assertRaises�
ValueErrorr)rrs  r"�test_invalid_opening_modez(FileInputTests.test_invalid_opening_mode�s���$�	)�	)�D����4��(�(�
)�
)��&�&�z�2�2�)�)��4�(�(�(�(�)�)�)�)�)�)�)�)�)�)�)����)�)�)�)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)����
)�
)�
)�
)��	)�	)s4�A*�A�A*�A�A*�A�A*�*A.	�1A.	c��tjd��5}td��|_t	dgd���}t|��}|�|dg��ddd��dS#1swxYwYdS)Nz	sys.stdin�spam, bacon, sausage, and spamre�rb�r]r)r
�patchr�bufferrrprq)r�m_stdinr�rFs    r"�test_stdin_binary_modez%FileInputTests.test_stdin_binary_mode�s���
�Z��
$�
$�	I��$�%F�G�G�G�N��#��T�2�2�2�B���H�H�E����U�%F�$G�H�H�H�		I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I�	I����	I�	I�	I�	I�	I�	Is�A
A/�/A3�6A3c�V�tj}	td��t_|�t	tjd����tdgd���}t
|��}|�|dg��|t_dS#|t_wxYw)Nr�r�rer�r�)rxryrrt�hasattrrrprq)r�
orig_stdinr�rFs    r"�test_detached_stdin_binary_modez.FileInputTests.test_detached_stdin_binary_mode�s����Y�
�	#�� A�B�B�C�I����W�S�Y��9�9�:�:�:��#��T�2�2�2�B���H�H�E����U�%F�$G�H�H�H�"�C�I�I�I��
�C�I�"�"�"�"s�A>B�B(c���	tdd����}|�d��n#t$rYnwxYw	td���}|�d��n#t$rYnwxYwGd�d��}|�d	��}|��}t|g|���5}|���ddd��n#1swxYwY|�|jd
��dS)NrOc��dSr,r')r!r�s  r"�<lambda>z7FileInputTests.test_file_opening_hook.<locals>.<lambda>s��D�r()rir9zGFileInput should raise if both inplace and openhook arguments are given�r9z2FileInput should check openhook for being callablec��eZdZd�Zd�ZdS)�=FileInputTests.test_file_opening_hook.<locals>.CustomOpenHookc��d|_dSr�)r�r/s r"r0zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__init__s
��$����r(c�(�d|_t|ddi�S)NTrr)r�r)rr��kargss   r"r�zFFileInputTests.test_file_opening_hook.<locals>.CustomOpenHook.__call__s��#����T�4�G�4�4�4r(Nr�r'r(r"�CustomOpenHookr�s2������
%�
%�
%�
5�
5�
5�
5�
5r(r�rjzopenhook not invoked)r�failr�r#r@�
assertTruer�)rr�r��t�custom_open_hooks     r"�test_file_opening_hookz%FileInputTests.test_file_opening_hooks���	��1�/@�/@�A�A�A�B��I�I�@�
A�
A�
A�
A���	�	�	��D�	����	��A�&�&�&�B��I�I�J�K�K�K�K���	�	�	��D�	����	5�	5�	5�	5�	5�	5�	5�	5�
�M�M�$����)�>�+�+��
��s�%5�
6�
6�
6�	�"��K�K�M�M�M�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����(�0�2H�I�I�I�I�Is/�'*�
7�7�%A!�!
A.�-A.�/C�C�Cc��ttd��5}|�d��|�ddz��|�d��ddd��n#1swxYwY|�tt��ttt
d�����5}	|�|���d��|�|���d	��|�|���d
��n%#t$r|�
d��YnwxYw|�t��5t|��ddd��n#1swxYwY|�|���d��|�|���d��ddd��dS#1swxYwYdS)
N�wbsA
B
C
s
123456789
i����ascii�r]r9r�r��C
zRead to end of filer;)
rr	rr�safe_unlinkrrrqr@�UnicodeDecodeErrorr�r�rp�rr!r�s   r"�
test_readlinezFileInputTests.test_readlines���
�&�$�
�
�	�1�
�G�G�N�#�#�#�
�G�G�N�T�)�*�*�*�
�G�G�G����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	
����V�,�,�,�
�V� ,�W� 5� 5�7�7�7�	0�:<�
1�� � �������6�6�6�� � �������6�6�6�� � �������6�6�6�6��%�
1�
1�
1��	�	�/�0�0�0�0�0�
1�����"�"�#5�6�6�
�
��R����
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
���R�[�[�]�]�B�/�/�/����R�[�[�]�]�B�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0sn�AA%�%A)�,A)�3G1�5A8D.�-G1�.E�
G1�E�G1�-F	�=G1�	F
	�
G1�F
	�AG1�1G5�8G5c��ttd��5}|�d��ddd��n#1swxYwY|�tt��ttd���5}|�|���d��|�|���d��|�|���d��|�|���d��|�|���d��ddd��dS#1swxYwYdS)	Nr�sA
B
C
Dr�r�sA
sB
sC
Dr()rr	rrr�rrqr@r�s   r"�test_readline_binary_modez(FileInputTests.test_readline_binary_mode2s���
�&�$�
�
�	%�1�
�G�G�O�$�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�����V�,�,�,�
�V�$�
/�
/�
/�	1�2����R�[�[�]�]�F�3�3�3����R�[�[�]�]�H�5�5�5����R�[�[�]�]�G�4�4�4����R�[�[�]�]�C�0�0�0����R�[�[�]�]�C�0�0�0�
	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1�	1����	1�	1�	1�	1�	1�	1s�8�<�<�9C	E�E�Ec��|�dd���}t|dd���5}|���}|�|d��tj�d��ddd��n#1swxYwYt|d��5}|�|���d��ddd��dS#1swxYwYdS)Ns
Initial text.r�rr�T)rris	New line.)	r#rr@rqrxrzrr�read�r�	temp_file�fobjr?r!s     r"�test_inplace_binary_write_modez-FileInputTests.test_inplace_binary_write_mode?sJ���M�M�"2��M�>�>�	�
�y�t�T�
:�
:�
:�	+�d��=�=�?�?�D����T�#3�4�4�4��J���\�*�*�*�		+�	+�	+�	+�	+�	+�	+�	+�	+�	+�	+����	+�	+�	+�	+�
�)�T�
"�
"�	5�a����Q�V�V�X�X�|�4�4�4�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5�	5����	5�	5�	5�	5�	5�	5s$�A
B�B�B�)C�C�Cc���|�dd���}t|ddd���5}|���}|�|d��t	d	��ddd��n#1swxYwYt|d
��5}|�|����d��d��ddd��dS#1swxYwYdS)
NsInitial text �r�rTr��replace)rir�errorsuInitial text �uNew line ˆr�s
s
New line ?)r#rr@rqrorr��rstripr�s     r"�test_inplace_encoding_errorsz+FileInputTests.test_inplace_encoding_errorsIsk���M�M�"6�T�M�B�B�	�
�y�$� '�	�;�;�;�	#�>B��=�=�?�?�D����T�#8�9�9�9��/�"�"�"�		#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#�
�)�T�
"�
"�	F�a����Q�V�V�X�X�_�_�W�5�5�}�E�E�E�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F�	F����	F�	F�	F�	F�	F�	Fs#�:A1�1A5�8A5�<C�C�Cc���d�}|�d��}t|g|���5}|���}ddd��n#1swxYwY|�|d��dS)Nc�*�tjd��S)N�(I used to receive only filename and mode)�ior�r8rs  r"�old_hookzFFileInputTests.test_file_hook_backward_compatibility.<locals>.old_hookTs���;�I�J�J�Jr(rjr�r�)r#rr@rq)rr�r�r��results     r"�%test_file_hook_backward_compatibilityz4FileInputTests.test_file_hook_backward_compatibilitySs���	K�	K�	K��M�M�$����
��s�X�
.�
.�
.�	#�"��[�[�]�]�F�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#�����!K�L�L�L�L�Ls�A�A�Ac���|�d��}|�d��}t||fd���5}t|��}ddd��n#1swxYwY|�|gd���|�|���d��|�|���d��|�|jd��dS)	Nr�r�rr\r�r�rcr')r#rrprqrsrr�_filesr�s     r"�test_context_managerz#FileInputTests.test_context_manager[s��
�]�]�9�
%�
%��
�]�]�9�
%�
%��
�b�"�X��
8�
8�
8�	�B���H�H�E�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����� F� F� F�G�G�G���������!�,�,�,���������a�(�(�(������B�'�'�'�'�'s�A�A�!Ac���|�d��}	t|d���5}t�#1swxYwYdS#t$r|�|jd��YdSwxYw)Nr;rr\r')r#r�OSErrorrqr�)rr�r�s   r"�test_close_on_exceptionz&FileInputTests.test_close_on_exceptiones���
�]�]�2�
�
��	,���g�6�6�6�
�"��
�
�
�
�
����
�
�
�
�
�
���	,�	,�	,����R�Y��+�+�+�+�+�+�	,���s#�=�0�4�=�4�=�%A&�%A&c��tgd���5}|�|jd��ddd��dS#1swxYwYdS)Nrr\)re)rrqr�)rr�s  r"�.test_empty_files_list_specified_to_constructorz=FileInputTests.test_empty_files_list_specified_to_constructorms���
�R�'�
2�
2�
2�	0�b����R�Y��/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s
�;�?�?c���tj}tt��}	|�d��}|�t|dz��t|gdd���5}t|��|t_|�	��ddd��n#1swxYwY|t_n#|t_wxYw|�
|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 ignoredrjz.bakTrrhNzos.unlink() was not invoked)�osr
r�r�r#rr�rr<rwr�r�)r�os_unlink_orig�os_unlink_replacementr�r�s     r"�%test_nextfile_oserror_deleting_backupz4FileInputTests.test_nextfile_oserror_deleting_backupqs��
��� 4�W� =� =��	'��
�
�d�#�#�A��O�O�K��V��4�4�4��!��d�W�E�E�E�
���R����1��	����
�
�
�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�
'�B�I�I���B�I�&�&�&�&�	
���-�5�5�	7�	7�	7�	7�	7s0�AB<�(0B$�B<�$B(�(B<�+B(�,B<�<C
c�z�tj}tt��}	|�d��}t|gdd���5}|t_|���ddd��n#1swxYwY|t_n#|t_wxYw|�|jd��dS)z{Tests invoking FileInput.readline() when os.fstat() raises OSError.
           This exception should be silently discarded.rjTrrhN�os.fstat() was not invoked)	r��fstatr�r�r#rr@r�r�)r�
os_fstat_orig�os_fstat_replacementr�r�s     r"�%test_readline_os_fstat_raises_OSErrorz4FileInputTests.test_readline_os_fstat_raises_OSError������
�3�G�<�<��	%��
�
�d�#�#�A��!��d�W�E�E�E�
��/������
�
�
�
�
�
�
�
�
�
�
�
�
�
����
�
�
�
�%�B�H�H��}�B�H�$�$�$�$�	
���,�4�4�	6�	6�	6�	6�	6�/�(B�
!A7�+B�7A;�;B�>A;�?B�Bc�z�tj}tt��}	|�d��}t|gdd���5}|t_|���ddd��n#1swxYwY|t_n#|t_wxYw|�|jd��dS)z{Tests invoking FileInput.readline() when os.chmod() raises OSError.
           This exception should be silently discarded.rjTrrhNr�)	r��chmodr�r�r#rr@r�r�)r�
os_chmod_orig�os_chmod_replacementr�r�s     r"�%test_readline_os_chmod_raises_OSErrorz4FileInputTests.test_readline_os_chmod_raises_OSError�r�r�c��Gd�dt��}|��}|�d��}t|gd���5}|j}	||_|���}||_n#||_wxYw	ddd��n#1swxYwY|�|jd��|�|dd��dS)	Nc��eZdZd�Zd�ZdS)�QFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueErrorc�F�t�|t��dSr,)r�r0r�r/s r"r0zZFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.__init__�s��$�-�-�d�J�?�?�?�?�?r(c�.�|���dSr,)r�r/s r"r�zXFileInputTests.test_fileno_when_ValueError_raised.<locals>.FilenoRaisesValueError.fileno�s���
�
�����r(N)r$r%r&r0r�r'r(r"�FilenoRaisesValueErrorr�s5������
@�
@�
@�
 �
 �
 �
 �
 r(r	rjrr\z_file.fileno() was not invokedrAzfileno() should return -1)r�r#r�_filer�r�r�rq)rr	� unconditionally_raise_ValueErrorr�r��file_backupr�s       r"�"test_fileno_when_ValueError_raisedz1FileInputTests.test_fileno_when_ValueError_raised�s7��	 �	 �	 �	 �	 �%9�	 �	 �	 �,B�+A�+C�+C�(��M�M�$����
�a�S�7�
3�
3�
3�	'�r��(�K�
'�;���������&�����;���&�&�&�&��
	'�	'�	'�	'�	'�	'�	'�	'�	'�	'�	'����	'�	'�	'�	'�	
���8�@�8�	:�	:�	:�	
�����%@�A�A�A�A�As*�B
�A1�)B
�1	A:�:B
�
B�Bc�b�t��}tddg|j���5}|�|jg��|�|���d��|�|jdg��|�|���d��|�|jdg��|�|���d��|�|jddg��|�|���d��|�|jdg��|�|���d��|�|jg��ddd��dS#1swxYwYdS�Nzline1
line2zline3
r�zline1
�line2r;)r*rr9rqr2r@�r�srcr�s   r"�test_readline_bufferingz&FileInputTests.test_readline_buffering�s����l�l��
�n�i�8� #��.�.�.�	0�13����S�]�B�/�/�/����R�[�[�]�]�I�6�6�6����S�]�Y�K�8�8�8����R�[�[�]�]�G�4�4�4����S�]�W�I�6�6�6����R�[�[�]�]�I�6�6�6����S�]�R��O�<�<�<����R�[�[�]�]�B�/�/�/����S�]�R�D�1�1�1����R�[�[�]�]�B�/�/�/����S�]�B�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s�E0F$�$F(�+F(c�(�t��}tddg|j���5}|�|jg��|�t|��d��|�|jdg��|�t|��d��|�|jdg��|�t|��d��|�|jddg��|�tt
|��|�|jdg��|�tt
|��|�|jg��ddd��dS#1swxYwYdSr)r*rr9rqr2r<r��
StopIterationrs   r"�test_iteration_bufferingz'FileInputTests.test_iteration_buffering�s����l�l��
�n�i�8� #��.�.�.�	0�13����S�]�B�/�/�/����T�"�X�X�y�1�1�1����S�]�Y�K�8�8�8����T�"�X�X�w�/�/�/����S�]�W�I�6�6�6����T�"�X�X�y�1�1�1����S�]�R��O�<�<�<����m�T�2�6�6�6����S�]�R�D�1�1�1����m�T�2�6�6�6����S�]�B�/�/�/�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0�	0����	0�	0�	0�	0�	0�	0s�EF�F�Fc��t|�d����}t|d���5}|���}|�|d��|�|���d��|�|���d��|�|���tj	|����ddd��dS#1swxYwYdS)N�
Pathlib file.rrrO)
rr#rr@rqrrrsr8r��fspath)rr�r�r?s    r"�test_pathlib_filez FileInputTests.test_pathlib_file�s��
�$�-�-��0�0�
1�
1��
�r�G�
,�
,�
,�	;���;�;�=�=�D����T�?�3�3�3����R�Y�Y�[�[�!�,�,�,����R�]�]�_�_�a�0�0�0����R�[�[�]�]�B�I�b�M�M�:�:�:�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;�	;����	;�	;�	;�	;�	;�	;s�B5C6�6C:�=C:c��t|�d����}t|dd���5}|���}|�|d��td|z��ddd��n#1swxYwYt
|d���5}|�|���d��ddd��dS#1swxYwYdS)NrTr)rirzModified %srzModified Pathlib file.
)rr#rr@rqrorr�)rr�r�r?r!s     r"�test_pathlib_file_inplacez(FileInputTests.test_pathlib_file_inplace�s`��
�$�-�-��0�0�
1�
1��
�r�4�'�
:�
:�
:�	(�b��;�;�=�=�D����T�?�3�3�3��-�$�&�'�'�'�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(�	(����	(�	(�	(�	(��"�w�
'�
'�
'�	C�1����Q�V�V�X�X�'A�B�B�B�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C�	C����	C�	C�	C�	C�	C�	Cs#�=A>�>B�B�)C�C�CN)r$r%r&r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrrr'r(r"r�r��s����������()�)�)�(
*�
*�
*�)�)�)�I�I�I�	#�	#�	#�J�J�J�60�0�0�.1�1�1�5�5�5�F�F�F�M�M�M�(�(�(�,�,�,�0�0�0�7�7�7�*6�6�6�$6�6�6�$B�B�B�.0�0�0� 0�0�0� ;�;�;�C�C�C�C�Cr(r�c�V�eZdZdZdddddd�d�Zd�Zd	�Zd
�Zd�Zd�Z	d
�Z
d�Zd�ZdS)�
MockFileInputzDA class that mocks out fileinput.FileInput for use during unit testsNFr;�r)rr9rr�c��||_||_||_||_||_||_||_d|_tj	d���|_
i|_dS)Nc��dSrCr'r'r(r"r�z(MockFileInput.__init__.<locals>.<lambda>s���r()r]ri�backuprr9rr�r
�collections�defaultdict�invocation_counts�
return_values)rr]rir"rr9rr�s        r"r0zMockFileInput.__init__�s]����
���������	� ��
� ��
������
�!,�!8���!C�!C�������r(c�0�|jdxxdz
cc<dS)NrIrO)r%r/s r"rIzMockFileInput.closes'����w�'�'�'�1�,�'�'�'�'�'r(c�F�|jdxxdz
cc<|jdS)NrwrO�r%r&r/s r"rwzMockFileInput.nextfile�/����z�*�*�*�a�/�*�*�*��!�*�-�-r(c�F�|jdxxdz
cc<|jdS)Nr8rOr)r/s r"r8zMockFileInput.filenamer*r(c�F�|jdxxdz
cc<|jdS)NrrrOr)r/s r"rrzMockFileInput.lineno�/����x�(�(�(�A�-�(�(�(��!�(�+�+r(c�F�|jdxxdz
cc<|jdS)NrsrOr)r/s r"rszMockFileInput.filelinenos/����|�,�,�,��1�,�,�,��!�,�/�/r(c�F�|jdxxdz
cc<|jdS)Nr�rOr)r/s r"r�zMockFileInput.filenor-r(c�F�|jdxxdz
cc<|jdS)NrurOr)r/s r"ruzMockFileInput.isfirstlines/����}�-�-�-��2�-�-�-��!�-�0�0r(c�F�|jdxxdz
cc<|jdS)NrvrOr)r/s r"rvzMockFileInput.isstdins/����y�)�)�)�Q�.�)�)�)��!�)�,�,r()NFr;)
r$r%r&�__doc__r0rIrwr8rrrsr�rurvr'r(r"rr�s�������N�N� ��D�4�� � � � � �-�-�-�.�.�.�.�.�.�,�,�,�0�0�0�,�,�,�1�1�1�-�-�-�-�-r(rc�$�eZdZdZd�Zd�Zd�ZdS)�BaseFileInputGlobalMethodsTestzQBase class for unit tests for the global function of
       the fileinput module.c�l�tj|_tj|_t
t_dSr,)�	fileinput�_state�_orig_stater�_orig_FileInputrr/s r"�setUpz$BaseFileInputGlobalMethodsTest.setUp's&��$�+���(�2���+�	���r(c�J�|jt_|jt_dSr,)r9r6rr8r7r/s r"�tearDownz'BaseFileInputGlobalMethodsTest.tearDown,s��"�2�	���+�	���r(c��|j|}|�|d|��t|j��}|�|d��dS)NrO)r%rqrD)r�mock_file_input�method_name�actual_count�actual_total_counts     r"�assertExactlyOneInvocationz9BaseFileInputGlobalMethodsTest.assertExactlyOneInvocation0sU��&�8��E������q�+�6�6�6� ��!B�C�C�����+�Q�/�/�/�/�/r(N)r$r%r&r2r:r<rBr'r(r"r4r4#sK������ � �,�,�,�
,�,�,�0�0�0�0�0r(r4c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�Test_fileinput_inputz Unit tests for fileinput.input()c�l�t��}t��|_|t_|�t��5}tj��ddd��n#1swxYwY|�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
r6r7r��RuntimeError�inputrq�	exceptionr��assertIs)r�instance�cms   r"�1test_state_is_not_None_and_state_file_is_not_NonezFTest_fileinput_input.test_state_is_not_None_and_state_file_is_not_None;s���
!�?�?�������#�	��
�
�
�|�
,�
,�	���O����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����4�b�l�6G�H�H�H��
�
�h�	� 0�2D�E�E�E�E�Es�A(�(A,�/A,c�p�t��}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)rr
r6r7�do_test_call_input�rrLs  r"�-test_state_is_not_None_and_state_file_is_NonezBTest_fileinput_input.test_state_is_not_None_and_state_file_is_NoneHs4��!�?�?�����#�	�����!�!�!�!�!r(c�F�dt_|���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)r6r7rPr/s r"�test_state_is_Nonez'Test_fileinput_input.test_state_is_NoneSs$�� �	�����!�!�!�!�!r(c�<�t��}t��}t��}t��}t��}t��}tj||||||���}|�|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().)r]rir"rr9rrFr]rir"rr9N)
rGr6rIrKr7r]rir"rr9)rr]rir"rr9rr�s        r"rPz'Test_fileinput_input.do_test_call_input\s���
�����(�(�������x�x���8�8���8�8����u�g�f���8�=�=�=��	
�
�
�f�i�.�0B�C�C�C�	
�
�
�e�V�\�7�3�3�3��
�
�g�v�~�y�9�9�9��
�
�f�f�m�X�6�6�6��
�
�d�F�K��0�0�0��
�
�h����<�<�<�<�<r(N)r$r%r&r2rNrRrTrPr'r(r"rDrD8sY������*�*�F�F�F�	"�	"�	"�"�"�"�=�=�=�=�=r(rDc��eZdZdZd�Zd�ZdS)�Test_fileinput_closez Unit tests for fileinput.close()c��dt_tj��|�tj��dS)zPTests that fileinput.close() does nothing if fileinput._state
           is NoneN)r6r7rI�assertIsNoner/s r"rTz'Test_fileinput_close.test_state_is_Nonezs7�� �	����������)�*�+�+�+�+�+r(c���t��}|t_tj��|�|d��|�tj��dS)z`Tests that fileinput.close() invokes close() on fileinput._state
           and sets _state=NonerIN)rr6r7rIrBrYrQs  r"�test_state_is_not_Nonez+Test_fileinput_close.test_state_is_not_None�sV��!�?�?��#�	��������'�'��'�:�:�:����)�*�+�+�+�+�+r(N�r$r%r&r2rTr[r'r(r"rWrWws8������*�*�,�,�,�,�,�,�,�,r(rWc��eZdZdZd�Zd�ZdS)�Test_fileinput_nextfilez#Unit tests for fileinput.nextfile()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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())	r6r7r�rHrwrqrJr�rY�rrMs  r"rTz*Test_fileinput_nextfile.test_state_is_None���� �	��
�
�
�|�
,�
,�	!���� � � �	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!����/���1B�C�C�C����)�*�+�+�+�+�+��A�A�Ac�(�t��}t��}||jd<|t_tj��}|�|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.rwN)rGrr&r6r7rwrBrK)r�nextfile_retvalrL�retvals    r"r[z.Test_fileinput_nextfile.test_state_is_not_None����
!�(�(�� �?�?��-<���z�*�#�	���#�%�%���'�'��*�=�=�=��
�
�f�o�.�.�.��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"r^r^��8������-�-�,�,�,�2�2�2�2�2r(r^c��eZdZdZd�Zd�ZdS)�Test_fileinput_filenamez#Unit tests for fileinput.filename()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHr8rqrJr�rYras  r"rTz*Test_fileinput_filename.test_state_is_None�rbrcc�(�t��}t��}||jd<|t_tj��}|�|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.r8N)rGrr&r6r7r8rBrK)r�filename_retvalrLrfs    r"r[z.Test_fileinput_filename.test_state_is_not_None�rgr(Nr\r'r(r"rjrj�rhr(rjc��eZdZdZd�Zd�ZdS)�Test_fileinput_linenoz!Unit tests for fileinput.lineno()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHrrrqrJr�rYras  r"rTz(Test_fileinput_lineno.test_state_is_None���� �	��
�
�
�|�
,�
,�	�������	�	�	�	�	�	�	�	�	�	�	����	�	�	�	����/���1B�C�C�C����)�*�+�+�+�+�+rcc�(�t��}t��}||jd<|t_tj��}|�|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.rrN)rGrr&r6r7rrrBrK)r�
lineno_retvalrLrfs    r"r[z,Test_fileinput_lineno.test_state_is_not_None�s���
���
� �?�?��+8���x�(�#�	���!�#�#���'�'��(�;�;�;��
�
�f�m�,�,�,��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"roro�s8������+�+�,�,�,�2�2�2�2�2r(roc��eZdZdZd�Zd�ZdS)�Test_fileinput_filelinenoz%Unit tests for fileinput.filelineno()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHrsrqrJr�rYras  r"rTz,Test_fileinput_filelineno.test_state_is_None�s��� �	��
�
�
�|�
,�
,�	#��� �"�"�"�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#�	#����	#�	#�	#�	#����/���1B�C�C�C����)�*�+�+�+�+�+rcc�(�t��}t��}||jd<|t_tj��}|�|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.rsN)rGrr&r6r7rsrBrK)r�filelineno_retvalrLrfs    r"r[z0Test_fileinput_filelineno.test_state_is_not_None�s���
#�H�H�� �?�?��/@���|�,�#�	���%�'�'���'�'��,�?�?�?��
�
�f�/�0�0�0��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"ruru�s8������/�/�,�,�,�2�2�2�2�2r(ruc��eZdZdZd�Zd�ZdS)�Test_fileinput_filenoz!Unit tests for fileinput.fileno()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHr�rqrJr�rYras  r"rTz(Test_fileinput_fileno.test_state_is_None�rqrcc�6�t��}t��}||jd<||_|t_t	j��}|�|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)	rGrr&�
fileno_retvalr6r7r�rBrK)rr}rLrfs    r"r[z,Test_fileinput_fileno.test_state_is_not_Nones���
���
� �?�?��+8���x�(�!.���#�	���!�#�#���'�'��(�;�;�;��
�
�f�m�,�,�,��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"rzrz�s8������+�+�,�,�,�
2�
2�
2�
2�
2r(rzc��eZdZdZd�Zd�ZdS)�Test_fileinput_isfirstlinez&Unit tests for fileinput.isfirstline()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHrurqrJr�rYras  r"rTz-Test_fileinput_isfirstline.test_state_is_Nones��� �	��
�
�
�|�
,�
,�	$���!�#�#�#�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$����/���1B�C�C�C����)�*�+�+�+�+�+rcc�(�t��}t��}||jd<|t_tj��}|�|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.ruN)rGrr&r6r7rurBrK)r�isfirstline_retvalrLrfs    r"r[z1Test_fileinput_isfirstline.test_state_is_not_Nones���
$�X�X�� �?�?��0B���}�-�#�	���&�(�(���'�'��-�@�@�@��
�
�f�0�1�1�1��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"rrs8������0�0�,�,�,�2�2�2�2�2r(rc��eZdZdZd�Zd�ZdS)�Test_fileinput_isstdinz"Unit tests for fileinput.isstdin()c�&�dt_|�t��5}tj��ddd��n#1swxYwY|�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`)	r6r7r�rHrvrqrJr�rYras  r"rTz)Test_fileinput_isstdin.test_state_is_None0s��� �	��
�
�
�|�
,�
,�	 �������	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 ����/���1B�C�C�C����)�*�+�+�+�+�+rcc�(�t��}t��}||jd<|t_tj��}|�|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.rvN)rGrr&r6r7rvrBrK)r�isstdin_retvalrLrfs    r"r[z-Test_fileinput_isstdin.test_state_is_not_None:s���
 ���� �?�?��,:���y�)�#�	���"�$�$���'�'��)�<�<�<��
�
�f�n�-�-�-��
�
�i�&��1�1�1�1�1r(Nr\r'r(r"r�r�-s8������,�,�,�,�,�2�2�2�2�2r(r�c��eZdZd�Zd�ZdS)�InvocationRecorderc��d|_dSrC)�invocation_countr/s r"r0zInvocationRecorder.__init__Js�� !����r(c�\�|xjdz
c_||f|_tjd��S)NrOs
some bytes)r��last_invocationr�rr�s   r"r�zInvocationRecorder.__call__Ms2������"��� $�f�~����z�-�(�(�(r(Nr�r'r(r"r�r�Hs2������"�"�"�)�)�)�)�)r(r�c��eZdZdZd�Zd�Zd�Zeje	d��d���Z
eje	d��d���Zejed��d	���Z
d
�Zd�Zd�Zd
�Zd�Zd�Zd�Zed���ZdS)�Test_hook_compressedz*Unit tests for fileinput.hook_compressed()c�,�t��|_dSr,)r��	fake_openr/s r"r:zTest_hook_compressed.setUpVs��+�-�-����r(c�2�|�dd��dS)Nr;r��do_test_use_builtin_open_textr/s r"�test_empty_stringz&Test_hook_compressed.test_empty_stringYs���*�*�2�s�3�3�3�3�3r(c�2�|�dd��dS�N�abcdrr�r/s r"�test_no_extz Test_hook_compressed.test_no_ext\����*�*�6�3�7�7�7�7�7r(zRequires gzip and zlibc�,�tj}|jt_	tjdd��}|t_n#|t_wxYw|�|jjd��|�|jjdif��dS)N�test.gzrrO)r�r)�gziprr�r6�hook_compressedrqr�r��r�
original_openr�s   r"�test_gz_ext_fakez%Test_hook_compressed.test_gz_ext_fake_s����	�
��N��	�	&��.�y�#�>�>�F�%�D�I�I��
�D�I�%�%�%�%������8�!�<�<�<������7�:J�B�9O�P�P�P�P�P��A�Ac���tj}d�t_	tjddd���}|t_n#|t_wxYw|�t|��dg��dS)Nc�*�tjd��S)NsEx-binary string)r�rr�s  r"r�zATest_hook_compressed.test_gz_with_encoding_fake.<locals>.<lambda>ns��2�:�6I�+J�+J�r(r�rrrzEx-binary string)r�rr6r�rqrpr�s   r"�test_gz_with_encoding_fakez/Test_hook_compressed.test_gz_with_encoding_fakeksq���	�
�J�J��	�	&��.�y�#��P�P�P�F�%�D�I�I��
�D�I�%�%�%�%�����f���(:�';�<�<�<�<�<s	�?�A
zRequires bz2c�,�tj}|jt_	tjdd��}|t_n#|t_wxYw|�|jjd��|�|jjdif��dS)N�test.bz2rrO)r�r)�bz2�BZ2Filer�r6r�rqr�r�r�s   r"�test_bz2_ext_fakez&Test_hook_compressed.test_bz2_ext_fakeus�����
��n���	(��.�z�3�?�?�F�'�C�K�K��-�C�K�'�'�'�'������8�!�<�<�<������7�:K�R�9P�Q�Q�Q�Q�Qr�c�2�|�dd��dS)Nz	abcd.blahr���do_test_use_builtin_open_binaryr/s r"�
test_blah_extz"Test_hook_compressed.test_blah_ext�s���,�,�[�$�?�?�?�?�?r(c�2�|�dd��dS)Nzabcd.Gzr�r�r/s r"�test_gz_ext_builtinz(Test_hook_compressed.test_gz_ext_builtin�s���,�,�Y��=�=�=�=�=r(c�2�|�dd��dS)Nzabcd.Bz2r�r�r/s r"�test_bz2_ext_builtinz)Test_hook_compressed.test_bz2_ext_builtin�s���,�,�Z��>�>�>�>�>r(c�2�|�dd��dS)Nr�r�r�r/s r"�test_binary_mode_encodingz.Test_hook_compressed.test_binary_mode_encoding�s���,�,�V�T�:�:�:�:�:r(c�2�|�dd��dSr�r�r/s r"�test_text_mode_encodingz,Test_hook_compressed.test_text_mode_encoding�r�r(c�T�|�|j��}	tj||��}|�|��n#|�|��wxYw|�|jjd��|�|jj||fddd�f��dS)NrO�rr���replace_builtin_openr�r6r�rqr�r��rr8rr�r�s     r"r�z4Test_hook_compressed.do_test_use_builtin_open_binary�s����1�1�$�.�A�A�
�	5��.�x��>�>�F��%�%�m�4�4�4�4��D�%�%�m�4�4�4�4���������8�!�<�<�<������7�#�T�*���,N�,N�O�	Q�	Q�	Q�	Q�	Q��A�Ac�T�|�|j��}	tj||��}|�|��n#|�|��wxYw|�|jjd��|�|jj||fddd�f��dS)NrO�localer�r�r�s     r"r�z2Test_hook_compressed.do_test_use_builtin_open_text�s����1�1�$�.�A�A�
�	5��.�x��>�>�F��%�%�m�4�4�4�4��D�%�%�m�4�4�4�4���������8�!�<�<�<������7�#�T�*��T�,R�,R�S�	U�	U�	U�	U�	Ur�c�6�tj}|t_|Sr,)�builtinsr)�
new_open_funcr�s  r"r�z)Test_hook_compressed.replace_builtin_open�s�� �
�
�%��
��r(N)r$r%r&r2r:r�r��unittest�
skipUnlessr�r�r�r�r�r�r�r�r�r�r�r��staticmethodr�r'r(r"r�r�Ss]������4�4�.�.�.�4�4�4�8�8�8��X���7�8�8�	Q�	Q�9�8�	Q��X���7�8�8�=�=�9�8�=��X���n�-�-�	R�	R�.�-�	R�@�@�@�>�>�>�?�?�?�;�;�;�8�8�8�	Q�	Q�	Q�	U�	U�	U�����\���r(r�c�$�eZdZdZd�Zd�Zd�ZdS)�Test_hook_encodedz'Unit tests for fileinput.hook_encoded()c���t��}t��}tj||���}t��}tj}|t_	t��}t��}|||��}|t_n#|t_wxYw|�|jd��|j\}	}
|�	|	d|��|�	|	d|��|�	|
�
d��|��|�	|
�
d��|��|�|
��dS)N�r�rOrrr�)rGr6rr�r�rrqr�r�rK�poprt)rrr�r�r�r�r8r�open_resultr�r�s           r"�testzTest_hook_encoded.test�s5���8�8�������'���@�@�@��&�(�(�	� �
�
�!��
�	*��x�x�H��8�8�D� �&��4�0�0�K�)�H�M�M��M�H�M�)�)�)�)�����3�Q�7�7�7� �0���f��
�
�d�1�g�x�(�(�(��
�
�d�1�g�t�$�$�$��
�
�f�j�j��,�,�h�7�7�7��
�
�f�j�j��*�*�F�3�3�3����� � � � � s�(B�Bc���ttd��5}|�d��ddd��n#1swxYwY��tt���fd�}|ddg����t��5|ddg��ddd��n#1swxYwY|ddg��|d	d
g��dS)Nr�s�abcc����ttdtd|������5}t|��}ddd��n#1swxYwY��||��dS)Nrrr��r]rr9�rr	rrprq)r��expected_linesr�rFrs    �r"�checkz,Test_hook_encoded.test_errors.<locals>.check�s������c�$0���$H�$H�$H�J�J�J�
!�MO��R����
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!����
!�
!�
!�
!�
���U�N�3�3�3�3�3s�A�A�A�ignore�abc�strictr�u�abc�backslashreplacez\x80abc)rr	rrr�r�r��rr!r�s`  r"�test_errorszTest_hook_encoded.test_errors�sg���
�&�$�
�
�	 �1�
�G�G�J����	 �	 �	 �	 �	 �	 �	 �	 �	 �	 �	 ����	 �	 �	 �	 �����V�,�,�,�	4�	4�	4�	4�	4�	��h��� � � �
�
�
�1�
2�
2�	%�	%��E�(�U�G�$�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�
��i�+��'�'�'�
�� �:�,�/�/�/�/�/s�9�=�=�B*�*B.�1B.c�t��ttd��5}|�d��ddd��n#1swxYwY��tt���fd�}|dgd�����t��5|dgd���ddd��dS#1swxYwYdS)Nr�s
A
B
C
D+IKw-c����tt|td�����5}t|��}ddd��n#1swxYwY��||��dS)Nzutf-7r�r�)rr�r�rFrs    �r"r�z+Test_hook_encoded.test_modes.<locals>.check�s������d�$0��$9�$9�;�;�;�
!�>@��R����
!�
!�
!�
!�
!�
!�
!�
!�
!�
!�
!����
!�
!�
!�
!�
���U�N�3�3�3�3�3s�A�A�	Ar)r�r�r��D€r�)r�zB
zC
r�)rr	rrr�r�r�r�s`  r"�
test_modeszTest_hook_encoded.test_modes�sS���
�&�$�
�
�	*�1�
�G�G�(�)�)�)�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*�	*����	*�	*�	*�	*�	
����V�,�,�,�	4�	4�	4�	4�	4�	��c�3�3�3�4�4�4�
�
�
�z�
*�
*�	<�	<��E�$�:�:�:�;�;�;�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<�	<����	<�	<�	<�	<�	<�	<s�9�=�=�B-�-B1�4B1N)r$r%r&r2r�r�r�r'r(r"r�r��sG������1�1�!�!�!�00�0�0�"<�<�<�<�<r(r�c��eZdZd�ZdS)�MiscTestc�:�tj|t��dSr,)r�check__all__r6r/s r"�test_allzMiscTest.test_all�s����T�9�-�-�-�-�-r(N)r$r%r&r�r'r(r"r�r��s#������.�.�.�.�.r(r��__main__)4r2r�r�rxrmr6r#r�rr�r��ImportErrorr�rrrr�pathlibr�test.supportr�test.support.os_helperr	r
r�rr�rr
rr*�TestCaserLr�r�rr4rDrWr^rjrorurzrr�r�r�r�r�r$�mainr'r(r"�<module>r�s*����
�	�	�	�	�	�	�	�
�
�
�
�	�	�	�	�����������������������J�J�J�J������
�C�C�C�������K�K�K�K�������D�D�D�����!� � � � � � � �-�-�-�-�-�-�-�-������� � � � � � �)�)�)�)�)�)�8�8�8�8�8�8�"�"�"�"�"�"�������������	�	�	�	�	�	�	�	�"
�"
�"
�"
�"
�"
�"
�"
�HQ�Q�Q�Q�Q�y�(�"3�Q�Q�Q�f$�$�$�$�$�$�$�$�C�C�C�C�C�Y�� 1�C�C�C�D
--�--�--�--�--�--�--�--�^0�0�0�0�0�X�%6�0�0�0�*==�==�==�==�==�9�==�==�==�~,�,�,�,�,�9�,�,�,�&2�2�2�2�2�<�2�2�2�62�2�2�2�2�<�2�2�2�62�2�2�2�2�:�2�2�2�62�2�2�2�2� >�2�2�2�62�2�2�2�2�:�2�2�2�82�2�2�2�2�!?�2�2�2�62�2�2�2�2�;�2�2�2�6)�)�)�)�)�)�)�)�W�W�W�W�W�8�,�W�W�W�r:<�:<�:<�:<�:<��)�:<�:<�:<�z.�.�.�.�.�x� �.�.�.��z����H�M�O�O�O�O�O��s�-�7�7�A�A
�	A