%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_logfile.cpython-312.pyc

�

Ϫ�f(G���ddlmZddlZddlZddlZddlZddlZddlmZddl	m
Z
mZddlm
Z
Gd�de
�ZGd�d	e
j�ZGd
�de
�Zy)�)�annotationsN)�skipIf)�logfile�runtime)�TestCasec���eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Zeej(j+�d�dd��Zdd�Zdd�Zdd�Zdd�Zy)�LogFileTestsz%
    Test the rotating log file.
    c���|j�|_tj|j�d|_tj
j
|j|j�|_y)Nztest.log��mktemp�dir�os�makedirs�name�path�join��selfs �;/usr/lib/python3/dist-packages/twisted/test/test_logfile.py�setUpzLogFileTests.setUpsD���;�;�=���
���D�H�H����	��G�G�L�L����4�9�9�5��	�c���tj|jd�tjj	|j�r!tj|jd�yy)z�
        Restore back write rights on created paths: if tests modified the
        rights, that will allow the paths to be removed easily afterwards.
        �N)r�chmodr
r�existsrs r�tearDownzLogFileTests.tearDownsA��
	������5�!�
�7�7�>�>�$�)�)�$��H�H�T�Y�Y��&�%rc���tj|j|j�}|j	|j
�|j
t|j�y)zf
        L{BaseLogFile.shouldRotate} is abstract and must be implemented by
        subclass.
        N)	r�BaseLogFilerr
�
addCleanup�close�assertRaises�NotImplementedError�shouldRotate�r�logs  r�test_abstractShouldRotatez&LogFileTests.test_abstractShouldRotate$sE��
�!�!�$�)�)�T�X�X�6������	�	�"����-�s�/?�/?�@rc���tjtj|j|j
��5}|j
d�|j
d�|j�|j
d�ddd�t|j�5}|j|j�d�ddd�y#1swY�HxYw#1swYyxYw)zn
        Log files can be written to, flushed and closed. Closing a log file
        also flushes it.
        �123�456�7890N�
1234567890)�
contextlib�closingr�LogFilerr
�write�flush�openr�assertEqual�read�rr%�fs   r�test_writingzLogFileTests.test_writing-s���
�
�
�����	�	�4�8�8� D�
E�	���I�I�e���I�I�e���I�I�K��I�I�f��		��$�)�)�_�	5�����Q�V�V�X�|�4�	5�	5�
	�	��	5�	5�s�AC	�!C�	C�Cc�j�tjtj|j|j
d���5}|j
d�|j
d�|j
d�|jtjj|j�d���|jtjj|j�d���|j
d�|jtjj|j�d���|jtjj|j�d���|jtjj|j�d	���|j
d
�|jtjj|j�d	���|j�|jtjj|j�d	���|jtjj|j�d���ddd�|jj�gd
��y#1swY�,xYw)zq
        Rotating log files autorotate after a period of time, and can also be
        manually rotated.
        �
)�rotateLengthr(�4567890�11111111111�.1�.2��.3�3�.4N)���)r,r-rr.rr
r/�
assertTruerrr�assertFalse�rotater2�listLogsr$s  r�
test_rotationzLogFileTests.test_rotation;s����
�
��O�O�D�I�I�t�x�x�b�A�
�	?�
��I�I�e���I�I�i� ��I�I�h���O�O�B�G�G�N�N�d�i�i�[��+;�<�=����R�W�W�^�^�t�y�y�k��,<�=�>��I�I�b�M��O�O�B�G�G�N�N�d�i�i�[��+;�<�=��O�O�B�G�G�N�N�d�i�i�[��+;�<�=����R�W�W�^�^�t�y�y�k��,<�=�>��I�I�c�N����R�W�W�^�^�t�y�y�k��,<�=�>�
�J�J�L��O�O�B�G�G�N�N�d�i�i�[��+;�<�=����R�W�W�^�^�t�y�y�k��,<�=�>�'	?�*	
��������3�+	?�	?�s
�H>J)�)J2c�4�tjtj|j|j
��5}|j
d�ddd�tj|j|j
�}|j|j�|j|jd�|j|jj�|j�|j
d�|j|jd�|j|jj�|j�|j}|jdd�|j|j�d�y#1swY��?xYw)a
        Log files can be written to, closed. Their size is the number of
        bytes written to them. Everything that was written to them can
        be read, even if the writing happened on separate occasions,
        and even if the log file was closed in between.
        �
