%PDF- %PDF-
| Direktori : /usr/lib/python3/dist-packages/twisted/test/__pycache__/ | 
| Current File : //usr/lib/python3/dist-packages/twisted/test/__pycache__/test_logfile.cpython-312.pyc | 
�
    Ϫ�f(G  �                  �   � d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZ d dl	m
Z
mZ d dlm
Z
  G d� de
�      Z G d� d	e
j                  �      Z G d
� de
�      Zy)�    )�annotationsN)�skipIf)�logfile�runtime)�TestCasec                  ��   � e Zd ZdZdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z	dd�Z
dd	�Zdd
�Zdd�Z
dd�Zdd
�Zdd�Zdd�Z eej(                  j+                  �       d�      dd��       Zdd�Zdd�Zdd�Zdd�Zy)�LogFileTestsz%
    Test the rotating log file.
    c                ��   � | j                  �       | _        t        j                  | j                  �       d| _        t        j
                  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.setUp   sD   � ��;�;�=���
���D�H�H����	��G�G�L�L����4�9�9�5��	�    c                ��   � t        j                  | j                  d�       t         j                  j	                  | j                  �      r!t        j                  | j                  d�       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   �existsr   s    r   �tearDownzLogFileTests.tearDown   sA   � �
 	������5�!�
�7�7�>�>�$�)�)�$��H�H�T�Y�Y��&� %r   c                ��   � t        j                  | j                  | j                  �      }| j	                  |j
                  �       | j
                  t        |j                  �       y)zf
        L{BaseLogFile.shouldRotate} is abstract and must be implemented by
        subclass.
        N)	r   �BaseLogFiler   r
   �
addCleanup�close�assertRaises�NotImplementedError�shouldRotate�r   �logs     r   �test_abstractShouldRotatez&LogFileTests.test_abstractShouldRotate$   sE   � �
 �!�!�$�)�)�T�X�X�6������	�	�"����-�s�/?�/?�@r   c                ��  � t        j                  t        j                  | j                  | j
                  �      �      5 }|j
                  d�       |j
                  d�       |j                  �        |j
                  d�       ddd�       t        | j                  �      5 }| j                  |j                  �       d�       ddd�       y# 1 sw Y   �HxY w# 1 sw Y   yxY w)zn
        Log files can be written to, flushed and closed. Closing a log file
        also flushes it.
        �123�456�7890N�
1234567890)�
contextlib�closingr   �LogFiler   r
   �write�flush�openr   �assertEqual�read�r   r%   �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  � t        j                  t        j                  | j                  | j
                  d��      �      5 }|j
                  d�       |j
                  d�       |j
                  d�       | j                  t        j                  j                  | j                  � d��      �       | j                  t        j                  j                  | j                  � d��      �       |j
                  d�       | j                  t        j                  j                  | j                  � d��      �       | j                  t        j                  j                  | j                  � d��      �       | j                  t        j                  j                  | j                  � d	��      �       |j
                  d
�       | j                  t        j                  j                  | j                  � d	��      �       |j                  �        | j                  t        j                  j                  | j                  � d	��      �       | j                  t        j                  j                  | j                  � d��      �       ddd�       | j                  j                  �       g d
��       y# 1 sw Y   �,xY w)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-   r   r.   r   r
   r/   �
assertTruer   r   r   �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  � t        j                  t        j                  | j                  | j
                  �      �      5 }|j
                  d�       ddd�       t        j                  | j                  | j
                  �      }| j                  |j                  �       | j                  |j                  d�       | j                  |j                  j                  �       |j                  �       |j
                  d�       | j                  |j                  d�       | j                  |j                  j                  �       |j                  �       |j                  }|j                  dd�       | j                  |j                  �       d�       y# 1 sw Y   ��?xY w)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�
   r   s
   0123456789abc)r,   r-   r   r.   r   r
   r/   r   r    r2   �size�_file�tell�seekr3   r4   s      r   �test_appendzLogFileTests.test_appendX   s  � � �
�
�����	�	�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                �  � t        j                  | j                  | j                  �      }| j	                  |j
                  �       |j
                  d�       |j
                  d�       |j                  �        |j
                  d�       |j                  �        | j                  |j                  �       dg�       t        j                  |j                  �       �      5 }|j                  j                  d�       | j                  |j!                  �       dg�       | j                  |j!                  �       g �       ddd�       t        j                  |j#                  d�      �      5 }| j                  |j!                  �       ddg�       | j                  |j!                  �       g �       ddd�       | j%                  t&