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

�Ke/���ddlZddlZddlZddlmZddlmZddlZddlZddl	m
Z
ddlmZddl	m
Z
ddl	mZddlmZGd	�d
��ZGd�deej��ZGd
�deej��ZGd�d��ZGd�deej��ZGd�deej��Zedkrej��dSdS)�N)�array)�proxy)�
gc_collect)�TESTFN)�	os_helper)�warnings_helper)�UserListc�\�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�ZdS)�
AutoFileTestsc�F�|�td��|_dS)N�wb)�openr�f��selfs �8/usr/local/apps/python3/lib/python3.11/test/test_file.py�setUpzAutoFileTests.setUps�����6�4�(�(�����c�x�|jr|j���tjt��dS�N)r�closer�unlinkrrs r�tearDownzAutoFileTests.tearDowns2���6�	��F�L�L�N�N�N���� � � � � rc�v�t|j��}|�d��|�|j���|�����|j���d|_t
��|�tt|d��dS)Ns
teststring�tell)
rr�write�assertEqualrrr�assertRaises�ReferenceError�getattr)r�ps  r�testWeakRefszAutoFileTests.testWeakRefss����$�&�M�M��	���
������������������1�1�1������������������.�'�1�f�=�=�=�=�=rc�>�|j}|j|j|jdSr)r�name�mode�closed�rrs  r�testAttributeszAutoFileTests.testAttributes%s"���F��	���	���	����rc�`�|j�d��|j���tdd��}|�t
d��|_|j�|��}|�d|���d|���dS)N�12�b�
xxxxxxxxxx�rb)	rrrrrr�readintor�tobytes)r�a�ns   r�testReadintozAutoFileTests.testReadinto,s�������U������������#�w�������6�4�(�(����F�O�O�A���������	�	���B�Q�B��0�0�0�0�0rc��tdd��}|j���|�td���|_t|jd��r(|�t|jj|��dSdS)Nr+r,zutf-8)�encodingr.)	rrrrr�hasattrr�	TypeErrorr.)rr0s  r�testReadinto_textzAutoFileTests.testReadinto_text5sw���#�w��������������6�G��4�4����4�6�:�&�&�	=����i����!�<�<�<�<�<�	=�	=rc�,�tddg��}|j�|��|j���|�t
d��|_|j���}|�|d��dS)N�1�2r-r*)r	r�
writelinesrrr�readr)r�l�bufs   r�testWritelinesUserListz$AutoFileTests.testWritelinesUserList=sx���d�D�\�"�"������!��������������6�4�(�(����f�k�k�m�m������e�$�$�$�$�$rc�V�|�t|jjgd���dS�N)����rr6rr;rs r�testWritelinesIntegersz$AutoFileTests.testWritelinesIntegersFs)�����)�T�V�%6�	�	�	�B�B�B�B�Brc�t�tgd���}|�t|jj|��dSrA)r	rr6rr;)rr=s  r�testWritelinesIntegersUserListz,AutoFileTests.testWritelinesIntegersUserListJs6���W�W�W�������)�T�V�%6��:�:�:�:�:rc��Gd�d��}|�t|jj|��|��g��dS)Nc��eZdZdS)�8AutoFileTests.testWritelinesNonString.<locals>.NonStringN)�__name__�
__module__�__qualname__�rr�	NonStringrKQs�������DrrPrE)rrPs  r�testWritelinesNonStringz%AutoFileTests.testWritelinesNonStringOsk��	�	�	�	�	�	�	�	�	
���)�T�V�%6�$�9�;�;�	�	���4�	6�	6�	6�	6�	6rc��|j}|�|jt��|�|�����|�|j��t|d��r(|�ttf|jd��|���|�
|j��dS)Nr.�)rrr$r�assertFalse�isattyr&r5r�OSErrorr6r.r�
assertTruer's  r�
testErrorszAutoFileTests.testErrorsWs����F��������(�(�(���������$�$�$������"�"�"��1�j�!�!�	D����w�	�2�A�J��C�C�C�	���	�	�	������!�!�!�!�!rc
��ddddddddd	d
ddgffdg
}|�d
��|j�ddd��|�|jj��|D].\}}t|j|��}|jt|g|�R��/|�|j�ddd��d��	ddzdS#|�|jjtj
���d��YdSxYw)N)�filenorO)�flushrO)rUrO)�__next__rO�r<rO)r)r��readlinerO��	readlinesrO)�seek)r)rrOr;)�__iter__rO)�truncaterOrBr)�appendr�__exit__rWr&r r�
ValueErrorr�sys�exc_info)r�methods�
methodname�args�methods     r�testMethodszAutoFileTests.testMethodsbs8��!� �!�#��$�#�$�!��$� �2�%�(�#�
��	���'�(�(�(�	
�����d�D�)�)�)������
�&�&�&� '�	9�	9��J���T�V�Z�0�0�F��D��j�&�8�4�8�8�8�8�8�	
��������t�T�:�:�D�A�A�A�	E�
�a�C�C�C�C��	E����_�T�V�_�c�l�n�n�=�t�D�D�D�D�D�D���s�C�6Dc�P�|�t|jj��dSr)rrVrr<rs r�testReadWhenWritingz!AutoFileTests.testReadWhenWriting�s"�����'�4�6�;�/�/�/�/�/rN)rLrMrNrrr"r(r2r7r?rFrHrQrXrnrprOrrrrs�������)�)�)�!�!�!�
>�>�>����1�1�1�=�=�=�%�%�%�C�C�C�;�;�;�
6�6�6�	"�	"�	"� E� E� E�D0�0�0�0�0rrc��eZdZejZdS)�CAutoFileTestsN�rLrMrN�iorrOrrrrrr��������
�7�D�D�Drrrc�.�eZdZeej��ZdS)�PyAutoFileTestsN�rLrMrN�staticmethod�pyiorrOrrrwrw���������<��	�"�"�D�D�Drrwc�>�eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	S)
�OtherFileTestsc�8�tjt��dSr)rrrrs rrzOtherFileTests.tearDown�s����� � � � � rc��|�td�����dD]Z}	|�t|��}|���|�d|z���K#t$rY�WwxYwdS)Nr
)rS�aUzwU+zU+z+UzrU+z%r is an invalid file mode)rrr�failrg)rr%rs   r�testModeStringszOtherFileTests.testModeStrings�s����	�	�&�$���%�%�'�'�'�8�	?�	?�D�
?��I�I�f�d�+�+�����	�	�	��	�	�6��=�>�>�>�>��	�
�
�
���
����	?�	?s�A;�;
B�Bc��tjdkr|�d��tj���s|�d��|�ttf��5tj�d��ddd��n#1swxYwY|�ttf��5tj�	��ddd��dS#1swxYwYdS)N�osf1V5zE sys.stdin.seek(-1) may crash the interpreter on OSF1. Test manually.z stdin must be a TTY in this test���)
rh�platform�skipTest�stdinrUr�IOErrorrgrbrdrs r�	testStdinzOtherFileTests.testStdin�sh���<�8�#�#��M�M�"�
#�
#�
#��y���!�!�	>��M�M�<�=�=�=�
�
�
���4�
5�
5�	�	��I�N�N�2����	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�
�
�
���4�
5�
5�	!�	!��I��� � � �	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!�	!�	!s$�: B&�&B*�-B*�C>�>D�Dc�l�d}	|�t|��}|���|�d|z��dS#t$r\}|jddkr:t
|��}t|vs||vr$|�d|z��Yd}~dSYd}~dSYd}~dSd}~wwxYw)N�qwertyzno error for invalid mode: %srz&bad error message for invalid mode: %s)rrrr�rgrl�str)r�bad_moder�msg�ss     r�testBadModeArgumentz"OtherFileTests.testBadModeArgument�s�����	B��	�	�&�(�+�+�A�
�G�G�I�I�I��I�I�5��@�A�A�A�A�A���	L�	L�	L��x��{�a�����H�H���Q�;�;�(�!�"3�"3��I�I�F��J�K�K�K�K�K�K�K�K�K� ������"3�"3�"3�"3�"3�"3�����	L���s�A
�
B3�AB.�.B3c��	|�td|��}|�t|���d����|���|���|�td|��}t
|����d����}|���|���n>#t$r1}|�
d|t|��fz��Yd}~nd}~wwxYw|�||��dS)Nr
�asciir-z error setting buffer size %d: %s)rrrr��encoder�intr<�decoderVr�r)rr�r�dr�s     r�_checkBufferSizezOtherFileTests._checkBufferSize�s��
	J��	�	�&�$��*�*�A�
�G�G�C��F�F�M�M�'�*�*�+�+�+�
�G�G�I�I�I�
�G�G�I�I�I��	�	�&�$��*�*�A��A�F�F�H�H�O�O�G�,�,�-�-�A�
�G�G�I�I�I�
�G�G�I�I�I�I���	J�	J�	J��I�I�8�A�s�3�x�x�=�H�I�I�I�I�I�I�I�I�����	J��������A�����s�C1C4�4
D/�>'D*�*D/c�4�dD]K}tj|dt���5|�|��ddd��n#1swxYwY�L|�td��5|�d��ddd��dS#1swxYwYdS)N)r�rizline buffering)�message�categoryrB)r�check_no_warnings�RuntimeWarningr��assertWarnsRegex)rr�s  r�testSetBufferSizez OtherFileTests.testSetBufferSize�s3���	)�	)�A� �2�4�3C�4B�D�D�D�
)�
)��%�%�a�(�(�(�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)�
)����
)�
)�
)�
)���
"�
"�>�3C�
D�
D�	%�	%��!�!�!�$�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�	%�	%s#�A�A	�
A	�*B
�
B�Bc�b�|�td��}	|�d��|���|�td��}|�d��}|dkr|�d|z��|���dkr*|�d|���z��|���|���dkr*|�d|���z��|���tj	�
t��}|dkr|�d	|z��|���dS#|���wxYw)
Nr
s12345678901zrb+�s12345z(Read on file opened for update failed %rzFile pos after read wrong %dz!File pos after ftruncate wrong %dz"File size after ftruncate wrong %d)rrrrr<r�rrd�os�path�getsize)rr�data�sizes    r�testTruncateOnWindowsz$OtherFileTests.testTruncateOnWindows�sS��
�I�I�f�d�#�#��	�
�G�G�N�#�#�#�
�G�G�I�I�I��	�	�&��'�'�A��6�6�!�9�9�D��x����	�	�D�t�K�L�L�L��v�v�x�x�1�}�}��	�	�8�1�6�6�8�8�C�D�D�D�
�J�J�L�L�L��v�v�x�x�1�}�}��	�	�=������H�I�I�I�
�G�G�I�I�I��7�?�?�6�*�*�D��q�y�y��	�	�>��E�F�F�F�
�G�G�I�I�I�I�I��A�G�G�I�I�I�I���s�E%F�F.c��d}d}|t|��z}gd�}ddddtdd	��ffg}|�td
��}|�||z��|�|��|���|D]l\}}|�td��}	|�t|	��|��t|	|��}
|
|�|	����m|�td��}	t|��D]}t|	���|�d��}	|	���}
n%#t$r|�d
��YnwxYw|
|kr|�d|
�d|����|�d��}tddt|��z��}	|	�|��n%#t$r|�d��YnwxYw|���}
|
|kr|�d|
�d|����|�d��}	|	�t|����}
n%#t$r|�d��YnwxYw|
|kr|�d|
�d|����	|	���}n%#t$r|�d��YnwxYw||kr|�d|
�d|����|	���|�td��}		|	D]}
�	|	���|	�|��|	���|	���n%#t$r|�d��YnwxYw|	���dS#|	���wxYw)Ni@sham
)sspam, spam and eggs
seggs, spam, ham and spam
ssaussages, spam, spam and eggs
sspam, ham, spam and eggs
s(spam, spam, spam, spam, spam, ham, spam
swonderful spaaaaaam.
r^r]r`r.r+sd                                                                                                    r
r-rzLreadline() after next() with supposedly empty iteration-buffer failed anywayz6readline() after next() with empty buffer failed. Got z, expected �zLreadinto() after next() with supposedly empty iteration-buffer failed anywayz6readinto() after next() with empty buffer failed. Got zHread() after next() with supposedly empty iteration-buffer failed anywayz2read() after next() with empty buffer failed. Got zMreadlines() after next() with supposedly empty iteration-buffer failed anywayz7readlines() after next() with empty buffer failed. Got z'read* failed after next() consumed file)�lenrrrrr;rr�nextr �range�popr_rgr�r.r/r<ra)r�
dataoffset�filler�nchunks�	testlinesrj�bagrkrlr�meth�i�testline�liner>�liness                r�
testIterationzOtherFileTests.testIteration�s����
�����F���+��
�
�
�	�$�\�3D���s�H�!5�!5� 7�8�:���i�i���%�%���	�	�&�7�"�#�#�#����y�!�!�!��	�	���� '�	�	��J���	�	�&�$�'�'�A����T�!�W�W�f�-�-�-��1�j�)�)�D��D�$�K�K�
�G�G�I�I�I�I�
�I�I�f�d�#�#���w���	�	�A���G�G�G�G��=�=��#�#��	:��:�:�<�<�D�D���	:�	:�	:��I�I�9�
:�
:�
:�
:�
:�	:�����8����I�I�I�9=���x�x�I�
J�
J�
J��=�=��#�#���C��3�x�=�=�0�1�1��	:�
�J�J�s�O�O�O�O���	:�	:�	:��I�I�9�
:�
:�
:�
:�
:�	:�����{�{�}�}���8����I�I�I�9=���x�x�I�
J�
J�
J��=�=��#�#��	:��6�6�#�h�-�-�(�(�D�D���	:�	:�	:��I�I�9�
:�
:�
:�
:�
:�	:�����8����I�I�I�9=���x�x�I�
J�
J�
J�	:��K�K�M�M�E�E���	:�	:�	:��I�I�9�
:�
:�
:�
:�
:�	:�����I����I�I�I�9=���x�x�I�
J�
J�
J�	���	�	�	�
�I�I�f�d�#�#��	��
�
���
E��
�
�����
�
�3�������������
�
�
�
���
E�
E�
E��	�	�C�D�D�D�D�D�
E����
�G�G�I�I�I�I�I��A�G�G�I�I�I�I���sy�E$�$F�F� G6�6H�H�&"J	�	J+�*J+�K%�%L�L�O.�!AN3�2O.�3O�O.�O�O.�.PN)rLrMrNrr�r�r�r�r�r�r�rOrrr}r}�s�������!�!�!�
?�
?�
?�!�!�!� B�B�B� ���%�%�%����8_�_�_�_�_rr}c��eZdZejZdS)�COtherFileTestsNrsrOrrr�r�Xrurr�c�.�eZdZeej��ZdS)�PyOtherFileTestsNrxrOrrr�r�[r{rr��__main__)rhr��unittestr�weakrefrrt�_pyiorz�test.supportr�test.support.os_helperrrr�collectionsr	r�TestCaserrrwr}r�r�rL�mainrOrr�<module>r�s���
�
�
�
�	�	�	�	�����������������	�	�	�	�����#�#�#�#�#�#�)�)�)�)�)�)�"�"�"�"�"�"�(�(�(�(�(�(� � � � � � �u0�u0�u0�u0�u0�u0�u0�u0�n�����]�H�$5����#�#�#�#�#�m�X�%6�#�#�#�H�H�H�H�H�H�H�H�T�����n�h�&7����#�#�#�#�#�~�x�'8�#�#�#��z����H�M�O�O�O�O�O��r