0123456789Nr8�abc�
rs
0123456789abc)r,r-rr.rr
r/rr r2�size�_file�tell�seekr3r4s   r�test_appendzLogFileTests.test_appendXs���
�
�����	�	�4�8�8� D�
E�	$���I�I�l�#�	$��o�o�d�i�i����2������	�	�"�������2�&���������)�3�8�8�4��	�	�%��������2�&���������)�3�8�8�4��I�I��	���q�!���������#3�4�	$�	$�s�F
�
Fc��tj|j|j�}|j	|j
�|j
d�|j
d�|j�|j
d�|j�|j|j�dg�tj|j��5}|jjd�|j|j!�dg�|j|j!�g�ddd�tj|j#d��5}|j|j!�ddg�|j|j!�g�ddd�|j%t&|j"d�|j%t(|j"d�|j�|j|j�ddg�tj|j#d��5}|jjd�|j|j!�dg�|j|j!�g�ddd�tj|j#d��5}|j|j!�ddg�|j|j!�g�ddd�y#1swY���xYw#1swY���xYw#1swY��xYw#1swYyxYw)	a[
        Various tests for log readers.

        First of all, log readers can get logs by number and read what
        was written to those log files. Getting nonexistent log files
        raises C{ValueError}. Using anything other than an integer
        index raises C{TypeError}. As logs get older, their log
        numbers increase.
        zabc
zdef
zghi
rBrNrC�1)rr.rr
rr r/rGr0r2rHr,r-�
getCurrentLogrOrQ�	readLines�getLogr!�
ValueError�	TypeError)rr%�readers   r�test_logReaderzLogFileTests.test_logReaderms����o�o�d�i�i����2������	�	�"��	�	�'���	�	�'���
�
���	�	�'���	�	��	
�������!��-�
�
�
�� 1� 1� 3�
4�	5���L�L���a� ����V�-�-�/�'��;����V�-�-�/��4�	5��
�
��
�
�1�
�
.�	5�&����V�-�-�/�'�7�1C�D����V�-�-�/��4�	5�
	
���*�c�j�j�!�4����)�S�Z�Z��5�	�
�
���������!�Q��0�
�
�
��
�
�1�
�
.�	5�&��L�L���a� ����V�-�-�/�'��;����V�-�-�/��4�	5��
�
��
�
�1�
�
.�	5�&����V�-�-�/�'�7�1C�D����V�-�-�/��4�	5�	5�'	5�	5��	5�	5��	5�	5��	5�	5�s4�AL�&AL+�	AL8�AM�L(�+L5�8M�M
c��t|jd�5	ddd�tj|j�}|j	|j
�|j
g|jd��y#1swY�exYw)zB
        L{LogReader.readLines} supports reading no line.
        �wNr)r1rr�	LogReaderrr r2rV)rrZs  r�test_LogReaderReadsZeroLinez(LogFileTests.test_LogReaderReadsZeroLine�sk��
�$�)�)�S�
!�	��	��"�"�4�9�9�-��������%�����V�-�-�a�0�1�	�	�s�A=�=Bc�8�t|jd�j�tj|jd�tj
|j�t
j}tj|j|j�}|j|j�|jd�|j�|j|tj
|j�t
j�y)zH
        Check rotated files have same permissions as original.
        r]��rLN)r1rr rr�stat�ST_MODErr.rr
rr/rGr2)r�moder%s   r�test_modePreservationz"LogFileTests.test_modePreservation�s���	
�T�Y�Y���"�"�$�
������E�"��w�w�t�y�y�!�$�,�,�/���o�o�d�i�i����2������	�	�"��	�	�%���
�
������r�w�w�t�y�y�1�$�,�,�?�@rc��tj|j|j�}|j	|j
�|j
d�tj|jd�	ttjj|jd�d�}|j�y#t$rYnwxYw|j�|j
d�|j�|j}|j!|j#�d�|j%dd�|j!|j'�d	�y)
zH
        Check it keeps working when permission on dir changes.
        rL�m�xxxr]N�def�rsabcdef)rr.rr
rr r/rrr1rr�OSErrorrGr0rOr2rPrQr3r4s   r�test_noPermissionzLogFileTests.test_noPermission�s����o�o�d�i�i����2������	�	�"��	�	�%��	������5�!�	��R�W�W�\�\�$�(�(�E�2�C�8�A�
�G�G�I���	�	��	��	�
�
���	�	�%���	�	���I�I���������1�%�	���q�!���������9�-s�84B=�=	C	�C	c�J�tj|j|jdd��}|j	|j
�|j
d�|j
d�|jtjj|j�d���|j
d�|jtjj|j�d���|j
d	�|jtjj|j�d
���t|j�d
��5}|j|j�d�ddd�|j
d�t|j�d
��5}|j|j�d�ddd�|jtjj|j�d
���y#1swY��xYw#1swY�QxYw)zl
        Test it respect the limit on the number of files when maxRotatedFiles
        is not None.
        r8rD)r9�maxRotatedFilesr;�22222222222r<�33333333333r=�44444444444r?N�55555555555rA)rr.rr
rr r/rErrrr1r2r3rF�rr%�fps   r�test_maxNumberOfLogz LogFileTests.test_maxNumberOfLog�s���
�o�o�d�i�i�����TU�V������	�	�"��	�	�(���	�	�(����������$�)�)��B�'7�8�9��	�	�(����������$�)�)��B�'7�8�9��	�	�(����������$�)�)��B�'7�8�9�
�T�Y�Y�K�r�"�
#�	2�r����R�W�W�Y��1�	2�	�	�	�(��
�T�Y�Y�K�r�"�
#�	2�r����R�W�W�Y��1�	2���������4�9�9�+�R�(8�9�:�
	2�	2��	2�	2�s�!H
�(!H�
H�H"c��tj|j|jdd��}|j	|j
�tjj
|jdd��}|j	|j
�|j|j|j�|jtjj|j�|j�|j|j|j�|j|j|j�y)z/
        Test the fromFullPath method.
        r8r��defaultModeN)
rr.rr
rr �fromFullPathrr2r�abspathr9rx)r�log1�log2s   r�test_fromFullPathzLogFileTests.test_fromFullPath�s������t�y�y�$�(�(�B�E�J������
�
�#����+�+�D�I�I�r�u�+�M������
�
�#�������D�I�I�.������������3�T�Y�Y�?�����*�*�D�,=�,=�>�����)�)�4�+;�+;�<rc�P�t|jd�5tj|jd�t	j
tj|j�tj�}ddd�tj|j|j�}|jt	j
tj|j�tj��|j|j�y#1swY��xYw)zx
        Test the default permission of the log file: if the file exist, it
        should keep the permission.
        �wbraN)r1rrrrb�S_IMODErcrr.rr
r2rr )r�currentModer{s   r�test_defaultPermissionsz$LogFileTests.test_defaultPermissions�s���
�$�)�)�T�
"�	I��H�H�T�Y�Y��&��,�,�r�w�w�t�y�y�'9�$�,�,�'G�H�K�	I����t�y�y�$�(�(�3��������b�g�g�d�i�i�&8����&F�G��U�����
�
�#�	I�	I�s�A$D�D%c��tj|j|jd��}|j	|j
�t
jtj|j�tj�}tjj�r|j|d�y|j|d�y)zG
        Test specifying the permissions used on the log file.
        �6rw�$N)rr.rr
rr rbr�rrrcr�platform�	isWindowsr2)rr{rds   r�test_specifiedPermissionsz&LogFileTests.test_specifiedPermissionss������t�y�y�$�(�(��F������
�
�#��|�|�B�G�G�D�I�I�.�t�|�|�<�=�����%�%�'����T�5�)����T�5�)rzCan't test reopen on Windowsc��tjtj|j|j
��5}|j
d�tjj|j
d�}tj|j|�|j�|j
d�ddd�t|j�5}|j|j�d�ddd�t�5}|j|j�d�ddd�y#1swY�|xYw#1swY�JxYw#1swYyxYw)z�
        L{logfile.LogFile.reopen} allows to rename the currently used file and
        make L{logfile.LogFile} create a new file.
        �hello1zsave.log�hello2N)r,r-rr.rr
r/rrr�rename�reopenr1r2r3)rr{�savePathr5s    r�test_reopenzLogFileTests.test_reopens����
�
�����	�	�4�8�8� D�
E�	!���J�J�x� ��w�w�|�|�D�H�H�j�9�H��I�I�d�i�i��*��K�K�M��J�J�x� �	!��$�)�)�_�	1�����Q�V�V�X�x�0�	1�
�(�^�	1�q����Q�V�V�X�x�0�	1�	1�	!�	!��	1�	1��	1�	1�s$�A=D6�!E�!E�6D?�E�Ec��|jttj|jd�}|j|jtj�y)zR
        Specifying an invalid directory to L{LogFile} raises C{IOError}.
        �this_dir_does_not_existN)r!�IOErrorrr.rr2�errno�ENOENT)r�es  r�test_nonExistentDirz LogFileTests.test_nonExistentDir s@��
����W�_�_�d�i�i�1J�
��	
������%�,�,�/rc�4�tjj�rd\}}d}nd\}}d}tj||d��}|j|j�|j|j|�|j|jd�y)z�
        Opening a L{LogFile} which can be read and write but whose mode can't
        be changed doesn't trigger an error.
        )�NULr>r�)�nullz/devz	/dev/nullrgrwN)
rr�r�rr.rr r2rrx)rr�	directory�expectedPathr%s     r�test_cantChangeFileModez$LogFileTests.test_cantChangeFileMode)s|��
���%�%�'�'�O�D�)� �L�,�O�D�)�&�L��o�o�d�I�5�A������	�	�"�������<�0�������%�0rc���tj|j|j�}|j	|j
�t
|j�d�d�5}|jd�ddd�t
|j�d�d�5}|jd�ddd�|jdg|j��y#1swY�^xYw#1swY�7xYw)zl
        L{LogFile.listLogs} doesn't choke if it encounters a file with an
        unexpected name.
        r<r]r(Nz	.bad-filerB)rr.rr
rr r1rr/r2rHrss   r� test_listLogsWithBadlyNamedFilesz-LogFileTests.test_listLogsWithBadlyNamedFiles;s���
�o�o�d�i�i����2������	�	�"�
�S�X�X�J�b�/�3�
'�	�2��H�H�U�O�	�
�S�X�X�J�i�(�#�
.�	�"��H�H�U�O�	�	
���!��c�l�l�n�-�	�	��	�	�s�C�C�C�C#c�v�tj|j|j�}|j	|j
�t
dd�D]7}t|j�d|��d�5}|jd�ddd��9|jddg|j��y#1swY�fxYw)	zR
        L{LogFile.listLogs} ignores log files which rotated suffix is 0.
        rrD�.r]r(NrBrC)rr.rr
rr �ranger1rr/r2rH)rr%�irts    r�%test_listLogsIgnoresZeroSuffixedFilesz2LogFileTests.test_listLogsIgnoresZeroSuffixedFilesJs����o�o�d�i�i����2������	�	�"��q�!��	 �A�����
�!�A�3�'��-�
 �������
 �
 �	 �	
���!�Q������0�
 �
 �s�0B/�/B8	N��return�None)�__name__�
__module__�__qualname__�__doc__rrr&r6rIrRr[r_rerlrur}r�r�rrr�r�r�r�r�r�r��rrr	r	s����6�'�A�5�4�:5�*)5�V
2�A�.�>;�0=�
$�*��G���&�&�(�*H�I�1�J�1�"0�1�$
.�1rr	c� �eZdZdZdd�Zdd�Zy)�RiggedDailyLogFile�c�l�tjj|�|j�|_y)N)r�DailyLogFile�	_openFile�toDate�lastDaters rr�zRiggedDailyLogFile._openFile[s#�����&�&�t�,����
��
rc�t�|rtj|�ddStj|j�ddS)NrD)�time�gmtime�_clock)r�argss  rr�zRiggedDailyLogFile.toDate`s5����;�;��%�b�q�)�)��{�{�4�;�;�'���+�+rNr�)r��floatr�ztuple[int, int, int])r�r�r�r�r�r�r�rrr�r�Xs��
�F�&�
,rr�c��eZdZdZdd�Zdd�Zdd�Zdd�Zdd�Ze	e
jj�d�dd��Z
dd	�Zdd
�Zdd�Zdd�Zy
)�DailyLogFileTestsz!
    Test rotating log file.
    c���|j�|_tj|j�d|_tj
j
|j|j�|_y)Nz
testdaily.logrrs rrzDailyLogFileTests.setUpksD���;�;�=���
���D�H�H��#��	��G�G�L�L����4�9�9�5��	rc��tjt|j|j��5}|jd�|jd�|j
�|jd�ddd�t|j�5}|j|j�d�ddd�y#1swY�HxYw#1swYyxYw)zO
        A daily log file can be written to like an ordinary log file.
        r(r)r*Nr+)r,r-r�rr
r/r0r1rr2r3r4s   rr6zDailyLogFileTests.test_writingqs����
�
� 2�4�9�9�d�h�h� G�
H�	�C��I�I�e���I�I�e���I�I�K��I�I�f��		��$�)�)�_�	5�����Q�V�V�X�|�4�	5�	5�
	�	��	5�	5�s�AB?�!C�?C�Cc�4�t|j|j�}|j|j�td�D�cgc]&}|jdz|j|dz�z��(}}d|_|jd�d|_|jd�d|_|jd�|jtjj|d	��|jtjj|d
��d|_|jd�|jtjj|d	��|jtjj|d
��|jtjj|d
��d|_|jd�|jtjj|d
��ycc}w)z/
        Daily log files rotate daily.
        rDr��Qr�r(i��r:r;rrBi�r>rCi�r@N)r�rr
rr r�r�suffixr�r/rErrrF)rr%�day�dayss    rrIzDailyLogFileTests.test_rotation~sr��!����D�H�H�5������	�	�"�GL�Q�x�P�����S��3�:�:�c�E�k�#:�:�P��P���
��	�	�%����
��	�	�)����
��	�	�(����������t�A�w�/�0����������Q��0�1���
��	�	�"�
���������t�A�w�/�0���������t�A�w�/�0����������Q��0�1���
��	�	�#�����������Q��0�1��%Qs�	+Hc��gd�}t|j|j�}|j|j�|D]}|j|��|j
�|jd�}|j|j�|j||j��|jt|jd�d|_|j	�|j�|jd�}|j|j�|j||j��y)zH
        Test retrieving log files with L{DailyLogFile.getLog}.
        )z1
z2
z3
r�r�i�QrN)r�rr
rr r/r0rWr2rVr!rXr�rG)r�datar%�d�rs     r�test_getLogzDailyLogFileTests.test_getLog�s���%�� ����D�H�H�5������	�	�"��	�A��I�I�a�L�	��	�	��
�J�J�s�O�������� �����q�{�{�}�-�	
���*�c�j�j�%�8���
�	���	��
�
���J�J�q�M�������� �����q�{�{�}�-rc��t|j|j�}|j|j�|j
�d|j
|j���}t|d�5}|jd�ddd�|j}|j�|j||j�y#1swY�BxYw)zu
        L{DailyLogFile.rotate} doesn't do anything if they new log file already
        exists on the disk.
        r�r]r(N)
r�rr
rr rr�r�r1r/rOrGr2)rr%�newFilePathrt�previousFiles     r�test_rotateAlreadyExistsz*DailyLogFileTests.test_rotateAlreadyExists�s���
!����D�H�H�5������	�	�"����
�!�C�J�J�s�|�|�$<�#=�>��
�+�s�
#�	�r��H�H�U�O�	��y�y���
�
������s�y�y�1�		�	�s�2C�CzVMaking read-only directories on Windows is too complex for this test to reasonably do.c��tj|j|j�}|j	|j
�t
j|jd�|j	tj|jd�|j}|j�|j||j�y)z�
        L{DailyLogFile.rotate} doesn't do anything if the directory containing
        the log files can't be written to.
        r�i�N)rr�rr
rr rrr�rOrGr2�rr%r�s   r�#test_rotatePermissionDirectoryNotOkz5DailyLogFileTests.test_rotatePermissionDirectoryNotOk�s~���"�"�4�9�9�d�h�h�7������	�	�"�
�������&�������#�-�-��7��y�y���
�
������s�y�y�1rc�>�tj|j|j�}|j	|j
�t
j|jd�|j}|j�|j||j�y)zi
        L{DailyLogFile.rotate} doesn't do anything if the log file can't be
        written to.
        r�N)rr�rr
rr rrrrOrGr2r�s   r�test_rotatePermissionFileNotOkz0DailyLogFileTests.test_rotatePermissionFileNotOk�sf��
�"�"�4�9�9�d�h�h�7������	�	�"�
������5�!��y�y���
�
������s�y�y�1rc��tj|j|j�}|j	|j
�t
jd�}|jd|j|��y)z~
        Test that L{DailyLogFile.toDate} converts its timestamp argument to a
        time tuple (year, month, day).
        )	��rBrBrrrrrr)r�rBrBN)
rr�rr
rr r��mktimer2r�)rr%�	timestamps   r�test_toDatezDailyLogFileTests.test_toDate�sV��
�"�"�4�9�9�d�h�h�7������	�	�"��K�K� >�?�	�����s�z�z�)�'<�=rc���d�fd�}tj�j�j�}�j	|j
��j
td|�|j�}�jgd�|�y)a�
        Test that L{DailyLogFile.toDate} returns today's date by default.

        By mocking L{time.localtime}, we ensure that L{DailyLogFile.toDate}
        returns the first 3 values of L{time.localtime} which is the current
        date.

        Note that we don't compare the *real* result of L{DailyLogFile.toDate}
        to the *real* current date, as there's a slight possibility that the
        date changes between the 2 function calls.
        c�R���jd|�ttdd��S)Nr�r�	)r2�listr�)r�rs �r�mock_localtimezADailyLogFileTests.test_toDateDefaultToday.<locals>.mock_localtime�s$������R��&���a���$�$r�	localtime)rrBrCN)r��objectr�z	list[int])
rr�rr
rr �patchr�r�r2)rr�r%�logDates`   r�test_toDateDefaultTodayz)DailyLogFileTests.test_toDateDefaultToday�s_���	%��"�"�4�9�9�d�h�h�7������	�	�"��
�
�4��n�5��*�*�,������G�,rc��tj|j|j�}|j	|j
�d}t
j|dz�}|j|�}|j||�y)zc
        Test that L{DailyLogFile.toDate} uses its arguments to create a new
        date.
        )i�r8�)rrrrrrN)
rr�rr
rr r�r�r�r2)rr%�date�secondsr�s     r�#test_toDateUsesArgumentsToMakeADatez5DailyLogFileTests.test_toDateUsesArgumentsToMakeADatesc��
�"�"�4�9�9�d�h�h�7������	�	�"����+�+�d�X�o�.���*�*�W�%������w�'rNr�)r�r�r�r�rr6rIr�r�rrr�r�r�r�r�r�r�r�rrr�r�fsd���6�5�2�4.�62�"����"�"�$�	!��

2��

2�2�	>�-�0(rr�)�
__future__rr,r�rrbr��unittestr�twisted.pythonrr�twisted.trial.unittestrr	r�r�r�r�rr�<module>r�sQ��#���	����+�+�E1�8�E1�P
,��-�-�,�n(��n(r

Zerion Mini Shell 1.0